Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DEXP or EXP for exponential function in fortran?

Tags:

fortran

I have two very short questions:

1 - I just read that DEXP() is the archaic form of EXP(). Does it mean that it should not be used anymore? I always thought that DEXP() was the double precision equivalent to EXP().

2 - What is the range of the exponential function? Is it compiler dependent?

Thanks in advance for your help!

Best, Remek

like image 979
remek Avatar asked Jan 12 '10 09:01

remek


People also ask

How do you declare an exponential function in Fortran?

EXP(X) computes the base e exponential of X . The type shall be REAL(*) or COMPLEX(*) . Return value: The return value has same type and kind as X .

What is a subroutine in Fortran?

A Fortran subroutine is a block of code that performs some operation on the input variables, and as a result of calling the subroutine, the input variables are modified. An expression containing a function call: ! func1 is a function defined elsewhere. !


2 Answers

Question number 1:

As mentioned before, it is always better to use the generic functions, such as EXP(), in preference to the outdated type specific equivalents, such as DEXP().

In the old (really old) versions of FORTRAN (before FORTRAN 77), a different function was required for each data type. So if you wanted the exponential function would need: EXP() for single precision numbers, DEXP() for double precision numbers, or CEXP() for complex numbers. FORTAN now has function overloading, so a single function will work for any standard type.

Question number 2.

In principle the possible range of the exponent can be processor and compiler dependent. However, as mentioned before, most modern processors and compilers will use the IEEE standard.

If needed, it is possible to specify the required range of a variable when declaring it. The function to use is SELECTED_REAL_KIND([P,R]).

For example, suppose you to make sure that x is of a type with decimal precision of at least 10 digits and a decimal exponent range of at least 100.

INTEGER, PARAMETER :: mytype = SELECTED_REAL_KIND(10, 100)
REAL(KIND=mytype) :: x

For more information: SELECTED_REAL_KIND

In practice, if you are writing a program that requires a given accuracy, and which may be run on exotic or old systems, it is a very good idea to define your types in this way. Some common definitions are shown here: Real Precision

like image 137
amicitas Avatar answered Sep 21 '22 14:09

amicitas


"exp" is a generic function, that returns the same type as its argument -- precision of real or complex. It should be used in preference to the older form "dexp" because with "exp" the compiler will automatically return the correct type. The generic names were added in Fortran 77.

like image 28
M. S. B. Avatar answered Sep 22 '22 14:09

M. S. B.