Comment on: [Humor] How to save the princess using 8 programming languages
3 06 Oct 2016 18:25 u/qx9 in v/programmingComment on: Concerning type float, if I typed out 38 digits, put a decimal point anywhere on that number except for the ends, and chose my 7 significant digits, can I really deal with those significant digits?
That's not a good example because multiplying by a power of two just bumps the exponent and doesn't change the mantissa, so no accuracy is lost unless it overflows. The expressions 4.59 * 8 and 4.59 * 2.0 * 2.0 * 2.0 will always be equal. A better example would be 4.59 * 1.331 which is more accurate than 4.59 * 1.1 * 1.1 * 1.1.
Comment on: Concerning type float, if I typed out 38 digits, put a decimal point anywhere on that number except for the ends, and chose my 7 significant digits, can I really deal with those significant digits?
@mort is right. Some numbers can be represented with perfect accuracy, and if the result is such a number then you don't lose accuracy. For example, 0.125 * 8 always equals 1 because 0.125, 8 and the result can all be represented perfectly as floats. That is the exception though, in most cases accuracy is lost.
Rescuing the princess is impossible, since both the princess and castle are immutable.
Instead, you make a new princess that is free but otherwise identical.