Live data from Hacker News

9999999999999999.0 – 9999999999999998.0

geocar.sdf1.org

51–60 of 83 posts

Re: 9999999999999999.0 – 9999999999999998.0

#51
post #41

Wolfram seems to excel at so many things, but does anyone actually use it? https://www.wolframalpha.com

Only every high school and college student everywhere.

No kidding. I don't trust my own by hand calculations anymore. And why bother? I'd rather just write down the equation I need and let a computer do the rest.

Re: 9999999999999999.0 – 9999999999999998.0

#52
post #33

The page never explicitly states what the right answer is, but based on the output of their suggested "correct" perl, we can infer that they expect 1. This is just me being idiosyncratic I guess, but if I see a number with a decimal place, I default to interpreting it as an fp64 unless otherwise specified - which yields a "correct" answer of 2.0 (which is not an answer I can get to in my head, admittedly) If the ques…

The page is asking which language answers the math question correctly, not which one implements a particular standard correctly. Perl6 also has a correct implementation, it's just using a different standard than the other languages.

Re: 9999999999999999.0 – 9999999999999998.0

#53
post #33

The page never explicitly states what the right answer is, but based on the output of their suggested "correct" perl, we can infer that they expect 1. This is just me being idiosyncratic I guess, but if I see a number with a decimal place, I default to interpreting it as an fp64 unless otherwise specified - which yields a "correct" answer of 2.0 (which is not an answer I can get to in my head, admittedly) If the ques…

I wasn't surprised, but that is not what I would expect if I were to see that expression. Two reasons for that: even though there is a decimal, I still mentally parsed it as an integer, and I wouldn't be thnking of the precision of the value.

(That said, I would never enter an integer with a decimal, and I would think of precision if it was a float. That said that said, there are other ways to bump into that problem which wouldn't make it so obvious - such as dealing with inputs from a user.)

Re: 9999999999999999.0 – 9999999999999998.0

#57
post #33

The page never explicitly states what the right answer is, but based on the output of their suggested "correct" perl, we can infer that they expect 1. This is just me being idiosyncratic I guess, but if I see a number with a decimal place, I default to interpreting it as an fp64 unless otherwise specified - which yields a "correct" answer of 2.0 (which is not an answer I can get to in my head, admittedly) If the ques…

The page is asking which language answers the math question correctly, not which one implements a particular standard correctly. Perl6 also has a correct implementation, it's just using a different standard than the other languages.

"math" is just yet another (implicit and at times poorly defined) standard.

The answers are all equally "correct" given a particular set of operating rules, the interesting part is what rules they picked.

Edit: See also, https://en.wikipedia.org/wiki/Definitions_of_mathematics - "Mathematics has no generally accepted definition"

Re: 9999999999999999.0 – 9999999999999998.0

#58

Postgres and SQL: postgres=# select 9999999999999999.0 - 9999999999999998.0 as result; result -------- 1.0

The default PG type, `numeric`, has almost arbitary precision. select pg_typeof(9999999999999999.0); -- numeric select 9999999999999999.0::double precision - 9999999999999998.0::double precision; -- 2 More interesting perhaps, is mixing up `real` (aka float32) with `numeric`: select 9999999999999999.0::real - 9999999999999998.0; -- 272564226 (?! can anyone explain?) select 9999999999999999.0::real; -- 100000003000000…

    #include

    int main(void) {
      long a = (float)9999999999999999;
      long b = 9999999999999998;
      printf("%ld - %ld = %ld\n", a, b, a-b);
    }

produces

    10000000272564224 - 9999999999999998 = 272564226

Re: 9999999999999999.0 – 9999999999999998.0

#59

Postgres and SQL: postgres=# select 9999999999999999.0 - 9999999999999998.0 as result; result -------- 1.0

The default PG type, `numeric`, has almost arbitary precision. select pg_typeof(9999999999999999.0); -- numeric select 9999999999999999.0::double precision - 9999999999999998.0::double precision; -- 2 More interesting perhaps, is mixing up `real` (aka float32) with `numeric`: select 9999999999999999.0::real - 9999999999999998.0; -- 272564226 (?! can anyone explain?) select 9999999999999999.0::real; -- 100000003000000…

The `real` type (float32) only has 24 bits of precision. So converting `9999999999999999.0` or `10000000000000000` or even `10000000300000000` yields the 32-bit float `10000000272564224`.

For some reason Postgres prints it as `10000000300000000`. It uses a heuristic to print a "pretty" number that converts to the actual stored value, and it's not smart enough to give `10000000000000000`. Some heuristic like this is needed so something like `0.3` doesn't print the actual stored value of `0.300000011920928955078125`, which would be confusing.

You can check all this here: https://www.h-schmidt.net/FloatConverter/IEEE754.html

Re: 9999999999999999.0 – 9999999999999998.0

#60
post #57

Earlier quoted context omitted.

The page is asking which language answers the math question correctly, not which one implements a particular standard correctly. Perl6 also has a correct implementation, it's just using a different standard than the other languages.

"math" is just yet another (implicit and at times poorly defined) standard. The answers are all equally "correct" given a particular set of operating rules, the interesting part is what rules they picked. Edit: See also, https://en.wikipedia.org/wiki/Definitions_of_mathematics - "Mathematics has no generally accepted definition"

I agree that what we call "math" is just a set of rules that could be defined differently, but a standard like IEEE-754 is downstream of math, and is explicitly defined as a method to perform arithmetic (which is part of math).

So they aren't on the same level, IEEE-754 is not an alternative standard to math. The answers can all be considered correct by a certain definition, but they are not equally correct in our shared context as human beings who know what math is.

Post reply on HN