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

Function ulp_abs_check

Lib/test/test_math.py:58–74  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

56
57
58def 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
76def parse_mtestfile(fname):
77 """Parse a file with test values

Callers 1

result_checkFunction · 0.85

Calls 3

absFunction · 0.85
to_ulpsFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…