Perl high precision calculation

If you want to make a high precision calculation with Perl you could use the bignum module.As little example:

#!/usr/bin/perl
print 4/3,"\n";
use bignum;
print 4/3,"\n";

And we could see the second result has a better accuracy than the default:

1.33333333333333 
1.333333333333333333333333333333333333333

 

But you could improve this by setting the precision in Significant figures, like in this example we want 60.

#!/usr/bin/perl
print sqrt(20),"\n";
use bignum ( p => -60 );;
print sqrt(20),"\n";

As result we get:

4.47213595499958
4.472135954999579392818347337462552470881236719223051448541794

 

3 thoughts on “Perl high precision calculation”

  1. I was more than happy to discover this web site. I wanted to thank
    you for ones time for this wonderful read!!
    I definitely enjoyed every bit of it and i also have you saved
    to fav to see new stuff on your blog.

  2. Every weekend i used to visit this web page, for the reason that i want
    enjoyment, as this this web site conations truly fastidious funny information too.

  3. It’s actually a nice and helpful piece of information. I am glad that
    you shared this useful info with us. Please stay us informed like this.
    Thanks for sharing.

Leave a Reply

Your email address will not be published.

5 × five =