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.

2
  • 2
    possible duplicate of Catch integer exceptions in Fortran Commented Oct 19, 2013 at 7:24
  • interesting, we know you cant count on an overflow going negative, but shouldn't this code catch it when it does? Commented Oct 19, 2013 at 14:15

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.