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.
9999999999999999.0 – 9999999999999998.0
51–60 of 83 posts
Re: 9999999999999999.0 – 9999999999999998.0
#52The 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…
Re: 9999999999999999.0 – 9999999999999998.0
#53The 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…
(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
#54Re: 9999999999999999.0 – 9999999999999998.0
#55Re: 9999999999999999.0 – 9999999999999998.0
#56Nim gives the wrong answer (2.0). I've posted this to the Nim forum: https://forum.nim-lang.org/t/10866#72441
Re: 9999999999999999.0 – 9999999999999998.0
#57The 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.
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
#58Postgres 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 = 272564226Re: 9999999999999999.0 – 9999999999999998.0
#59Postgres 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…
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
#60Earlier 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"
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.