- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi there,
I was wondering what data type should I use when I do a ** operation.
Is that fromcompiler point of view a difference when I calculate real**integer or should I do real**real?
For example 2.5**4 or 2.5**4. ?
Markus
I was wondering what data type should I use when I do a ** operation.
Is that fromcompiler point of view a difference when I calculate real**integer or should I do real**real?
For example 2.5**4 or 2.5**4. ?
Markus
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - onkelhotte
Hi there,
I was wondering what data type should I use when I do a ** operation.
Is that fromcompiler point of view a difference when I calculate real**integer or should I do real**real?
For example 2.5**4 or 2.5**4. ?
Markus
I was wondering what data type should I use when I do a ** operation.
Is that fromcompiler point of view a difference when I calculate real**integer or should I do real**real?
For example 2.5**4 or 2.5**4. ?
Markus
I believe integer exponentiation (where known)is better because of optimization eg (from the help) M=J**2 is optimized to M=J*J
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think it is good practice to write always a=b*b instead of a=b**2 or a=b*b*b instead of a=b**3, if possible, of course. Even if the compiler optimizes the exponentation with integers I prefer to control the optimization.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I agree with Les. Use an integer exponent if it is integer-valued.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - onkelhotte
Is that fromcompiler point of view a difference when I calculate real**integer or should I do real**real?
For example 2.5**4 or 2.5**4. ?
The integer exponent is certain to be at least as efficient and accurate as the real exponent. In this case, the result with the integer exponent would be exact, while that is not guaranteed with the real exponent.
If you want to be certain of a specific order of evaluation, such as ((2.5*2.5)*2.5)*2.5, you must write it out with parentheses, and, with ifort, include the option /assume:protect_parens. This prevents optimization to a potentially faster or slightly more accurate version. I don't know of any good reason to avoid the integer exponentiation.
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