Generating equally-spaced floats with least rounding error
rosuav at gmail.com
Sun Sep 25 08:09:01 CEST 2011
On Sun, Sep 25, 2011 at 3:31 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>>>> 2.1 == F(21, 10)
Ahh, but that may just mean that Fraction doesn't implement an == that
compares with floats.
This may be because one oughtn't to use == with floats anyway.
That denominator is a power of 2 (2**51 as it happens), which is
unsurprising for something created from an IEEE floating point value.
Rounding F(21,10) off to fit into float produces this same value.
More information about the Python-list