in reply to Determining when Math::BigFloat is necessary?

That can't be answered with the information given. It's not the representation of your input numbers that matters, but the arithmetic that drops off significance that give incorrect results. For example, if you compute c*(a-b) and all three numbers are well within the legal range and precision of floating point, you can still get the wrong answer if a and b are nearly equal and c is of a magnitude that's not nearly the same as that difference.

Perhaps you can do some testing and see which datasets give the same answer the fast way and the slow way, then see if you can derive some emperical ideas from that.

The formal approach would be to compute tolerances along side the main calculation. This would cut the speed in half, but that's still nothing like the factor of 40 you have now. Then you can detect when the significance requires upgrading to bigfloat. In fact... you could write a lazybigfloat module that does this for you automatically. Then you can do some analysis and only employ it for expressions that might need it, like in the example above.

—John

  • Comment on Re: Determining when Math::BigFloat is necessary?