Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are the specific double precision functions in Fortran useful?

I have noticed using gfortran that the tan function returns real values of the same kind as its argument; e.g. one can pass real(kind=4), real(kind=8) or real(kind=16) to it and get results in real(kind=4), real(kind=8) or real(kind=16) respectively.

Double precision functions like dtan, on the other hand, are not as flexible. If the default double kind is 8[1] they only accept and return real(kind=8) and if the default kind is 16[2], they only accept and return real(kind=16) .

Are these defined behaviors and if so, what is the use case for the double precision functions or are they obsolete?


[1] if compiled with -fdefault-double-8 or without -fdefault-real-8

[2] if compiled with -fdefault-real-8 and without -fdefault-double-8

like image 561
Eliad Avatar asked May 29 '18 15:05

Eliad


People also ask

What is double precision in Fortran?

A double-precision exponent consists of the letter D , followed by an optional plus or minus sign, followed by an integer. A double-precision exponent denotes a power of 10. The value of a double-precision constant is the product of that power of 10 and the constant that precedes the D .

How many digits is double precision in Fortran?

Double precision provides greater range (approximately 10**(-308) to 10**308) and precision (about 15 decimal digits) than single precision (approximate range 10**(-38) to 10**38, with about 7 decimal digits of precision).

How do you define precision in Fortran?

The decimal precision is the number of significant digits, and the decimal exponent range specifies the smallest and largest representable number. The range is thus from 10-r to 10+r.


1 Answers

The specific precision function such as dtan are effectively unnecessary since FORTRAN 77. That's a long time ago. Some still use them, but they should be used as little as possible (I'd say never). FORTRAN 77 brought generic intrinsic functions and that is what should normally be used. You just have to be sure to check the kind of the argument. With the d... functions the compiler will complain if the argument is not double precision.

But they are completely valid Fortran 2008. There was some change regarding their obsoleteness in Fortran 2018, but I am not sure what exactly. In Fortran 2018, however, they are declared obsolescent (see also Steve's comment). I think it will also not be possible to pass them as procedure arguments to other procedures.

As a final note, real(kind=4), real(kind=8) or real(kind=16) is NOT a portable notation. Kind numbers 4, 8 and 16 do not have to exist at all or can mean something different in various compilers. The kind number is NOT the number of bytes. Indeed certain compilers use kind numbers 1, 2 and 3. See Fortran 90 kind parameter

like image 179
Vladimir F Героям слава Avatar answered Sep 28 '22 01:09

Vladimir F Героям слава