fortran - Improve precision on variables defined by integer quotient -


say have following program:

program derp     implicit none     integer, parameter :: ikind = selected_real_kind(18)     real (kind = ikind) :: = 2.0 / 3.0     print*, end program derp 

the program derp outputs 0.6666666865348815917, not 18 digits of precision. however, if define a=2.0 , b=3.0 using same method , then define c=a/b output of 0.666666666666666666685, good. how define variable quotient of integers , have store digits of precision want selected_real_kind?

try: real (kind = ikind) :: = 2.0_ikind / 3.0_ikind

the reason while lhs high precision, rhs in code example, 2.0 / 3.0, not. fortran calculation in single precision , assigns result lhs. rhs side isn't calculated in higher precision because lhs high precision. digits_kind way of specifying type of constant digits.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -