Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Fun Question: Square Root of 5 to 10000 digits

by Zaxo (Archbishop)
on Feb 27, 2007 at 18:42 UTC ( [id://602369]=note: print w/replies, xml ) Need Help??


in reply to Fun Question: Square Root of 5 to 10000 digits

My entry was,

perl -MMath::Pari -e'Math::Pari::setprecision(10000); my $foo = PARI(5 +); my $bar = $foo->sqrt; print $bar,$/,$bar**2,$/'
which is cheating I suppose. But it's really fast.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Fun Question: Square Root of 5 to 10000 digits
by syphilis (Archbishop) on Feb 27, 2007 at 23:26 UTC
    You can do essentially the same with Math::MPFR:
    perl -MMath::MPFR=:mpfr -e "Rmpfr_set_default_prec(10000); $foo = Math +::MPFR->new(5); $bar = $foo ** 0.5; print $bar, $/, $bar ** 2, $/"

    With Math::MPFR, setting a default precision of 10000, means you have 10000 bits of precision, not 10000 decimal digits of precision. To be guaranteed 10000 decimal digits of precision I think you need to ask for 33220 bits - ie ceil(10000 / log(2)). I haven't checked whether Math::PARI sets its precision in bits or decimal digits.

    Cheers,
    Rob
      With Math::MPFR, setting a default precision of 10000, means you have 10000 bits of precision, not 10000 decimal digits of precision.

      Doh! You are right, I was wondering last night why I was getting a 1/3 factor of digits. 10000 gave me ~ 3000 decimal places, while 100000 precision gave me ~30000 decimal places. I thought it might be the print accuracy needed to do the inverse, but I was wrong. Thanks for clearly that up. :-)


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://602369]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-24 00:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found