I thought that the 'mp' in mpfr stood for multi-precision?
Aaah ... but when a double is assigned to an X-bit (where X > 53) precision mpfr object, the first 53 bits are set the same as the double, and the following bits are all 0.
(To get an X-bit representation of (eg) 1.3, you would need to assign the string '1.3', not the double 1.3.)
A small demo:
use strict;
use warnings;
use Math::MPFR qw(:mpfr);
my $prec_53 = Rmpfr_init2(53);
my $prec_4000 = Rmpfr_init2(4000);
my $d = 1.3;
Rmpfr_set_d($prec_53, $d, MPFR_RNDN);
# The 53 bits of $prec_53 are now set to:
# 10100110011001100110011001100110011001100110011001101
Rmpfr_set_d($prec_4000, $d, MPFR_RNDN);
# The first 53 bits are as for $prec_53
# The remaining 3947 bits are 0.
# But we'll run a check:
die "Things aint right"
if $prec_53 != $prec_4000;
print "$prec_53\n";
# prints 1.3
print "$prec_4000\n";
# prints 1.3000000000000000444089209850062616169452667236328125
So if I want to assign (from a string) the value held by that double to a 53-bit precision object I can just assign the string "1.3".
But if I want to assign (from a string) the same value to a 4000-bit object then I need to assign the latter string.
I assume that the latter value is an exact representation of the value of the double because after the 53rd decimal digit, all (1153) following decimal digits are 0.
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.