Please help me to understand this code snippet:
def binary_float_to_int(float_number: float) -> int:
return ctypes.c_uint.from_buffer(ctypes.c_float(float_number)).value
The results from these inputs:
print(binary_float_to_int(7.1746481e-43))
print(binary_float_to_int(5.3809861e-43))
Are: 512 & 384
Why does the simple Python conversion int(7.1746481e-43) not work?
Are there any other ways to do this type of conversion?
int(7.1746481e-43)works fine so far as I can see.int()rounds towards zero, and7.1746481e-43is less than 1. I'm not sure whatbinary_float_to_int()is doing, but7.1746481e-43isn't anywhere close to512.