-12

I know the question here:

Is floating point math broken?

explains why 0.1 + 0.2 == 0.3 is false well. But I think it fails to explain the case that why a very large float number with integer value is rounded up, here is an example:

Why does my float of 999999999 become 10000000000?

because I think the reason of 0.1 being rounded up is different from 999999999 being rounded up. Consider the answer here : https://stackoverflow.com/a/588014/9059929

Under my interpretation, the denominator of 0.1 is not the power of two, so it needs to be rounded up, but the denominator of 999999999 is 1, which is the power of two, but still rounded up.

So my question is , why are questions about a very large floating number rounded up still a duplicate of 'Is floating point math broken?'?

2
  • 8
    Why do you think it fails to explain it?
    – Stephen Rauch Mod
    Feb 22, 2018 at 2:41
  • 1
    "because I think the reason of 0.1 being rounded up is different from 999999999 being rounded up' - Well you are wrong. The fundamental reason is the same in both cases.
    – Stephen C
    Feb 22, 2018 at 11:01

2 Answers 2

14

This is precisely why we need that question, and why you should read the answers (keep reading them until you find one that makes sense to you; different people understand different explanations).

You're thinking about this as though floating point was a superset of integers, some chimera of precise integer representation and imprecise fractional... But that's not how it works. Every number you store as a floating-point type is a floating-point number, and inherently imprecise (if not when initially stored then certainly as soon as you do anything non-trivial with it). You can't treat them as integers until you think you might have a fractional portion; they're different formats from start to finish.

The answers to that question are as true for 0.9 as they are for 9.0 or 999999999... The only difference is whether you notice it.

0
11

Because it's still a limitation of floating-point representation. Not only is the scaling limited to powers of two, but the range of the mantissa is limited as well.

But we're getting off topic for Meta. You need to go back and fully read "Is floating point math broken?" (Highly upvoted answers such as this one explain things the accepted answer doesn't), along with both versions of "What every computer scientist needs to know about floating-point". "Why is floating-point math inaccurate?" has some of that discussion in the accepted answer, instead of halfway down the page.

Your answer is in there.

Not the answer you're looking for? Browse other questions tagged .