Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Double precision

wkramer
Beginner
1,650 Views
When coding in double precision should I write:
a=b**7.6D0

or
a=b**7.6


and with integer exponent:
a=b**7.D0

or
a=b**7.

or
a=b**7


Which is the more efficient approach?

Regards,

Walter Kramer
0 Kudos
3 Replies
Steven_L_Intel1
Employee
1,651 Views
In almost all cases, you should use the 7.6D0 form for double precision constants, as 7.6 is a single precision constant.

However, in exponentiation, if the power is integer-valued (such as 7.0), you are much better off to use an integer constant (7), as this permits use of a more efficient power routine. Sometimes the compiler will detect that 7.0 is integer-valued and do the faster one anyway, but I suggest not relying on this.

Steve
0 Kudos
wkramer
Beginner
1,651 Views
Just for curiosity:
The power function for double precision argument does accept single precision constant as exponent. Does this mean that the exponent is converted to double precision at runtime (with precision problems), or interpreted as double precision at compile time?

Does something like the improved performance for exponentiation with integers also apply to multiplication with integers.
I.e. is 5*a better than 5.D0*a
I know you already implied that this is not the case, but to be on the save side (I promise not to ask about division).

Regards

Walter Kramer
0 Kudos
Steven_L_Intel1
Employee
1,650 Views
I suggest you read section 4.1.1 of the Compaq Fortran Language Reference Manual, "Numeric Expressions". It goes into this subject in great detail.

In most cases, when the operands of a binary operator are of different types or different kinds of a type, the "lower" type or kind is converted to the "upper" one. An exception is exponentiation, where if the power value is an integer, it need not be converted.

The compiler can do optimizations on things such as 5*A and recognizes that 5.0*A is the same thing. 5*A is mixed-mode arithmetic and should be avoided.

Steve
0 Kudos
Reply