in reply to RFC: Large Floating Point Numbers - Rounding Errors

I'm thinking that it might make sense to use Math::BigRat for the calculations and only convert to "float" for display purposes (do your own output routines). I've always found floating point to be treacherous, and have gotten burned more than once by unexpected behavior and rounding errors (and, at first, naive comparisons with zero).

I haven't done a comparison of how fast BigRat works compared to BigFloat, so it may not be worth the effort after all.

Replies are listed 'Best First'.
Re^2: RFC: Large Floating Point Numbers - Rounding Errors
by syphilis (Archbishop) on Sep 19, 2011 at 04:05 UTC
    I haven't done a comparison of how fast BigRat works compared to BigFloat, so it may not be worth the effort after all.

    If speed is ever an issue, then the gmp library provides "bigrat" (as well as both "bigfloat" and "bigint") types.
    The "bigrat" arithmetic is accessible from perl via Math::GMPq

    Cheers,
    Rob
      Ah, so little time. If I didn't have to compile this first, I'd have already posted timing differentials.