1/07/2019

9999999999999999.0 – 9999999999999998.0 の答え

Geo Carncrossより浮動小数点演算も参照

単純な問題:

9999999999999999.0 - 9999999999999998.0

あなたのお気に入りのプログラミング言語は正しい答えを出しますか?

Ruby: irb(main):001:0> 9999999999999999.0 - 9999999999999998.0
2.0
Java: public class Foo{public static void main(String args[]){System.out.println(9999999999999999.0-9999999999999998.0);}}
2.0
Python: >>> 9999999999999999.0 - 9999999999999998.0
2.0
Rebol: >> 9999999999999999.0 - 9999999999999998.0
== 2.0
Haskell: % expr "9999999999999999.0-9999999999999998.0"
0.0
TCL: >>> 9999999999999999.0 - 9999999999999998.0
2.0
Emacs Lisp: ELISP> (- 9999999999999999.0 9999999999999998.0)
2.0
Common–Lisp: [1]> (- 9999999999999999.0 9999999999999998.0)
0.0
Maxima: (%i1) 9999999999999999.0-9999999999999998.0;
(%o1)           2.0
Google: 0
K/Q: q)9999999999999999.0-9999999999999998.0
2f
R: > 9999999999999999.0-9999999999999998.0
[1] 2.0
Erlang: 1> 9999999999999999.0-9999999999999998.0 .
2.0
C: main(){printf("%lf\n",(double)9999999999999999.0-9999999999999998.0);}
2.000000
AWK: $ awk 'END{print 9999999999999999.0-9999999999999998.0}'</dev/null
2
GoLang: var a = 9999999999999999.0; var b = 9999999999999998.0; fmt.Printf("%f\n", a-b)
2.000000
Perl: $ perl -e 'print 9999999999999999.0-9999999999999998.0;print "\n";'
2.0
Perl6: $ perl6 -e 'print 9999999999999999.0-9999999999999998.0;print "\n";'
1
Wolfram: 1
soup: 9999999999999999.0-9999999999999998.0
1

Hacker News