Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^11: subtraction issue

by syphilis (Chancellor)
on Jan 29, 2017 at 08:47 UTC ( #1180550=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1180550]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-03-20 19:52 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (259 votes). Check out past polls.