On Thu, Aug 8, 2019 at 11:34 PM Ronald Oussoren via Python-ideas email@example.com wrote:
On 8 Aug 2019, at 12:22, Richard Musil firstname.lastname@example.org wrote:
I have found myself in an awkward situation with current (Python 3.7) JSON module. Basically it boils down to how it handles floats. I had been hit on this particular case:
In : float(0.6441726684570313) Out: 0.6441726684570312
but I guess it really does not matter.
It really doesn’t, both values have the same binary representation. See the Python FAQ at https://docs.python.org/3/faq/design.html#why-are-floating-point-calculations-so-inaccurate or the floating point section of the tutorial at https://docs.python.org/3/tutorial/floatingpoint.html#tut-fp-issues for more information.
That depends on your definition of "matter". The JSON specification doesn't actually stipulate IEEE 64-bit floating point; it just defines the grammar. It'd be completely valid to use a JSON number to carry data from one Python script into another, where both ends use decimal.Decimal to store it. But if the value is going to be parsed into a float at the other end, then yeah, they're equivalent.