9999999999999999.0 – 9999999999999998.0
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}'</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 |
最后看看 ChatGPT 的回答:
来源:https://geocar.sdf1.org/numbers.html
本文文字及图片出自 OSC开源社区
你也许感兴趣的:
- 【程序员搞笑图片】数据类型简明指导
- 33 种编程语言的 UUIDv7 实现
- 【外评】Rust,你错了
- 【外评】为什么人们对 Go 1.23 的迭代器设计感到愤怒?
- 华为自研编程语言“仓颉”来了!鸿蒙应用开发新语言,性能优于 Java、Go、Swift
- 【外评】JavaScript 变得很好
- 【外评】华为发布自己的编程语言 “仓颉”
- VBScript 废弃:时间表和后续步骤
- 【外评】BASIC 编程语言 60 岁了
- 【外评】为什么 ALGOL 是一种重要的编程语言?
你对本文的反应是: