Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: subtraction issue

by AnomalousMonk (Archbishop)
on Jan 24, 2017 at 22:59 UTC ( [id://1180252]=note: print w/replies, xml ) Need Help??


in reply to Re: subtraction issue
in thread subtraction issue

Anonymous: Previous to Perl version 5.22.0, you can use a format like '%0.20f'.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: subtraction issue
by syphilis (Archbishop) on Jan 27, 2017 at 09:00 UTC
    Previous to Perl version 5.22.0, you can use a format like '%0.20f'

    Yes, I think that's a good enough replacement for most purposes - and a useful addition to my post.

    However, it's not guaranteed to give you the exact base 10 value stored in the double - whereas %a will give you the exact (base 16) value.

    Cheers,
    Rob

      Feel free to ignore this post. I just couldn't help myself (I needed the coffee-break distraction, apparently)

        it takes n fixed-point decimal digits to exactly represent an n-bit fixed-point fractional binary number

        Thank you for correcting me ... but shouldn't that be "n+1 fixed-point decimal digits" ?
        use strict; use warnings; use Math::MPFR qw(:mpfr); Rmpfr_set_default_prec(1000); my $d = 1 / 11; my $x = Math::MPFR->new($d); print "$x\n", length($x), "\n"; # (print() removes trailing zeros.) # Outputs: 9.09090909090909116141432377844466827809810638427734375e-2 58
        Take out the "." and the "e-2" and we're left with 54 decimal digits.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1180252]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-24 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found