views:

145

answers:

1

The question I meant to ask concerned the mantissa, not the exponent, and has lots to do with the question I asked earlier in the week regarding "missing" digits on the sum of two negative floats.

Given that the mantissa has a variable precision, how does one tell if one has overflowed the mantissa's current precision setting? Or, from the proactive side, how can one tell if mantissa precision overflow is likely?

Kind regards, Bruce.

+1  A: 

There are a few numerical methods to see if you're going to lose precision, but the bottom line is that you need to understand the definition of precision better.

-4939600281397002.2812

and

-4939600281397002.2812000000000000

are NOT the same number.

When you add

-2234.6016114467412141

and

-4939600281397002.2812

together, the correct output will only have 20 digits of precision, because the additional 12 digits in the smaller number are meaningless given that the 12 similarly sized digits in the larger number are unknown. You can imply that they are zero, but if that's the case then you must explicitly declare them to be as such, and use a numbering system that can handle it - the computer is not good at understanding implicit intentions.

As far as detecting when you are going to have this problem, all you need to do is find out if they have the same exponent (assuming a normalized mantissa +/- 1 or similar binary equivalent). If they aren't normalized, then you'll need to normalize them to compare, or use a slightly more complex comparison with the exponent.

Precision and accuracy are not the same thing...

Adam Davis