[Python-ideas] PEP 485: A Function for testing approximate equality

Antoine Pitrou solipsis at pitrou.net
Fri Jan 23 22:43:36 CET 2015


On Fri, 23 Jan 2015 08:51:00 -0800
Chris Barker <chris.barker at noaa.gov> wrote:
> 
> As for the ulps test -- can you suggest a way to do that, while also
> providing a simple definition of tolerance that casual users can understand
> and use (and have a reasonable default? I know I can't. Note that some of
> the feedback on the PEP as is is that it's too hard to understand already!
> (without better docs, anyway)

My approach was roughly:

  delta = 2 ** (ulps - 53 - 1) * (abs(first) + abs(second))
  assertAlmostEqual(first, second, delta=delta)

I don't know if it's right in the case of denormals etc.

(there's also special code surrounding that to care for zeros,
infinities, and NaNs)

Regards

Antoine.




More information about the Python-ideas mailing list