Silverfrost Forums

Welcome to our forums

Integer Arithmetic Overflow

13 May 2011 2:11 #8243

[URL=http://imageshack.us/photo/my-images/96/equationr.gif/]http://img96.imageshack.us/img96/4008/equationr.gif[/URL]

To prove that the roots of the above equation are x=2 and y=3, I wrote the following simple program and it works fine on a 64-bit Laptop-Ubuntu 10.10 with gfortran 95 compiler. In about 5 minutes or so, the compiler gives the results. However, Salford FTN95 Compiler (Plato3 IDE) on a 32-bit Desktop with Win XP/SP3 generates a run-time error stating 'Integer Arithmetic Overflow' both at line 4 and 6.

      INTEGER X, Y
      DOUBLE PRECISION A, B
      DO 20 X=32767,1,-1
          A=X**(X**(X**X))+74
          DO 10 Y=32767,1,-1
             B=(19-Y**X)*(Y**(X**Y))
             IF (A-B) 10,30,10
   10 CONTINUE
   20 CONTINUE
   30 WRITE (6, 40) X,Y
   40 FORMAT(//'X=',I2,2X,'Y=',I2)        
      END

I would appreciate any suggestions or comments. Thanks and regards.

13 May 2011 2:48 #8244

Are you sure?

How can any compiler handle

X**(X**(X**X)) when X = 32767.

For 32 bit integers you get overflow at about X = 3 I think.

13 May 2011 3:28 #8245

Hehehe, sure sign it's Friday 😄

Honore, was the question 'Prove that the roots of ... are ...'? In which case, you just need to compute the expression for x = 2 and y = 3 and show it is equal to 0.

If the question was 'Find the roots of ...', then you need to search for integer solutions as you have done. But Paul is right, iterated exponentiation gets phenomenally large very quickly as the argument increases. I have no idea how your program worked before, I can only imagine that it was failing to report every overflow until it found something that made computational sense near the end of the double do loop :roll:

13 May 2011 3:53 #8247

Thanks for the comments and critiques. Yes, the question was actually on finding the roots of the equation. The solution by hand is okay and I am trying to prove the solution using Fortran.

I changed the program a bit as follows and the output came out again as expected. What I more wonder is why Plato 3 cannot do some similar optimisation if any required.

Thanks and regards

[URL=http://img577.imageshack.us/i/outputa.gif/]http://img577.imageshack.us/img577/1943/outputa.gif[/URL]

13 May 2011 4:10 #8248

I think you are failing to appreciate the mindboggling vastness of the numbers you think you are manipulating with your program.

You have set A and B to be selected_int_kind(18 ). That means they can be as big as 10 with 18 zeros after it (give or take).

How big is 32767327673276732767? Well, let's set our sights a little lower. How big is 10101010?

1010 = 10 with 10 0s after it. That's 10,000,000 So 101010 is 10 with 1010 = 10,000,000 zeros after it

10,000,000 >>>>>>>>>>> 18 10 <<<<<<<<<<<<<<<< 32,767

Game comprehensively over.

Whatever else your other program is doing, it is not telling you that it is spending most of its time overflowing left right and centre.

Score one elementary point for FTN95. Subtract one whopping point for gfortran 95.

13 May 2011 4:39 #8249

... and most of the satisfied FTN95 users are quietly congratulating themselves on not using a compiler that lets you make this big a mistake!

Eddie

13 May 2011 5:08 #8250

Thanks for the comments. When I try the program using lower numbers such as 10,000, 5000, 500, etc instead of 32767, the result is generated almost immediately. For this issue, FTN95 is not satisfactory enough for me.

14 May 2011 2:39 #8252

Honore,

While you may find FTN95 is not satisfactory enough, I think you need to better understand the limits of real calculations. May I suggest that I find your understanding of real calculations not satisfactory enough.

Try the changed code below: real10 x,y,a,b integer4 ix,iy ! do ix = 200,254 x = ix /100.0 A = X**(X**(XX))+74.0_3 write (,) ix,x,a end do ! DO iX = 1,3 x = ix A = X(X**(XX))+74.0_3 DO iY = 1,4 y = iy B = (19.0_3-YX)(Y**(X**Y)) write (,) x,a,y,b end do end do ! IF (A-B) 10,30,10 ! 10 CONTINUE ! 20 CONTINUE 30 WRITE (, 40) X,Y 40 FORMAT(//'X=',f0.1,2X,'Y=',f0.1)
END

14 May 2011 2:45 #8253

Suggest 'now satisfactory' instead of 'not satisfactory'?

Please login to reply.