[Python-ideas] Way to check for floating point "closeness"?
solipsis at pitrou.net
Mon Jan 12 22:00:00 CET 2015
On Mon, 12 Jan 2015 12:04:47 -0800
Guido van Rossum <guido at python.org> wrote:
> So is 1e-100 close to 1e-50 with the default tolerance? What about 1e+100
> and (1e+100 plus one ulp)?
Indeed, there are different ways to express such a requirement. Numpy
uses a combination of relative and absolute difference (see
but you may also want a maximum number of ulps differing.
You also need special code for infinities and the like.
(and in some cases you may want to distinguish positive and negative
zeros, even though they are infinitely close :-))
More information about the Python-ideas