douxin2002 2012-10-05 04:00
浏览 23
已采纳

为什么这个比较不起作用? [重复]

Possible Duplicate:
Is JavaScript's Math broken?

If(0.3-0.2==0.2-0.1) most of programming language showing result false.So I want to know which Language Support this statement true and why most of language shows false.

Tested in Javascript and PHP. Why does this happen?

  • 写回答

1条回答 默认 最新

  • duanhunlou7051 2012-10-05 04:03
    关注

    The reason that this happens is not to do necessarily with a language, per se, but an implementation. The answer to this question is that when you write If(0.3-0.2==0.2-0.1), you are thinking that the operations performed are in the rationals, this is false, they are indeed in floating point arithmetic. Indeed, within floating point arithmetic, this is false! So the answer is: any language which defaults to interpreting constants in an arbitrarily precise arithmetic. (For example, if these had been written in Haskell using a Rational number, then the test would have "worked.") For completeness: the Racket language does this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度