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

Alex Martelli aleax at aleax.it
Sat Feb 22 15:19:16 EST 2003


djw wrote:
   ...
> should be able to write something like:
> 
> sys.floatepsilon = 0.000000001 # or maybe some nice default value
   ...
> Seems like this would keep more people from running into this 'problem'.

"Seems", maybe, but years of experience in APL, which uses this
kind of approach, have convinced me it doesn't work.  Having
a == b and b == c NOT imply a == c makes "==" so utterly different
from all workable versions of "equality" that you may as well
forget it.  And having a type on which == doesn't work at all would
also lead to all sort of anomalies.

In practice, I think it boils down to: floating-point is hard, and
there is no "royal road" that will shield programmers who choose
to use floating-point from undestanding what they're doing, even
though strange little anomalies will probably keep surfacing.  I
_think_ it follows, as night follows day, that Python should NOT
foist floating-point on unsuspecting users who do NOT really know 
what they're doing in the matter (over 90% of us, I fear) -- e.g.,
true division and decimal literals should map to fixed-point or
rational types, and floating-point should only be used when it is
required explicitly.  Unfortunately Guido disagrees (and his
opinion trumps mine, of course), because "shielding user from
floating point" was what ABC, Python's precursor language, did,
and floating point is SO much faster than the alternatives (as it
can exploit dedicated hardware present in nearly every computer
of today) that defaulting to non-floating point for non-integer
numerical calculations might be perceived by naive users as an
excessive slowing-down of their programs, if said programs perform
substantial amounts of numeric computation.  Oh well.



Alex





More information about the Python-list mailing list