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

A foolproof way to calculate DO LOOP iterations.

WSinc
New Contributor I
3,411 Views

An afterthought ;

Why not use REAL(16) arithmetic to calculate that?

We are always guaranteed to get the correct answer for ANY combination of inputs,

and the most extreme range (-huge to +huge)

You get  a REAL(16) result, which you would round off to get the final number.

NO_STEPS = (real(STOP,16) - real(start,16)+real(step,16))/real(step,16)

Since the compiler supports REAL(16) arithmetic, this should not cause any problems.

Anyway, I wanted to see what the compiler guys think about this, since it completely

avoids the integer overflow curse.

0 Kudos
26 Replies
WSinc
New Contributor I
563 Views

In Quote #13 I gave a method which DOES NOT USE higher order arithmetic.

It does, however, have an extra divide, and a couple of extra adds.

Basically, it splits the problem into two parts.

You would not need to use it if START and STOP have the same sign, however.

0 Kudos
Arjen_Markus
Honored Contributor II
563 Views

I can't help myself - no offense, but when I read:

"Now of course, those limits have to be really large numbers for that to occur, but who is to say that a given application would NEVER run into that situation?"

I immediately thought of an expression we have in Dutch, somewhat freely translated: If the sky falls, we will all wear a blue hat.

I do not know the English equivalent, but I guess, you can tell the meaning ;).

 

0 Kudos
mecej4
Honored Contributor III
563 Views

arjenmarkus wrote:
"If the sky falls, we will all wear a blue hat."

That is so apt! My favorite, very useful when helping someone debug their code, is "De aap komt uit de mouw!", which is even less translatable.

0 Kudos
Arjen_Markus
Honored Contributor II
563 Views

You may like this one too: "Let op het springen van de lintwurm!"

Literally: "Watch the jumping of the tapeworm", used when you are about to confirm something you anticipated to happen. Don't ask me where it comes from :).
 

0 Kudos
WSinc
New Contributor I
563 Views

Hey, I wear a BROWN hat -

 

You never know what could be raining down upon you. . . .

0 Kudos
WSinc
New Contributor I
563 Views

Did I "get in dutch" for that?

 

We ARE SPEAKING Dutch, aren't we?

 

0 Kudos
Reply