I have a limited background in scientific computing. I'm writing a program for EM wave scattering, trying to replicate work done in python. I'm having problems with round-off (I believe) and am hoping someone can explain what is going on. So I have
integer, parameter :: wp = selected_real_kind( 15 )
real (wp) :: epsilon_1,epsilon_2, f
epsilon_1=1.0
epsilon_2=2.05
f=100.0*1.0*10**9
write(*,*) "epsilon_1=",epsilon_1,"epsilon_2=",epsilon_2,"f=",f
So, I want high precision, I'll be making several computations. When I run the code, it writes
epsilon_1= 1.0000000000000000 epsilon_2= 2.0499999523162842 f= 99999997952.000000
Why is epsilon_2 and f rounded the way they are rather than being stored as 2.0500000000000000 etc? I have several variables I'm working with, and they're all giving similar results, I'm worried that there will be lots of error due to this. I tried changing to epsilon_2=2.05_wp and got 2.0499999999999998 but this is still not what I'd expect.
Can someone please tell me what's happening here? Your help is appreciated.
Additionally, is there much benefit to working in fortran rather than python?
integer, parameter :: wp = selected_real_kind( 15 )
real (wp) :: epsilon_1,epsilon_2, f
epsilon_1=1.0
epsilon_2=2.05
f=100.0*1.0*10**9
write(*,*) "epsilon_1=",epsilon_1,"epsilon_2=",epsilon_2,"f=",f
So, I want high precision, I'll be making several computations. When I run the code, it writes
epsilon_1= 1.0000000000000000 epsilon_2= 2.0499999523162842 f= 99999997952.000000
Why is epsilon_2 and f rounded the way they are rather than being stored as 2.0500000000000000 etc? I have several variables I'm working with, and they're all giving similar results, I'm worried that there will be lots of error due to this. I tried changing to epsilon_2=2.05_wp and got 2.0499999999999998 but this is still not what I'd expect.
Can someone please tell me what's happening here? Your help is appreciated.
Additionally, is there much benefit to working in fortran rather than python?