> would you mind stating the mathematically correct result (say, to six digits after decimal point)?

This should be correct for at least 50 digits after decimal point:

1141973130130727445029596475.97165373568561208619839490929389898529956 +04918087368059784750017004880305063884032742217053556637130

calculated using Math::BigFloat (which operates decimal with configurable precision) and taking advantage of exponentiation laws described here.

(NB: BigFloat's own ->bpow() method is far slower)

use strict; use warnings; use Math::BigFloat; my $exp=6e7; Math::BigFloat->precision(-100); my $x=Math::BigFloat->new('1.000001'); my $val=Math::BigFloat->new('1'); $\="\n"; for my $bit (reverse split //,sprintf '%b',$exp) { # print "$bit ",$x; $val->bmul($x) if $bit; $x->bpow(2); } $val->bmul(10); print "Result : $val"; my $syphilis=Math::BigFloat->new('1141973130130727445029596475.971760' +); print "diff: ", $val - $syphilis;

took about a second on a netbook.

Compilation started at Tue Jan 20 02:19:30 /usr/bin/perl -w /home/lanx/pm/big_expo.pl Result : 1141973130130727445029596475.97165373568561208619839490929389 +89852995604918087368059784750017004880305063884032742217053556637130 diff: -0.0001062643143879138016050907061010147004395081912631940215249 +982995119694936115967257782946443362870 Compilation finished at Tue Jan 20 02:19:31

The results from the C-libs are as you can see only accurate till the third digit after decimal point.

I'm not a big expert on BigFloat, if you see a problem, all feedback welcome. :)

Cheers Rolf

PS: Je suis Charlie!

update

you can easily increase the accuracy to 1000 digits after decimal point by setting precision to -1050, only takes a second.


In reply to Re^3: Decimal Floating Point (DFP) and does Perl needs DFP? (50 digits precision) by LanX
in thread Decimal Floating Point (DFP) and does Perl needs DFP? by flexvault

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.