Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.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
为什么Perl模运算符使用bignum而不是Math::BigInt处理大整数?_Perl_Biginteger_Modulo - Fatal编程技术网

为什么Perl模运算符使用bignum而不是Math::BigInt处理大整数?

为什么Perl模运算符使用bignum而不是Math::BigInt处理大整数?,perl,biginteger,modulo,Perl,Biginteger,Modulo,我在Perl脚本中尝试了以下操作: $b = 19999999999999999 % 10000000000000000; print "$b\n"; 它错误地输出了0 然后我发现说使用bignum: 它正确地输出了99999999999 但是bignum只是将所有整数常量转换为Math::BigInt。因此,我尝试了以下与使用bignum相同的方法: 但这不正确地输出了0。我在Math::BigInt上做错了什么吗?您仍然首先使用本机Perl数字,然后将它们转换为Math::BigInt对象

我在Perl脚本中尝试了以下操作:

$b = 19999999999999999 % 10000000000000000;
print "$b\n";
它错误地输出了0

然后我发现说使用bignum:

它正确地输出了99999999999

但是bignum只是将所有整数常量转换为Math::BigInt。因此,我尝试了以下与使用bignum相同的方法:


但这不正确地输出了0。我在Math::BigInt上做错了什么吗?

您仍然首先使用本机Perl数字,然后将它们转换为Math::BigInt对象。请尝试以下方法:

my $x = Math::BigInt->new('19999999999999999') % Math::BigInt->new('10000000000000000');
引述自:

以标量数字形式给出的输入可能会失去精度。引用您的输入以确保没有数字丢失:

$x = Math::BigInt->new( 56789012345678901234 );   # bad
$x = Math::BigInt->new('56789012345678901234');   # good

另外,不要在sort和类似例程之外使用$b。

您仍然首先使用本机Perl数字,然后将它们转换为Math::BigInt对象。请尝试以下方法:

my $x = Math::BigInt->new('19999999999999999') % Math::BigInt->new('10000000000000000');
引述自:

以标量数字形式给出的输入可能会失去精度。引用您的输入以确保没有数字丢失:

$x = Math::BigInt->new( 56789012345678901234 );   # bad
$x = Math::BigInt->new('56789012345678901234');   # good

另外,不要在排序和类似例程之外使用$b。

在64位和32位Perl 5.26上对我都适用。是的,我刚刚在64位Perl上试用过,效果很好,所以我认为在32位Perl上会出现问题。在64位和32位Perl 5.26上对我都适用。是的,我只是在64位Perl上试用过,效果很好,所以我认为它会在32位Perl上崩溃。