I tried to read on the IEEE standard about floating point implementation but it is quite advanced for me and I don’t program for a living.
This is something I wondered.
Suppose I have a float variable between 0 and N and I will scale it up when needed, but intermediary calculations will be done in this unnormalized value.
Logically, the range [0.0, 1.0] will be enough. But if I limit my numbers between 0 and 1, do I lose precision some way? Do I gain anything if I use [0, 10.0], or [0, 1000000.0]?
Thank you.
your idea is a good one, but you don’t save anything because, in a sense, floating point numbers are designed to do this for you.
internally, a float has two parts, called mantissa and exponent. the mantissa is equivalent to your range, and the exponent is the scaling needed to get it to the “real” value.
any number you give is normalised to a range like [1-9.999…] plus a power of 10 multiplier. so you get the precision of the mantissa for almost all values (the only exceptions are when you get to the extremes of the exponent – these are called “denormalized numbers” (or “subnormal”), but are extremely small (close to zero) or large, and not something you need worry about, normally).
so whether you enter 1.23 or 12.3 or 123, it’s stored as 1.23 (the mantissa) plus a factor (1, 10 or 100, the exponent) internally.
actually, that’s not quite true, because it uses powers of 2 (binary) rather than powers of ten (decimal) (see the comment from sixlettervariable), but it’s the same general idea.