- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When coding in double precision should I write:
or
and with integer exponent:
or
or
Which is the more efficient approach?
Regards,
Walter Kramer
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
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page