Is floating point arbitrary precision available?
Just for fun and because it was really easy, I’ve written a short program to generate Grafting numbers, but because of floating point precision issues it’s not finding some of the larger examples.
Just for fun and because it was really easy, I’ve written a short program to generate Grafting numbers, but because of floating point precision issues it’s not finding some of the larger examples.
>>> float(str(0.65000000000000002)) 0.65000000000000002 >>> float(str(0.47000000000000003)) 0.46999999999999997 ??? What is going on here? How do I convert 0.47000000000000003 to string and the resultant value back to float? I am using Python 2.5.4 on Windows. Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the … Read more
I encountered negative zero in output from python; it’s created for example as follows:
I know that most decimals don’t have an exact floating point representation (Is floating point math broken?).
Python now uses David Gay’s algorithm for finding the shortest floating point representation that doesn’t change its value. This should help mitigate some of the confusion surrounding binary floating point numbers.