Precision for equality of two floats?
Dan Sommers
me at privacy.net
Tue Nov 29 22:18:10 EST 2005
On Tue, 29 Nov 2005 14:31:46 GMT,
bokr at oz.net (Bengt Richter) wrote:
> On Mon, 28 Nov 2005 07:58:37 -0800, aleax at mail.comcast.net (Alex Martelli) wrote:
>> Python's builtin floats compare for exact bit-by-bit equality -- no
>> "threshold". You may want to look at the allclose function in the
> Does "exact bit-by-bit" mean that
> a = <floatexpr>
> a == <floatexpr>
> is 100% guaranteed? I.e., are there implementations where an
> expression value might remain in 80-bit representation in the fpu and
> be rounded to 64 bits for assignment to a and then not compare equal
> because the second a is a rounded 64-bit value compared to the
> regenerated 80-bit value?
IIRC, if you consider NaNs, then a == a isn't even guaranteed if a might
be a NaN, but that's probably Too Much Information. ;-)
There have been (and may well still be) seemingly endless debates about
this on comp.std.c (even without the possibility of NaNs, for similar
reasons to the one you cite). I don't know if the Lisp and/or IEEE-754
crowds have worked all of this out.
Regards,
Dan
--
Dan Sommers
<http://www.tombstonezero.net/dan/>
More information about the Python-list
mailing list