[issue39310] Add math.ulp(x)
STINNER Victor
report at bugs.python.org
Sun Jan 12 07:33:34 EST 2020
New submission from STINNER Victor <vstinner at python.org>:
In bpo-39288, I added math.nextafter(x, y) function. I propose to now add math.ulp() companion function.
Examples from tests of my PR:
self.assertEqual(math.ulp(1.0), sys.float_info.epsilon)
self.assertEqual(math.ulp(2.0 ** 52), 1.0)
self.assertEqual(math.ulp(2.0 ** 53), 2.0)
self.assertEqual(math.ulp(2.0 ** 64), 4096.0)
Unit in the last place:
* https://en.wikipedia.org/wiki/Unit_in_the_last_place
* Java provides a java.lang.Math.ulp(x) function: https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#ulp-double-
In numpy, I found two references to ULP:
* numpy.testing.assert_array_almost_equal_nulp:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.testing.assert_array_almost_equal_nulp.html
* numpy.testing.assert_array_max_ulp:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.testing.assert_array_max_ulp.html
Attached PR implements math.ulp(x).
----------
components: Library (Lib)
messages: 359846
nosy: vstinner
priority: normal
severity: normal
status: open
title: Add math.ulp(x)
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39310>
_______________________________________
More information about the Python-bugs-list
mailing list