[SciPy-user] numerical accuracy

Steve Schmerler elcorto at gmx.net
Wed Dec 21 06:10:38 CST 2005


Hi

I think this is a general Python and not pure scipy topic:

#############################################################################################

In [26]: from scipy import arange

In [27]: ar = arange(0, 0.5, 0.05); a = ar[4]

In [28]: a
Out[28]: 0.20000000000000001

In [29]: b = 0.2

In [30]: b
Out[30]: 0.20000000000000001

In [31]: a == b
Out[31]: True

In [32]: c = 1.0 - 0.8

In [33]: c
Out[33]: 0.19999999999999996

In [34]: a == c
Out[34]: False

In [35]: a - b
Out[35]: 0.0

In [36]: a - c
Out[36]: 5.5511151231257827e-17

#############################################################################################

If a and c are "equal" regarding the numerical accury (a - c < 1e-16), 
aren't they supposed to be considered equal when comparing them?

cheers,
steve

-- 
Should array indices start at 0 or 1? My compromise of 0.5 was rejected 
without, I thought, proper consideration.
-- Stan Kelly-Bootle



More information about the SciPy-user mailing list