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

问题描述

我想打造的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?

感谢你在前进,阿德南

Thank you in advance,Adnan

推荐答案

欢迎到IEEE 754浮点。享受不准确的。如果你想避免他们使用定点机构。

Welcome to IEEE 754 floating point. Enjoy the inaccuracies. Use a fixed-point mechanism if you want to avoid them.

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

09-24 12:39