3 ms·
I think of a float as an integer with a shift. Take the mantissa, stick on the implicit leading 1, put it in the middle of an infinitely big string of zeroes wi
by twic 7y ago
I think of a float as an integer with a shift. Take the mantissa, stick on the implicit leading 1, put it in the middle of an infinitely big string of zeroes with a decimal (well, binary) point at the right-hand end, then shift it by the exponent (which can be positive or negative).
If you're comfortable thinking about shifting integers, then perhaps this is a simple way to think about floats. For me, it's easier than thinking about them as fractions.
- deleted 7y ago[deleted]
- emmelaich 7y agoYep, this is how the Unix `bc` tool works; all numbers are internally simple decimal but have a `scale` and `length`. Scale is the number of dec digits after the decimal point and length is the number of significant figures. See `man bc`