monirg
Well-known Member
- Joined
- Jan 11, 2005
- Messages
- 629
Hello;
The following two sample codes produce two different results !!
Variables: Result1, Result2, SUM, A,B,C are DOUBLE data types
Values of A,B,C vary from very small to very large, in no specific order
For a typical set of analytical data, Result1 = 0.9986, while Result2 = 4.2432, a considerable difference.
The different results are most likely associated with accumilated round-off errors known to be associated with floating-point arithmetic precission.
I would very much appreciate your suggestion(s) on how to minimize this serious round-off error.
Can one use a higher precission than DOUBLE ... either in VBA or FORTRAN ??
Thank you kindly.
The following two sample codes produce two different results !!
Code:
SUB TEST1()
' ... my code...
SUM = 0.0
FOR I = 1 TO 20000
SUM = SUM + A(I)*B(I)/C(I)
NEXT
RESULT1 = SUM
' ...my code...
END SUB
Code:
SUB TEST2()
' ... my code...
SUM = 0.0
FOR I = 1 TO 20000
SUM = SUM + A(I)*B(I)/C(I) /1000.
NEXT
RESULT2 = SUM*1000.
' ...my code
END SUB
Values of A,B,C vary from very small to very large, in no specific order
For a typical set of analytical data, Result1 = 0.9986, while Result2 = 4.2432, a considerable difference.
The different results are most likely associated with accumilated round-off errors known to be associated with floating-point arithmetic precission.
I would very much appreciate your suggestion(s) on how to minimize this serious round-off error.
Can one use a higher precission than DOUBLE ... either in VBA or FORTRAN ??
Thank you kindly.