Actionscript 3 数学不一致 [英] Actionscript 3 Math inconsistencies
问题描述
我正在尝试在 Flex/actionscript 3 中构建一个计算器,但是使用 Math 类得到了一些奇怪的结果:
I'm trying to build a calculator in Flex / actionscript 3 but have some weird results using the class Math :
trace(1.4 - .4); //should be 1 but it is 0.9999999999999999
trace(1.5 - .5); //should be 1 and it is 1
trace(1.444 - .444); //should be 1 and it is 1
trace(1.555 - .555); //should be 1 but it is 0.9999999999999999
我知道浮点数存在一些问题,但正如您所见,它至少应该对我的所有示例都失败,对吗?
I know there are some issues with floating point numbers, but as you can see, it should at least fail for all of my examples, am I right?
这个问题在其他计算器中是如何解决的,我应该如何在 Actionscript 3 中构建一个可用的计算器?
How the problem is solved in other calculators and how should I proceed in order to build a usable calculator in Actionscript 3 please?
先谢谢你,阿德南
推荐答案
欢迎使用 IEEE 754 浮点数.享受不准确之处.如果您想避免它们,请使用定点机制.
Welcome to IEEE 754 floating point. Enjoy the inaccuracies. Use a fixed-point mechanism if you want to avoid them.
这篇关于Actionscript 3 数学不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!