|
|||
To see the
differences between C and F90 floating point, consider a sample
program, and its C equivalent. These programs simply assign 0.7 to
a number and than print it on screen. F90:
program foo C: #include <stdio.h>
void main(void)
C output :
0.70000000000 Upon examination of the assembly machine code produced by F90, it appears to ignore that a is declared as an 8 byte real, and instead stores only the first 4 bytes of 0.7 in IEEE format. C assembly:
.dword 0x3fe6666666666666 # double 0.700000
F90 assembly:
.dword
0x3fe6666660000000 # double 0.700000 store 0.7 as 0.7d0, or 3.455e-5 as 3.455d-5. This improves accuracy, sometimes significantly. The example below stores light speed squared in the old and new notation. Notice the improvement in precision:
old
notation : a = 89875517873681764.0
prints as 89875514973487104 The minor discrepancy might not seem significant, and for a few calculations, it probably isn't, but notice what happens when we do many calculations, where the errors can accumulate. The program below simply starts with 0.0, adds 0.01 to the variable a 100 times, and prints out the value of the variable a at each iteration. The output from both C and F90 code is shown for comparison. F90:
program foo C:
#include
<stdio.h> |
|||
|
|||
|
|||
-- Max Smirnoff |
![]() |
|