in reply to Re^3: Decimal Arithmetic
in thread Decimal Arithmetic

I don't remember the last time I owed π dollars to someone. Remember, you are starting with finite amounts (fractions of cents), not numbers like π.

There not always a potential for round-off to occur, when the system has bounds. When something is 1/3rd off, the discount will be rounded/ceiled/floored. Infinite precision is not needed.

Replies are listed 'Best First'.
Re^5: Decimal Arithmetic
by liverpole (Monsignor) on Feb 06, 2007 at 16:06 UTC
        "Infinite precision is not needed"

    Yes, that's the point I was making.

        "I don't remember the last time I owed π dollars to someone"

    Well, you did say "you can store any number"  :-)

    But even if we do limit the calculations to strictly financial ones, it's very easy to demonstrate a case where you'll get round-off.

    Assume you have invested $1000, and your average annual interest rate is exactly 4%.  According to the The Rule of 72, you can expect your money to double in approximately (72 / 4) = 18 years.

    The problem is, this isn't exact.  The exact period after which your money will double is given by the formula ln 2 / ln 1.04, which is approximately 17.67298769 years.  But my point is, no module is going to give you 100% accuracy for that, because ln 2 and ln 1.04, as well as their quotient, are all transcendental numbers, which means you can't represent them 100% accurately.  Which is all I was trying to get across.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

      Well, you did say "you can store any number" :-)

      Point made. I wasn't precise enough.

      and your average annual interest rate is exactly 4%

      That's the thing, it isn't. The interest will be rounded/ceiled/floored. If you want to calculate it accurately, you need a loop. Furthermore, logarithms is not one of the operations I allowed.