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

Function _calc_errors

Lib/test/test_statistics.py:72–85  ·  view source on GitHub ↗

Return the absolute and relative errors between two numbers. >>> _calc_errors(100, 75) (25, 0.25) >>> _calc_errors(100, 100) (0, 0.0) Returns the (absolute error, relative error) between the two arguments.

(actual, expected)

Source from the content-addressed store, hash-verified

70
71
72def _calc_errors(actual, expected):
73 """Return the absolute and relative errors between two numbers.
74
75 >>> _calc_errors(100, 75)
76 (25, 0.25)
77 >>> _calc_errors(100, 100)
78 (0, 0.0)
79
80 Returns the (absolute error, relative error) between the two arguments.
81 """
82 base = max(abs(actual), abs(expected))
83 abs_err = abs(actual - expected)
84 rel_err = abs_err/base if base else float('inf')
85 return (abs_err, rel_err)
86
87
88def approx_equal(x, y, tol=1e-12, rel=1e-7):

Callers 2

_make_std_err_msgMethod · 0.85
generate_substringsMethod · 0.85

Calls 1

absFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…