Re: storing an integer in a double precision
- From: steve <kargls@xxxxxxxxxxx>
- Date: Fri, 6 May 2011 09:24:21 -0700 (PDT)
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
.
- Follow-Ups:
- Re: storing an integer in a double precision
- From: Richard Maine
- Re: storing an integer in a double precision
- References:
- storing an integer in a double precision
- From: Lynn McGuire
- Re: storing an integer in a double precision
- From: Richard Maine
- Re: storing an integer in a double precision
- From: Lynn McGuire
- Re: storing an integer in a double precision
- From: gmail-unlp
- Re: storing an integer in a double precision
- From: steve
- Re: storing an integer in a double precision
- From: tholen
- Re: storing an integer in a double precision
- From: robin
- Re: storing an integer in a double precision
- From: gmail-unlp
- Re: storing an integer in a double precision
- From: robin
- Re: storing an integer in a double precision
- From: Ron Shepard
- Re: storing an integer in a double precision
- From: Richard Maine
- storing an integer in a double precision
- Prev by Date: Re: storing an integer in a double precision
- Next by Date: Re: storing an integer in a double precision
- Previous by thread: Re: storing an integer in a double precision
- Next by thread: Re: storing an integer in a double precision
- Index(es):
Relevant Pages
|