Builtin Float Epsilon? (was: Re: Does python suck or I am just stupid? )

Stephen Horne intentionally at blank.co.uk
Sat Feb 22 16:14:07 EST 2003


On Sat, 22 Feb 2003 18:33:59 GMT, djw <dwelch91 at no.spam.attbi.com>
wrote:

>sys.floatepsilon = 0.000000001 # or maybe some nice default value

Debatable - most people expect '==' to only return true if the values
are precisely equal. I suspect an 'approximately equal' operator has
been suggested in the past, though.

One problem is - just how close do two values need to be to count as
equal. There is no single good answer to this - it depends on the
context. If you are dealing with numbers that range from zero to
several billion, you might consider 0 and 0.1 to be equal - if your
numbers range from 0 to 0.00000001 you will probably take quite a
different view.

So yes, there's an issue - but it's hard to tie down exactly what 'the
right thing' is to solve it.

-- 
steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list