Say I have two Python floats a
and b
, is there an easy way to find out how many representable real numbers are between the two in IEEE-754 representation (or whatever representation the machine used is using)?
AFAIK, IEEE754 floats have an interesting property. If you have float f, then
(*(int*)&f + 1)
under certain conditions, is the next representable floating point number. So for floats a and b
*(int*)&a - *(int*)&b
Will give you the amount of floating point numbers between those numbers.
See http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With