## accuracy in gfortran

## accuracy in gfortran

(OP)

if all the variables at first are integer isn't integer multiplication supposed to be exact ?

Even though i am getting very large numbers(as long as not overflow): anyway at the end i will have to divide a floating point number by the integer(s). There are several steps and at first i just divided the floating point number by the integers at each step and was getting more off than what i should have thought reasonable so then i changed strategy and multiplied all the integers and at the end divided by the product.Assuming integer multiplication is exact would not the 2nd way of doing all the integer multiplications first and then divide the floating point number by the final(rather large but not enough to overflow or underflow) result be more accurate than doing several divisions of the floating point number by the integers at each step.

The difference in these two ways was a lot more than i would have thought - like around 15% or so.

The floating point was single precision and the number of integer products was less than 20 i think. The reason i would have thought the 2nd way is better is because only have one floating point division by an integer(all be it much larger) instead of several.

Even though i am getting very large numbers(as long as not overflow): anyway at the end i will have to divide a floating point number by the integer(s). There are several steps and at first i just divided the floating point number by the integers at each step and was getting more off than what i should have thought reasonable so then i changed strategy and multiplied all the integers and at the end divided by the product.Assuming integer multiplication is exact would not the 2nd way of doing all the integer multiplications first and then divide the floating point number by the final(rather large but not enough to overflow or underflow) result be more accurate than doing several divisions of the floating point number by the integers at each step.

The difference in these two ways was a lot more than i would have thought - like around 15% or so.

The floating point was single precision and the number of integer products was less than 20 i think. The reason i would have thought the 2nd way is better is because only have one floating point division by an integer(all be it much larger) instead of several.

## RE: accuracy in gfortran

Take some simple addition

(28 / 10) + (29 /10)

= 2 + 2

= 4

but

(28 + 29) / 10

= 57 / 10

= 5

With multiplication

(24 / 10) * (3 / 2)

= 2 * 1

= 2

But

(24 * 3)/(10 * 2)

= 72 / 20

= 3

## RE: accuracy in gfortran

## RE: accuracy in gfortran

Dividing may produce a different result to multiplying by the reciprocal. Mathematically, it is the same. Work out on a calculator or by hand what the answer should be and check the two methods.

## RE: accuracy in gfortran