[英]perl: bignum not working with STDIN
#!/usr/bin/perl
use bignum;
$line = <STDIN>;
( $arr[0], $arr[1], $n ) = split( / /, $line );
$i = 2;
sub func {
while ( $i < $n ) {
$t = $arr[ $i - 1 ];
$arr[$i] = $arr[ $i - 1 ] * $arr[ $i - 1 ] + $arr[ $i - 2 ];
$i = $i + 1;
}
return $arr[ $i - 1 ];
}
print func;
when i am setting manual value for $arr[1] then bignum is working fine but when the value is taken from STDIN then it is being printed as integer no BIGINt. 当我为$ arr [1]设置手动值时,bignum正常工作,但是当该值取自STDIN时,它将被打印为整数而不是BIGINt。 can anyone explain why this is happening.
谁能解释为什么会这样。
When you use strings in a numeric context, perl converts them using your C library's atof()
. 在数字上下文中使用字符串时,perl使用C库的
atof()
转换它们。 This is not changed by bignum
. bignum
不会更改。 If you'd like your strings converted in a different manner, I'd recommend Math::BigFloat->new
or Math::BigInt->new
. 如果您希望以其他方式转换字符串,则建议使用
Math::BigFloat->new
或Math::BigInt->new
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.