Division of large negative number leads to integer overflow



Hello,

the program below results in an integer overflow, when dividing k by
m:

! Check behaviour of -(huge+1)/-1
!
program chk
implicit none
integer :: k, m, s

m = -1
k = -huge(k)-1

write(*,*) 'Largest negative number: ',k
s = k/m
write(*,*) 'Divided by -1: ', s
s = k*m
write(*,*) 'Multiplied by -1: ', s
s = -k
write(*,*) 'Negated: ', s
end program

I checked this with two different compilers on Windows XP. Is this
behaviour prescribed
by the standard or is it machine-dependent?

Just curious - it is a corner case that I do not expect to pop up all
that often in practice,
but I heard of it yesterday (in a Java/C# context) and thought I'd try
it in Fortran.

Regards,

Arjen

.