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

Function _nan_equal

Lib/test/test_statistics.py:41–69  ·  view source on GitHub ↗

Return True if a and b are both the same kind of NAN. >>> _nan_equal(Decimal('NAN'), Decimal('NAN')) True >>> _nan_equal(Decimal('sNAN'), Decimal('sNAN')) True >>> _nan_equal(Decimal('NAN'), Decimal('sNAN')) False >>> _nan_equal(Decimal(42), Decimal('NAN')) False

(a, b)

Source from the content-addressed store, hash-verified

39 return math.copysign(1, x)
40
41def _nan_equal(a, b):
42 """Return True if a and b are both the same kind of NAN.
43
44 >>> _nan_equal(Decimal('NAN'), Decimal('NAN'))
45 True
46 >>> _nan_equal(Decimal('sNAN'), Decimal('sNAN'))
47 True
48 >>> _nan_equal(Decimal('NAN'), Decimal('sNAN'))
49 False
50 >>> _nan_equal(Decimal(42), Decimal('NAN'))
51 False
52
53 >>> _nan_equal(float('NAN'), float('NAN'))
54 True
55 >>> _nan_equal(float('NAN'), 0.5)
56 False
57
58 >>> _nan_equal(float('NAN'), Decimal('NAN'))
59 False
60
61 NAN payloads are not compared.
62 """
63 if type(a) is not type(b):
64 return False
65 if isinstance(a, float):
66 return math.isnan(a) and math.isnan(b)
67 aexp = a.as_tuple()[2]
68 bexp = b.as_tuple()[2]
69 return (aexp == bexp) and (aexp in ('n', 'N')) # Both NAN or both sNAN.
70
71
72def _calc_errors(actual, expected):

Callers 3

test_decimal_nanMethod · 0.85
test_nanMethod · 0.85
test_nanMethod · 0.85

Calls 1

as_tupleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…