fortran90 - Is There a Better Double-Precision Assignment in Fortran 90? -


in fortran 90 (using gfortran on mac os x) if assign value double-precision variable without explicitly tacking on kind, precision doesn't "take." mean is, if run following program:

program sample_dp  implicit none  integer, parameter :: sp = kind(1.0) integer, parameter :: dp = kind(1.0d0)  real(sp) :: = 0. real(dp) :: b = 0., c = 0., d = 0.0_dp, e = 0_dp  ! assign values = 0.12345678901234567890 b = 0.12345678901234567890 c = dble(0.12345678901234567890) d = 0.12345678901234567890_dp  write(*,101) a, b, c, d 101 format(1x, 'single precision: ',  t27, f17.15, / &            1x, 'double precisison: ', t27, f17.15, / &            1x, 'double precision (dble): ', t27, f17.15, / &            1x, 'double precision (_dp): ',  t27, f17.15)  end program 

i result:

single precision:        0.123456791043282 double precision:        0.123456791043282 double precision (dble): 0.123456791043282 double precision (_dp):  0.123456789012346 

the single precision result starts rounding off @ 8th decimal expected, double precision variable assigned explicitly _dp keeps 16 digits of precision. seems odd, expect (i'm relatively new fortran) double precision variable automatically double-precision. there better way assign double precision variables, or have explicitly type them above?

a real isn't marked double precision assumed single precision. because sometime later assign double precision variable, or convert double precision, doesn't mean value 'magically' double precision. doesn't ahead see how value used.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -