[ACCEPTED]-DEXP or EXP for exponential function in fortran?-fortran
Question number 1:
As mentioned before, it is always better 28 to use the generic functions, such as EXP(), in 27 preference to the outdated type specific 26 equivalents, such as DEXP().
In the old 25 (really old) versions of FORTRAN (before 24 FORTRAN 77), a different function was required 23 for each data type. So if you wanted the 22 exponential function would need: EXP() for 21 single precision numbers, DEXP() for double 20 precision numbers, or CEXP() for complex 19 numbers. FORTAN now has function overloading, so 18 a single function will work for any standard 17 type.
Question number 2.
In principle the possible range of 16 the exponent can be processor and compiler 15 dependent. However, as mentioned before, most 14 modern processors and compilers will use 13 the IEEE standard.
If needed, it is possible 12 to specify the required range of a variable 11 when declaring it. The function to use 10 is
For example, suppose you to make sure 9 that
x is of a type with decimal precision 8 of at least 10 digits and a decimal exponent 7 range of at least 100.
INTEGER, PARAMETER :: mytype = SELECTED_REAL_KIND(10, 100) REAL(KIND=mytype) :: x
For more information: SELECTED_REAL_KIND
In 6 practice, if you are writing a program that 5 requires a given accuracy, and which may 4 be run on exotic or old systems, it is a 3 very good idea to define your types in this 2 way. Some common definitions are shown 1 here: Real Precision
"exp" is a generic function, that returns 6 the same type as its argument -- precision 5 of real or complex. It should be used in 4 preference to the older form "dexp" because 3 with "exp" the compiler will automatically 2 return the correct type. The generic names 1 were added in Fortran 77.
The answer to part 2 of your question is 14 that the range of the exponential function 13 is the set of all positive real numbers. In 12 Fortran terms that means the set of all 11 REAL numbers greater than 0. Yes it is, according 10 to the Fortran standards, compiler dependent, but 9 in practice you won't go far wrong if you 8 take it to be the set of all positive IEEE 7 floating-point numbers, single or double 6 precision as you wish. But to be strict 5 you need to be familiar with the KINDs of 4 real numbers that your compiler supports 3 which will almost certainly include the 2 IEEE f-p numbers, but may include others 1 too.
More Related questions