Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran Modern variable precision and integer multipliers

  1. Mar 16, 2016 #1
    I learned Fortran from ancient people who disregard modern standards. As such, my code consists mainly of that older syntax. I am wondering how well this meshes with current Fortran environments, specifically regarding double precision calculations. This comes up mainly because I have been told that real*8 and similar declarations should be abandoned in favor of KIND.

    For example, in the following code section
    Code (Fortran):
    real*8 x,y,z
    will y maintain full double precision, or will a statement like z be required?

    Similarly, if the fractional nature of the initial variable is defined only implicitly,
    Code (Fortran):
    real*8 pi,y,z
    does this change the nature of y or z?

    Or, for that matter, does pi maintain an appropriate value here instead of being declared as pi=4.d0*atan(1.d0)?

  2. jcsd
  3. Mar 16, 2016 #2

    jim mcnamara

    User Avatar

    Staff: Mentor

    If I understand what you are asking: can I use what seems to be an integer value and apply some arithmetic operator to it on a double precision variable without losing precision? In general, yes. Double precision on most systems is 15 digits of precision. That means the two operands and the result all have to fall within those bounds, or things may go wonky, precision-wise.

    Promotion: from http://www.cs.uwm.edu/~cs151/Bacon/Lecture/HTML/ch06s09.html FORTRAN class notes.
    Promotion is defined as taking the variable with least precision and boosting it up to the precision of the other variable.
  4. Mar 16, 2016 #3
    Specifically, is real*8 still fully compatible this way with newer version compilers? Also, do I lose anything with my simpler definition of pi?
  5. Mar 21, 2016 #4


    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    You can always run a test. Calculate π using REAL*8 and calculate it using the KIND parameter. Compare the two results.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted