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
Post a Comment