def test_float(self): def close(a, b): assert abs(a - b) < 0.0001 close(Bits.from_float(1.5).float, 1.5) close(Bits.from_float(-1.5).float, -1.5) close(Bits.from_float(0.0).float, 0.0) close(Bits.from_float(1.2).float, 1.2)
def test_from_float(self): assert Bits.from_float(1.5) == Bits.from_hex(0x3fc00000, 32) assert Bits.from_float(-1.5) == Bits.from_hex(0xbfc00000, 32) assert Bits.from_float(0.0) == Bits(size=32) assert Bits.from_float(1.2) == Bits.from_hex(0x3f99999a, 32)