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)
| 39 | |
| 40 | |
| 41 | def 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 | |
| 58 | def ulp_abs_check(expected, got, ulp_tol, abs_tol): |
no test coverage detected
searching dependent graphs…