http://www.perlmonks.org?node_id=1180550


in reply to Re^10: subtraction issue
in thread subtraction issue

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-3

Yes, 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