[Python-Dev] math.areclose ...? (original) (raw)

Raymond Hettinger raymond.hettinger at verizon.net
Mon Feb 6 22:37:22 CET 2006


[Chris Smith]

Does it help to spell it like this?

def areclose(x, y, relativeerr = 1.e-5, absoluteerr=1.e-8): diff = abs(x - y) ave = (abs(x) + abs(y))/2 return diff < absoluteerr or diff/ave < relativeerr

There is a certain beauty and clarity to this presentation; however, it is problematic numerically:

The original Numeric definition is likely to be better for people who know what they're doing; however, I still question whether it is an appropriate remedy for the beginner issue of why 1.1 + 1.1 + 1.1 doesn't equal 3.3.

Raymond



More information about the Python-Dev mailing list