Given finite floats `expected` and `got`, check that they're approximately equal to within the given number of ulps or the given absolute tolerance, whichever is bigger. Returns None on success and an error message on failure.
(expected, got, ulp_tol, abs_tol)
| 56 | |
| 57 | |
| 58 | def ulp_abs_check(expected, got, ulp_tol, abs_tol): |
| 59 | """Given finite floats `expected` and `got`, check that they're |
| 60 | approximately equal to within the given number of ulps or the |
| 61 | given absolute tolerance, whichever is bigger. |
| 62 | |
| 63 | Returns None on success and an error message on failure. |
| 64 | """ |
| 65 | ulp_error = abs(to_ulps(expected) - to_ulps(got)) |
| 66 | abs_error = abs(expected - got) |
| 67 | |
| 68 | # Succeed if either abs_error <= abs_tol or ulp_error <= ulp_tol. |
| 69 | if abs_error <= abs_tol or ulp_error <= ulp_tol: |
| 70 | return None |
| 71 | else: |
| 72 | fmt = ("error = {:.3g} ({:d} ulps); " |
| 73 | "permitted error = {:.3g} or {:d} ulps") |
| 74 | return fmt.format(abs_error, ulp_error, abs_tol, ulp_tol) |
| 75 | |
| 76 | def parse_mtestfile(fname): |
| 77 | """Parse a file with test values |
no test coverage detected
searching dependent graphs…