Exemple #1
0
 def test_round_trip(self):
     test_data = [struct.unpack('<f', os.urandom(4))[0]
                  for _ in range(1000)]
     for value in test_data:
         round_tripped = hex_to_float(float_to_hex(value))
         if math.isnan(value):
             assert math.isnan(round_tripped)
         else:
             assert round_tripped == value
Exemple #2
0
 def test_round_trip(self):
     test_data = [
         _pad_to(hex(struct.unpack('<I', os.urandom(4))[0]), 8)
         for _ in range(1000)]
     for value in test_data:
         fromhex = hex_to_float(value)
         if math.isnan(fromhex):
             continue
         round_tripped = float_to_hex(fromhex)
         assert round_tripped == value
Exemple #3
0
 def test_negative_inf(self):
     expected = '0xff800000'
     result = float_to_hex(-float('inf'))
     assert result == expected
Exemple #4
0
 def test_inf(self):
     expected = '0x7f800000'
     result = float_to_hex(float('inf'))
     assert result == expected
Exemple #5
0
 def test_nan(self):
     round_tripped = hex_to_float(float_to_hex(float('nan')))
     assert math.isnan(round_tripped)
Exemple #6
0
 def test_negative_zero(self):
     expected = '0x80000000'
     result = float_to_hex(-0.0)
     assert result == expected
Exemple #7
0
 def test_zero(self):
     expected = '0x00000000'
     result = float_to_hex(0.0)
     assert result == expected