in reply to Calculation discrepancy between Perl versions

Following on from ig's comment a couple of alarm bell stimulating items in relation to your code, data and results should be mentioned:

  1. sums and differences of floats can easily lead to large errors if not managed correctly, especially in the context of exponentiation
  2. output values with more significant digits than seem reasonable given the input data is a cause for concern

This sort of code can be very tricky to get right with careful attention needing to be paid to expected ranges of values at each step and consideration given to changing calculation order to minimise errors propagating through the calculation chain. Using higher precision numerical representation is a quick way around what can otherwise often be a difficult problem.

True laziness is hard work
  • Comment on Re: Calculation discrepancy between Perl versions