Clicky

Fortran Wiki
Real precision (Rev #5, changes)

Skip the Navigation Links | Home Page | All Pages | Recently Revised | Authors | Feeds | Export |

Showing changes from revision #4 to #5: (追記) Added (追記ここまで) | (削除) Removed (削除ここまで) | (削除) Chan (削除ここまで)(追記) ged (追記ここまで)

In Fortran 90 and later, intrinsic types such as real and integer have a kind attribute which guarantees a specific precision and/or range. real*8 and counterparts should no longer be used (Chin, Worth, and Greenough, 2006, p. 5). double precision is also no longer needed and can be thought of as a kind of real. The following example declares two real variables a and b which are guaranteed to have at least 15 significant digits of precision and an exponent range of at least 307 (Lemmon and Schafer, 2005, p. 20-22):

integer, parameter :: dp = selected_real_kind(15, 307)
real(kind=dp) :: a
real(dp) :: b

One can also guarantee precision up to that of the machine-compiler-specific double precision real by using the kind function to get the kind of 1.d0:

integer, parameter :: dp = kind(1.d0)

Another possibility, suggested by Metcalf, et. al (2004, p. 71), ensures that the double and quad types are actually twice and four times the precision of a single:

integer, parameter :: &
 sp = kind(1.0), &
 dp = selected_real_kind(2*precision(1.0_sp)), &
 qp = selected_real_kind(2*precision(1.0_dp))

Finally, precision of(削除) 16-, (削除ここまで) 32-,(追記) 64-, (追記ここまで) and(削除) 64-bit (削除ここまで)(追記) 128-bit (追記ここまで) reals can usually be obtained with the following constants:

integer, parameter :: sp = selected_real_kind(6, 37)
integer, parameter :: dp = selected_real_kind(15, 307)
integer, parameter :: qp = selected_real_kind(33, 4931)

References

Revision from March 20, 2012 16:34:50 by Anonymous Coward
Forward in time (3 more) | Back in time (4 more) | See current | Hide changes | History | Rollback | View: Source | Linked from: 2009, FAQ

AltStyle によって変換されたページ (->オリジナル) /