- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
- Balises:
- Intel® Fortran Compiler
Lien copié
3 Réponses
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable