本文介绍了是否有一个定点库动作3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想美元的Flex的C $ CA的计算器,但不能在网上找到的任何定点库。

I would like to code a calculator in Flex but can't find any fixed-point libraries on the web.

有关计算器,我需要更多的precision然后IEEE 754可以保证。例如:

For the calculator, I need more precision then IEEE 754 can guarantee. For example:

trace(1.4 - .4); //should be 1 but it is 0.9999999999999999

可有人提出一个很好的定点库好吗?

Can someone suggest a good fixed-point library please ?

感谢你在前进

推荐答案

它的工作原理,但它并不是完美的,所有的学分转到乔希从的

It works but it is not perfect, all credits go to Josh from http://joshblog.net/2007/01/30/flash-floating-point-number-errors/

/**
 * Corrects errors caused by floating point math.
 */
public function correctFloatingPointError(number:Number, precision:int = 5):Number
{
    //default returns (10000 * number) / 10000
    //should correct very small floating point errors
    var correction:Number = Math.pow(10, precision);
    return Math.round(correction * number) / correction;
}
/**
 * Tests if two numbers are <em>almost</em> equal.
 */
public function fuzzyEquals(number1:Number, number2:Number, precision:int = 5):Boolean
{
    var difference:Number = number1 - number2;
    var range:Number = Math.pow(10, -precision);
    //default check:
    //0.00001 <difference> -0.00001
    return difference <range && difference> -range;
}
/*
Copyright (c) 2007 Josh Tynjala
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

再次谢谢:)

Thank you again :)

这篇关于是否有一个定点库动作3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 13:14