0

I need to know, what is the problem with my overflow algorithm?, In Fortran I have to do an algorithm to return the number of the increment "n" when it reach the overflow break.

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

Its contains negative values, and "mutations" in factorial before reach the number that means "overflow", but it's false, n should be 15.

BHF
  • 748
  • 7
  • 19
lexcasa
  • 3
  • 3
  • 2
    possible duplicate of [Catch integer exceptions in Fortran](http://stackoverflow.com/questions/18881865/catch-integer-exceptions-in-fortran) – Alexander Vogt Oct 19 '13 at 07:24
  • interesting, we know you cant *count on* an overflow going negative, but shouldn't this code catch it when it does? – agentp Oct 19 '13 at 14:15

1 Answers1

0

I have never been a Fortran programmer but perhaps your return value should be a double.

Ross Bush
  • 14,648
  • 2
  • 32
  • 55