e vs exp()? / financial applications

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Sep 23 20:46:08 EDT 2002


Andrew Thompson fed this fish to the penguins on Monday 23 September 
2002 10:15 am:

> 
> 1+w+w+w+w
> 
> and
> 
> w+w+w+w+1
> 
> which are both *different* according to the == operator, but for the
> purposes of numerical accuracy are identical.
> 
> This behaviour is quite mild, but it shows the point that rounding
> errors can easily creep in, and using == to test for equality is not
> always sensible.
>

        Don't they teach anything about floating point in college anymore?

        I'm pretty sure it came up by my second year "advanced FORTRAN" class 
that one should not rely upon testing for equality between any two 
floating point values, but instead should test for a difference less 
than some predetermined epsilon...

        abs(f1 - f2) < epsilon

-- 
--
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list