Live data from Hacker News

9999999999999999.0 – 9999999999999998.0

geocar.sdf1.org

21–30 of 83 posts

Re: 9999999999999999.0 – 9999999999999998.0

#21
Floating-point literals are confusing. The basic arithmetic less so (although it too has some pitfalls). I said this before, but I think inexact literals (which are very common) should cause warnings in languages where used.

    >>> 9999999999999999.0 == 10000000000000000.0
    True
    >>> from decimal import Decimal as D
    >>> D(9999999999999999.0)
    Decimal('10000000000000000')
"It's a simple question" I find it very much not simple question; indeed I'm not sure what is the expected "right answer" here?

Re: 9999999999999999.0 – 9999999999999998.0

#22
post #14

Was curious what chatGPT would say: The result of subtracting 9999999999999998.0 from 9999999999999999.0 is 2.0. This result is due to the limitations in the precision of floating-point arithmetic in computers. When dealing with very large numbers, the precision can be lost, leading to such unexpected results. I suppose this must be in its training set.

these days it looks like ChatGPT generates and runs code behind the scenes for math questions (it used to be pretty bad at these kinds of math questions. you can click the little "view analysis" button to see the code it's running.

when I ask about this question it generates and runs Python behind the scenes, thus the incorrect answer.

Re: 9999999999999999.0 – 9999999999999998.0

#24
post #14

Was curious what chatGPT would say: The result of subtracting 9999999999999998.0 from 9999999999999999.0 is 2.0. This result is due to the limitations in the precision of floating-point arithmetic in computers. When dealing with very large numbers, the precision can be lost, leading to such unexpected results. I suppose this must be in its training set.

Just asking for the subtraction it just gives me 1.0, what did you ask?

Re: 9999999999999999.0 – 9999999999999998.0

#26
post #22
post #14

Was curious what chatGPT would say: The result of subtracting 9999999999999998.0 from 9999999999999999.0 is 2.0. This result is due to the limitations in the precision of floating-point arithmetic in computers. When dealing with very large numbers, the precision can be lost, leading to such unexpected results. I suppose this must be in its training set.

these days it looks like ChatGPT generates and runs code behind the scenes for math questions (it used to be pretty bad at these kinds of math questions. you can click the little "view analysis" button to see the code it's running. when I ask about this question it generates and runs Python behind the scenes, thus the incorrect answer.

Although it offers an explanation, which is something it could not do by just evaluating the expression. So the explanation is in its training set. And given that this is an understood flaw or limitation, it is possible it didn't even need to run any code.

Re: 9999999999999999.0 – 9999999999999998.0

#27
post #14

Was curious what chatGPT would say: The result of subtracting 9999999999999998.0 from 9999999999999999.0 is 2.0. This result is due to the limitations in the precision of floating-point arithmetic in computers. When dealing with very large numbers, the precision can be lost, leading to such unexpected results. I suppose this must be in its training set.

Hmm, I asked Bing Chat in Precise mode and got the correct answer:

Q: What is the result of subtracting 9999999999999998.0 from 9999999999999999.0

A: The result of subtracting 9999999999999998.0 from 9999999999999999.0 is 1.0. Here is the calculation: 9999999999999999.0−9999999999999998.0=1.0

I also tried a variation and it's still correct, maybe it's using a calculator plugin:

Q: What is the result of 1239995999999999.0 - 1239995999999998.0

A: The result of the subtraction operation 1239995999999999.0−1239995999999998.0 is 1.0

Re: 9999999999999999.0 – 9999999999999998.0

#29
post #17

> That Go uses arbitrary-precision for constant expressions seems dangerous to me. I'm somewhat baffled by this statement. If a Go program compared a constant expression float against a runtime computed float, it could have unexpected results, but comparing floats in general is dangerous. I don't see how this language quirk increases that danger in a meaningful way.

It's not an issue an issue about whether or not efficient float formats are dangerous to work with rather one of whether they are consistent to work with in a language. It's simple enough to remember when reading about it but will you and everyone else know this from the start and remember it every time it comes up without fail?

That said, for the negatives it comes with it does come with positives as well and I think that makes it worth it.

Post reply on HN