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

Method test_binary_floats

Lib/test/test_numeric_tower.py:87–106  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

85 self.check_equal_hash(n, float(n))
86
87 def test_binary_floats(self):
88 # check that floats hash equal to corresponding Fractions and Decimals
89
90 # floats that are distinct but numerically equal should hash the same
91 self.check_equal_hash(0.0, -0.0)
92
93 # zeros
94 self.check_equal_hash(0.0, D(0))
95 self.check_equal_hash(-0.0, D(0))
96 self.check_equal_hash(-0.0, D('-0.0'))
97 self.check_equal_hash(0.0, F(0))
98
99 # infinities and nans
100 self.check_equal_hash(float('inf'), D('inf'))
101 self.check_equal_hash(float('-inf'), D('-inf'))
102
103 for _ in range(1000):
104 x = random.random() * math.exp(random.random()*200.0 - 100.0)
105 self.check_equal_hash(x, D.from_float(x))
106 self.check_equal_hash(x, F.from_float(x))
107
108 def test_complex(self):
109 # complex numbers with zero imaginary part should hash equal to

Callers

nothing calls this directly

Calls 6

check_equal_hashMethod · 0.95
DClass · 0.90
FClass · 0.70
randomMethod · 0.45
expMethod · 0.45
from_floatMethod · 0.45

Tested by

no test coverage detected