would you mind stating the mathematically correct result (say, to six digits after decimal point)?According to Math::Decimal128:
C:\>perl -MMath::Decimal128=":all" -le "$n1=Math::Decimal128->new('10'
+, 0);$n2=Math::Decimal128->new('1000001', -6);for(1..60000000){$n1 *=
+ $n2}print $n1;"
114197313013072744502959647597176e-5
Or, to 6 decimal places:
1141973130130727445029596475.971760 which is the same as
flexvault got.
With 80-bit long doubles, the calculation came out as:
C:\>perl -MMath::LongDouble=":all" -le "$n1=Math::LongDouble->new('10'
+);$n2=Math::LongDouble->new('1.000001');for(1..60000000){$n1 *= $n2}p
+rint $n1;"
1.14197313013239314e+027
Or, printing to 28 decimal digits (which implies a level of precision that we don't have):
C:\>perl -MMath::LongDouble=":all" -le "$n1=Math::LongDouble->new('10'
+);$n2=Math::LongDouble->new('1.000001');for(1..60000000){$n1 *= $n2}p
+rint LDtoSTRP($n1, 28);"
1.141973130132393144424071168e+027
This figure is equivalent to the first one you quoted.
With __float128:
C:\>perl -MMath::Float128=":all" -le "$n1=Math::Float128->new('10');$n
+2=Math::Float128->new('1.000001');for(1..60000000){$n1 *= $n2}print $
+n1;"
1.14197313013072744502959647306684e+27
This differs from your second figure - and I don't think there's any valid reason that they should differ.
I'm inclined to think that mine is correct (surprise :-) because it matches up pretty well with the _Decimal128 calculation (where the respective precisions are reasonably close to each other).
Might you have assigned a long double or double value that got cast to a __float128, instead of assigning an actual __float128 value ?
As
LanX points out, rounding is involved. The above one-liner programs all employ rounding to nearest with ties to even - the different results of course arising from the different precisions involved.
Cheers,
Rob
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.