Why isn't Python king of the hill?
grante at visi.com
Sat Jun 2 06:08:40 CEST 2001
On Fri, 1 Jun 2001 16:35:03 -0700, Geoffrey Gerrietts <geoff at homegain.com> wrote:
>The big problem with binary FP is that most people (myself
>included) don't know when to expect approximation rather than
>an exact result.
Always expect an approximation. Surprise is one of the 3 main
weapons of floating point...
The secret to using binary floating point successfully is to
_never_ expect an exact result and not to use binary floating
point if you require an exact result.
You may thing that 1.0 + 2.0 == 3.0 ought to be true, but you
should always treat floating point operations as if there are
small random numbers being thrown in at every step. So you
should check for
fabs((1.0 + 2.0) - 3.0) < [a small number]
Choosing the value for [a small number] is left as an exercise
for the reader.
Grant Edwards grante Yow! Did you find a
at DIGITAL WATCH in YOUR box
visi.com of VELVEETA??
More information about the Python-list