In your example above 1 / 526, you posted a result of: 1.9011406844106463 7711435114653113487293012440204620361328125e-3
Yes, in this instance (as also in earlier posts) I'm using mpfr to express the exact base 10 equivalent of the value held by the double.
(And that value held by the double is 1/526, calculated to 53 bits of precision.)
But the actual result (to 100 digits of precision is : 1.9011406844106463 87832699619771863117870722433460076045627376425855513307984790874524714828897338403e-3Yes, this is a much better approximation of 1/526 than that provided by the double, and a different figure is therefore expected.
We can, of course, use mpfr to give us an approximation of 1/526 to whatever precision we want (so long as the precision does not exceed MAX_PREC):
use strict;
use warnings;
use Math::MPFR qw(:mpfr);
my $x = Rmpfr_init2(328);
Rmpfr_set_d($x, 1.0, MPFR_RNDN);
$x /= 526;
print $x;
# Outputs:
# 1.901140684410646387832699619771863117870722433460076045627376425855
+513307984790874524714828897338403e-3
# which is the same as the figure you've provided
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.