Hacker News 上的昨日热帖,求 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: Prelude> 9999999999999999.0 - 9999999999999998.0
2.0 TCL: % expr "9999999999999999.0-9999999999999998.0"
0.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 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}'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
最后看看 ChatGPT 的回答:
来源: https://geocar.sdf1.org/numbers.html
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.