Re: storing an integer in a double precision



On May 6, 8:54 am, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:
Ron Shepard <ron-shep...@xxxxxxxxxxxxxxxxxx> wrote:
In article <4dc3fc3e$0$99954$c30e3...@xxxxxxxxxxxxxxxxxxxxxx>,
 "robin" <robi...@xxxxxxxxxxxxxxxxxx> wrote:

program test
   implicit none
   integer :: i
   do i = huge(i)-5, huge(i)
      print *, i
   end do
end program test

I can understand why the first code might have problems, the value
of the trip count for the do loop cannot be computed in an integer
register.  But I don't see why the above do loop does not terminate.
The trip count should be 6.  What quirk of hardware would make it
anything other than 6?

The compiler might do an increment and then test instead of computing
the trip count. The last increment would then overflow - well what was
supposed to be the last increment. That seems quite plausible to me.

Then the 'compiler' is not a Fortran compiler as 8.1.6.4.2
clearly states that the iteration count is tested for loop
termination, and the manipulation of the iteration count
involves a decrement not an increment.

Also note that the standard does not specific the type
or kind type parameter of the iteration count.

PS: One doesn't need to you a GOTO.

program foo
implicit none
double precision, volatile :: d
integer j, k
common /noop/ d
k = - huge(k)
do
if (k == huge(k)) exit
d = k
call bar
j = d
if (j /= k) print *, j, k, d
k = k + 1
end do
d = k
call bar
j = d
if (j /= k) print *, j, k, d
end program foo

subroutine bar
return
end subroutine bar

.



Relevant Pages

  • Re: storing an integer in a double precision
    ... But I don't see why the above do loop does not terminate. ... The trip count should be 6. ... The compiler might do an increment and then test instead of computing ... Also note that the value of i after the DO loop terminates should be ...
    (comp.lang.fortran)
  • Re: Definition of expression and statement.
    ... The fact that a while loop is recognized ... behavior, e.g., if a is an "int" variable and is initially set to ... The various modifier operators, ... increment and decrement, have TWO uses: ...
    (comp.lang.c)
  • Re: Letter to US Sen. Byron Dorgan re unpaid overtime
    ... it's a for loop in the C sense. ... >> sloppy thinking that results from confusing a programming language ... > The line count increment is necessary because the value is used as an offset ... I really hope you know that the C compiler will generate code to ...
    (comp.programming)
  • Re: Definition of expression and statement.
    ... they end with a semicolon, are not recognized as an "expression" ... The fact that a while loop is recognized ... The various modifier operators, ... increment and decrement, have TWO uses: ...
    (comp.lang.c)
  • Re: The inaugural VB6 vs dot net test
    ... increment a third variable inside the inner loop. ... But I was repsonding to Ulrich's statement about counting down to zero as opposed to counting up to a specific value in order to save a couple of clock cycles. ... WTF is the point of doing that if you are then going to include and additional otherwise unnecessary pointer that gets incremented within the loop, which will eat up as least as many clock cycles as you saved, thereby negating your efforts! ...
    (microsoft.public.vb.general.discussion)