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

Function ulp_abs_check

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

105 return outer << (n - count_set_bits(n))
106
107def ulp_abs_check(expected, got, ulp_tol, abs_tol):
108 """Given finite floats `expected` and `got`, check that they&#x27;re
109 approximately equal to within the given number of ulps or the
110 given absolute tolerance, whichever is bigger.
111
112 Returns None on success and an error message on failure.
113 """
114 ulp_error = abs(to_ulps(expected) - to_ulps(got))
115 abs_error = abs(expected - got)
116
117 # Succeed if either abs_error <= abs_tol or ulp_error <= ulp_tol.
118 if abs_error <= abs_tol or ulp_error <= ulp_tol:
119 return None
120 else:
121 fmt = ("error = {:.3g} ({:d} ulps); "
122 "permitted error = {:.3g} or {:d} ulps")
123 return fmt.format(abs_error, ulp_error, abs_tol, ulp_tol)
124
125def parse_mtestfile(fname):
126 """Parse a file with test values

Callers 1

result_checkFunction · 0.85

Calls 3

to_ulpsFunction · 0.85
absFunction · 0.50
formatMethod · 0.45

Tested by

no test coverage detected