Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^9: Why am I losing accuracy?

by roboticus (Chancellor)
on Jan 12, 2020 at 15:56 UTC ( #11111341=note: print w/replies, xml ) Need Help??


in reply to Re^8: Why am I losing accuracy?
in thread Why am I losing accuracy?

haukex:

Yes, it's asking for reduced precision, but I think that bliako is surprised as I am by the sign of the precision argument. The various number formatting tools I've used have given me the expectation that a positive number indicates the number of digits I want to retain to the right of the decimal place, rather than to the left.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^10: Why am I losing accuracy?
by bliako (Parson) on Jan 12, 2020 at 19:47 UTC

    yes, for me the sign of precision is confusing.

    I am also confused as to what precision and what accuracy mean for bignum and why in incrementing an integer (for example, in the loop) precision discards useful digits to replace them with zeros.

    What perl -Mbignum=p,1 -wle '$i = 1; print $i + 123456788,"\n"' does is round((1+123456788)/10) * 10 =  123456790 Why? Just add the numbers please? At least when the "width" of the largest can accommodate the result too. Instead it discards the LS"D" of the result and replaces it with a zero. The more increasing p the more LS"D"s are thrown away but the width of the result is not getting any smaller, so what's the practical reason?

    From roboticus home node I clicked on dominus home node and then on to his blog which happens to talk about bc just a few days ago. And points out that bc adding two numbers increases the number of digits to accommodate the result. Well bignum does that and then replaces "p" LS"D"s with zeros. thanks.

    edit: LS"D" = least significant digit

      I am also confused as to what precision and what accuracy mean for bignum and why in incrementing an integer (for example, in the loop) precision discards useful digits to replace them with zeros

      When you specify p => 1 you're actually saying that you want the values rounded to the nearest multiple of 10.
      To have the values rounded to the nearest multiple of 100, specify p => 2. For rounding to the nearest multiple of 1000, specify p => 3, and so on.
      So, with p => 1, 10 + 1 == 10 and 10 + 6 == 20, because 11 rounded to the nearest multiple of 10, is 10 and 16 rounded to the nearest multiple of 10 is 20.

      OTOH, a => 1 indicates that you want the value rounded to a value that comprises a single digit multiplied by a power of 10, a => 2 indicates that the value should be rounded to a double-digit value multiplied by a power of 10.
      It seems to me that "accuracy" would be better named "precision". (The trailing zeroes are just the exponent - it's the number of leading digits ahead of the exponent that determines the precision of the value.)
      Not sure what "precision" should be renamed to .... "accuracy" ?

      I think negative values for "p" just tell you how many decimal places you want after the decimal point.

      With practice and experience it's probably useful - if you keep your wits about you. (I have not tested this - the reliance on "wits" deters me.)

      Cheers,
      Rob

        Thanks for explaining this

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2020-06-05 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?