Reputation: 91
Basically i wrote this code ..
import sympy
number = 5.62527e-11;
f = sympy.Symbol('f');
answer = sympy.solve(Eq(f,number),f);
print(answer);
and as expected the answer is "5.62527e-11"
but when i change "5.62527e-11" to "5.62527e-67" and run the same code ...i am getting [0.0] as output which is awkward ...it is working for "e-11" but fails for "e-67" can someone please exp-lain why this is happening ..and can someone show me the solution ...i need a solution for this problem
Note : the above code is just a piece of the actual code ...and i have to run it in the same way ...so can anyone please help me dealing with that number ?
thanks in advance
Upvotes: 0
Views: 480
Reputation: 19047
Use a symbol instead of the number (and substitute it in at the end if necessary):
>>> from sympy import *
>>> number = Symbol('5.62527e-11')
>>> f = sympy.Symbol('f');
>>> sympy.solve(Eq(f,number),f)
[5.62527e-11]
Upvotes: 0
Reputation: 91490
This is a bug in SymPy. See https://stackoverflow.com/a/22574099/161801 and https://github.com/sympy/sympy/issues/7322.
Upvotes: 1
Reputation: 11
The limitation of floating point numbers is that they are only accurate to a certain about of decimal places. I was curious about your question myself and found https://docs.python.org/3/tutorial/floatingpoint.html
Upvotes: 0