Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 为什么Actionscript为大值的模数显示不同的值?_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 为什么Actionscript为大值的模数显示不同的值?

Actionscript 3 为什么Actionscript为大值的模数显示不同的值?,actionscript-3,flash,Actionscript 3,Flash,使用Flash CS4和Actionscript 3,我键入以下内容: trace(Math.pow(97,83) % 205); 结果是86。但是,如果我输入Wolfram Alpha: 97^83 mod 205 我得到13分,这是正确的答案。为什么actionscript显示了错误的值 谢谢, 这是由于数字类型的浮点精度造成的。Flash仅使用64位表示Math.pow(97,83)的结果,其中53位用于描述浮点数的尾数部分。对于53位,在需要对数字进行四舍五入之前,只能获得15-

使用Flash CS4和Actionscript 3,我键入以下内容:

 trace(Math.pow(97,83) % 205);
结果是86。但是,如果我输入Wolfram Alpha:

 97^83 mod 205
我得到13分,这是正确的答案。为什么actionscript显示了错误的值

谢谢,
这是由于数字类型的浮点精度造成的。Flash仅使用64位表示Math.pow(97,83)的结果,其中53位用于描述浮点数的尾数部分。对于53位,在需要对数字进行四舍五入之前,只能获得15-16位的精度。由于Math.pow(97,83)是一个大约164位长的数字,Flash的近似形式为7.98093813043768e+164

这不是Math.pow(97,83)的精确值,因为精度降低,因此在计算mod时会产生不好的结果


Wolfram Alpha可能使用一个专门的库来计算大量数字,而不会损失精度。我不知道ActionScript3有任何这样的库,但谷歌可能会提供帮助;)

因为
97^83
的结果太大,无法在AS3中正确计算。

当你在上面有一个@goddaver的正确答案时,这是我的5美分

var test:String = "";

// a binary number with bit 53 up
test += "10000000"; // 8
test += "00000000"; // 16
test += "00000000"; // 24
test += "00000000"; // 32
test += "00000000"; // 40
test += "00000000"; // 48
test += "00000";    // 53

trace("test", test);
trace(parseInt(test, 2).toString(2) == test); // true

test += "1"; // bit 0 and 54 up, the rest -- down

var chck:String = parseInt(test, 2).toString(2);
trace("test", test);
trace("chck", chck);
trace(chck == test); // false
这将产生:

test 10000000000000000000000000000000000000000000000000000
true
test 100000000000000000000000000000000000000000000000000001
chck 100000000000000000000000000000000000000000000000000000
false
所以,你可以使用整数,直到

dec: 9007199254740991
hex: 1FFFFFFFFFFFFF
bin: 11111111111111111111111111111111111111111111111111111
以下是另一个示例:

trace(parseFloat("9007199254740993") == parseFloat("9007199254740992"));
// output: true

搜索“as3 biginteger”会得到一些相关的结果。我搜索了as3 biginteger,发现了as3crypto:|很难理解它是如何工作的,因为我知道:var a:biginteger=new biginteger(“50”,10);微量元素(a.toString(10));答案是280。我还可以使用其他库吗?做trace(chck==test);?背后的逻辑是什么??你能给我点光吗。我很好奇,但不明白。
test
只是一个包含0和1个字符的字符串
parseInt()
用于将字符串
test
转换为数字。我要做的是将
test
转换为数字,然后再转换回字符串。转换结果保存到
chck
。然后,我比较了前后转换测试的结果。结果不匹配,因此我们已经达到了部分数字的上限。感谢您的回答:)。。。你有什么建议?我是否应该拆分整数以便能够执行pow?我建议您应该查看java biginteger库。要么尝试找到一个移植的as3版本,要么自己移植(将java代码移植到as3通常不是什么大问题)。