0

I'm relatively new using the Fortran language and I'm dealing with a pre-written program that I have to make some changes, and I have all 8 bytes variables declared as REAL(8) on the program's statement area. However, when attributing numerical values to the variables and/or arrays, the original program's author always uses something like:

...

REAL(8) A

A = 1.d0

...

Is that strict necessary given that 'A' is declared not as DOUBLE PRECISION, but literally as REAL(8), even thought -- I think -- both have the same KIND?

Furthermore, I have read somewhere that the use of REAL(8) should be abandoned? Is that so? Why?

As far as I know (and I certainly can be wrong), the number of bytes used in a DOUBLE PRECISION variable is dependent of the compiler, making it dangerous (I assume) or at least undesirable its use in place of REAL(8), if my intention is to declare an 8 bytes variable.

(I am working with Fortran 90/95)

I would gratefully receive comments to clarify this issue! Thanks a lot!

  • 2
    Although your points are closely related, you are perhaps asking too much in one question. As an introduction to kind parameters, though, please see [this other question](https://stackoverflow.com/q/838310/3157076). Once you have read that, please trim any related aspects that you newly understand from here so that this question becomes more focused. – francescalus Apr 28 '21 at 21:48
  • 4
    Firstly, you should not use `real(8)` with a magic constant 8 at all. `.d0` declares the constant to be `double precision`, not `real(8)`. `real(8)` does not always mean 8-bytes and does not have to exist at all. Integers like `1` and powers of 2 like `0.25` are exactly representable in binary. I do not use real kinds for integer constants. I just use `A = 1`. – Vladimir F Героям слава Apr 28 '21 at 21:50
  • You can also read [here](https://stackoverflow.com/q/49183219/3157076) about aspects of assignment and type conversion. – francescalus Apr 28 '21 at 21:51
  • @VladimirF , thank you for your comment. However, "A = 1.d0" was just an example indicating how the program's original author writes and attribute values to real variables. Why should I not use '8' in real(8) at all? How would you then declare a real variable with 8-bytes and asign a value to it ? – Augusto Bopsin Borges Apr 28 '21 at 22:06
  • Thanks, @francescalus .. I'll read the posts – Augusto Bopsin Borges Apr 28 '21 at 22:09
  • 2
    Real( 8 ) is not guaranteed to be supported by compilers. Thus using Real( 8 ) means that your program might fail to compile. We have had questions here where that is the case. Further Real( 8 ), if supported, has no well defined precision or range for number being represented. There are ways within standard Fortran to avoid both these problems. Thus Real( 8 ) is not good practice. See the question linked by Francescalus – Ian Bush Apr 28 '21 at 22:17
  • You might also look at https://stackoverflow.com/questions/5263157/getting-double-precision-in-fortran-90-using-intel-11-1-compiler?rq=1 Even though the question mentions the Intel compiler it is not specific to that – Ian Bush Apr 29 '21 at 10:31
  • I like the ISO_C_BINDING and then the REAL (KIND=C_DOUBLE) ::A. Later the A=1.0_C_DOUBLE then shows the intent. – Holmz Apr 30 '21 at 00:41

0 Answers0