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)
| 38 | |
| 39 | |
| 40 | def 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 |
no test coverage detected