MCPcopy Index your code
hub / github.com/RustPython/RustPython / to_ulps

Function to_ulps

Lib/test/test_math.py:40–54  ·  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

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

Callers 1

ulp_abs_checkFunction · 0.85

Calls 2

unpackMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected