在ActionScript 3奇怪的数学? [英] odd math in actionscript 3?

查看:152
本文介绍了在ActionScript 3奇怪的数学?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

      
  • <一个href="http://stackoverflow.com/questions/177506/why-do-i-see-a-double-variable-initialized-to-some-value-like-21-4-as-21-39999961">Why我看到初始化为一些价值像21.4作为21.399999618530273双变量?
  •   
  • 是JavaScript的数学坏了吗?
  •   
  • 在其他许多问题,对于每一种语言和平台,都用同样的答案。
  •   
  • Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?
  • Is JavaScript’s math broken?
  • many, many other questions, for every language and platform, all with the same answer.


trace( ">> " + (399.6-(Math.floor(399.6))) );

打印出

>> 0.6000000000000227

为什么?

推荐答案

浮点舍入误差。浮点数不能再present一些值完全相同,所以你看到的是使用FP数的限制。尾数(对FP民,使该精度的一部分)是只有一定的比特数,而当某物也不可能完全重新presented,则得到像上述结果。我知道一个事实,即0.1不能重新presented完全,所以它是有道理的,0.6不能为好。

Floating Point rounding errors. Floating point numbers can't represent some values exactly, so what you are seeing is the limitations of using FP numbers. The mantissa (the part of the FP num that gives the accuracy) is only a certain number of bits, and when something can't be exactly represented, you get results like the above. I know for a fact that 0.1 can't be represented exactly, so it makes sense that 0.6 can't as well.

这篇关于在ActionScript 3奇怪的数学?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆