3 ms·
This. But you can get pretty close to "stuffing in the bits". What we used to do to get a random float: Set the exponent to 0 and stuff in bits for the signifi
by mabster 5y ago
This. But you can get pretty close to "stuffing in the bits". What we used to do to get a random float:
Set the exponent to 0 and stuff in bits for the significand. This gets you a random float in the range [1,2). Now subtract 1.0.
Note that this misses many floating point values that should be selectable if you wanted all floats between 1 and 2, but it was good enough for video games.
It's worth pointing out that IEEE 754-2008 has decimal numbers like you describe without the hidden bit. But for decimals this can be really useful because numbers "remember" their exponent. So if you're doing addition of dollar values, for example, .84 + .12 = 1.00 rather than 1 (i.e. it remembers its significant digits).
- dnautics 5y agoRemembering significant digits is not really that important in fintech applications, as you're usually in a fixed-point system that is pinned to the currency (dollar transactions usually down to the cent, handful of arabics down to the millimes, yen cut off at single unit).