我有一个用perl编写的简单脚本,当我尝试运行时,我不断收到此特定错误。该脚本用于生成一些数字,用于检查整数到浮点。这是我得到的特殊错误。
Can't use an undefined value as an ARRAY reference at /tools/oss/packages/i86pc-5.10/perl/5.8.8-32/lib/5.8.8/Math/BigInt/Calc.pm line 1180
从错误消息中我无法弄清楚我的代码出错的地方。顺便说一下,我需要使用64位数字。我该如何调试此问题?
以下是代码示例
use bignum;
use warnings;
use strict;
open(VCVT, ">CvtIntToFp") or die "couldn't open file to write:$!";
my $number;
my $sgn;
# left with 31 bits excluding the sign
# 23 bits of significand needed, all the result
# will be exact except where leading bit ignoring singn is >23
# take its 2's complement to get the negative number and put it
# into the register
# 32 bit number 1 bit sign 31 left any number with leading 1 @position >23 (counting from 0) will be inexact when in floating point
# 30-24 bit positons can have a leading ones at at any position and result is an inexact
my $twoPwr32 = 0x100000000; #2**32
my @num=();
for(my $i=0; $i<100; $i++)
{
$sgn = (rand()%2);
my $tempLead = (rand()%7); # there are 7 bits from 24 to 30
$number=$tempLead << 24;
if($sgn)
{$number = ($twoPwr32- $number +1) & 0xffffffff;
}
$number = sprintf("%x", $number);
push(@num, $number);
}
my $item=0;
foreach $item (@num)
{
print "$item\n";
print VCVT "$item\n";
}
答案 0 :(得分:0)
尝试使用use diagnostics
获取更好的错误消息并阅读perldoc bignum。给出了错误和解释,使用bignum在内部将数字转换为bignum并返回引用。由于我有perl 5.14文档,我有perl 5.20文档的链接,我认为该bug仍然存在。请参阅http://perldoc.perl.org/bignum.html
更新:
Hexadecimal number > 0xffffffff non-portable at throw_stack.pl line 19 (#1)
(W portable) The hexadecimal number you specified is larger than 2**32-1
(4294967295) and therefore non-portable between systems. See
perlport for more on portability concerns.
另请参阅this问题,了解Perl中64位算法的用法。