简体   繁体   中英

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. I know this can be done via a one liner as detailed on the module's CPAN page :

$ 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:

#!/usr/bin/perl
use bignum;

setPrecision(-50);
print sqrt(20);

I've searched around here, Google, and PerlMonks without any luck so far. Thanks in advance.

Per Anon.'s suggestion:

#!/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM