in reply to Re^5: Getting different results with $var++ and $var += 1
in thread Getting different results with $var++ and $var += 1

Shouldn't bigrat do most of the "do math without losing precision" thing?

  • Comment on Re^6: Getting different results with $var++ and $var += 1

Replies are listed 'Best First'.
Re^7: Getting different results with $var++ and $var += 1
by gone2015 (Deacon) on Dec 04, 2008 at 10:50 UTC

    Yes you could do everything as a rational.

    Thing about fractions is that you end up doing quite a lot of work finding hcf of the denominators.

    An indefinite precision decimal fixed point arithmetic would, essentially, be an "bigrat", but all denominators would be powers of 10. That would mean, of course, that 1/3 would have a "representation" error -- but we are at least used to that.

    The advantage of a fixed (but large) precision decimal floating point would be that functions like exp() and log() etc. (which do appear in financial calculations) would be more straightforward... as would any arithmetic involving widely different scales of numbers. You have to understand the effect of rounding...

    Now that I've looked, I see that there is Math::BigFloat which is decimal (though that small fact doesn't exactly leap out at you). I see it is implemented using BigInt for the significands, and allows quite fine control over the precision. So I'll go away now.