0
我需要知道,我的溢出算法有什么问题?在Fortran中,我必须执行一种算法,以在返回溢出中断时返回增量“n”的数量。Fortran溢出算法
program overflow
integer::n,i,fact;
fact = 1;
n = 50;
do i=1,n,1
fact=fact*i;
if ((fact==abs(fact)).and.(fact /= 0)) then
print*,"F!=",fact;
n=n+1;
!print*,"Overflow=",n;
end if;
end do;
print*,n;
end program overflow
它包含负值,而“突变”的阶乘之前到达,意思是“溢出”的数量,但它是假的,正应该是15
可能重复的[在Fortran中捕获整数异常](http://stackoverflow.com/questions/18881865/catch-integer-exceptions-in-fortran) –
有趣的是,我们知道你不能*计数溢出会否定的,但是它不应该在它的时候捕获它吗? – agentp