MCPcopy Index your code
hub / github.com/python/cpython / to_ulps

Function to_ulps

Lib/test/test_math.py:41–55  ·  view source on GitHub ↗

Convert a non-NaN float x to an integer, in such a way that adjacent floats are converted to adjacent integers. Then abs(ulps(x) - ulps(y)) gives the difference in ulps between two floats. The results from this function will only make sense on platforms where native doubles are

(x)

Source from the content-addressed store, hash-verified

39
40
41def to_ulps(x):
42 """Convert a non-NaN float x to an integer, in such a way that
43 adjacent floats are converted to adjacent integers. Then
44 abs(ulps(x) - ulps(y)) gives the difference in ulps between two
45 floats.
46
47 The results from this function will only make sense on platforms
48 where native doubles are represented in IEEE 754 binary64 format.
49
50 Note: 0.0 and -0.0 are converted to 0 and -1, respectively.
51 """
52 n = struct.unpack('<q', struct.pack('<d', x))[0]
53 if n < 0:
54 n = ~(n+2**63)
55 return n
56
57
58def ulp_abs_check(expected, got, ulp_tol, abs_tol):

Callers 1

ulp_abs_checkFunction · 0.85

Calls 2

unpackMethod · 0.80
packMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…