[英]How can I set the level of precision for Perl's bignum?
I'm trying to use the bignum module in Perl and want to set the precision. 我正在尝试在Perl中使用bignum模块并想要设置精度。 I know this can be done via a one liner as detailed on the module's CPAN page :
我知道这可以通过单个衬管完成,详见模块的CPAN页面 :
$ perl -Mbignum=p,-50 -le 'print sqrt(20)'
...which will print out the square root of 20 to 50 digits of precision, but what I'm wondering is if there's anyway to set the precision within a script, ie something like: ...它将打印出20到50位精度的平方根,但我想知道的是,无论如何都要在脚本中设置精度,例如:
#!/usr/bin/perl
use bignum;
setPrecision(-50);
print sqrt(20);
I've searched around here, Google, and PerlMonks without any luck so far. 到目前为止,我在这里,Google和PerlMonks都没有运气。 Thanks in advance.
提前致谢。
Per Anon.'s suggestion: Per Anon。的建议:
#!/usr/bin/perl
use strict;
use warnings;
use bignum ( p => -50 );
print sqrt(20);
You might like to look at the docs for Math::BigFloat and Math::BigInt which bignum makes use of. 您可能希望查看bignum使用的Math :: BigFloat和Math :: BigInt的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.