First the bad news. In standard F95, exception handling is not supported. It is part of the F2003 standard, but as of yet pgf90 does not support F2003. “-Ktrap=fp” will trap floating point exceptions, but halts execution if one occurs. So you’ll need to devise a different method to accomplish this.
As for your seeing the floating point exception when calculating ifix. ifix converts a real to integer by truncating the real to a single precision real (32-bits) and then stores the value as a 32-bit integer. However, single precision reals use 1 bit for the sign, 8 bits for the exponent, and 23 bits for the mantissa (Note that there is an implied ‘1’ so the mantissa can be thought to have 24 bits). This means that the value 231-1 can not be exactly represented as single precision real and is rounded by the hardware to 231. This is causing the floating point exeception. Note, you can use pgdbg to walk through the assembly instructions and see how the values change in the x87 registers and where the exception occurs.
The largest actual integer you’ll be able to use is 2147483392 (231-255). To determine this take the hex value of 231-1, 0x7FFFFFFF and mask the last byte to account for the 23-bit mantissa to get 0x7FFFFF00. So instead of using exception handling, we can modify your program to test the data before its used, or use the minimum value if the actual value is too large.
real rmyreal, rmaxint
rmaxint = (2**31)-255
rmyreal = (2**31)-1
write(*,*) rmaxint, rmyreal
! First method, test the data before its used
if (rmyreal .gt. rmaxint) then
write(*,*), 'Bad Data'
! Second method, use the smaller of the values
i = int (amin1(rmyreal, rmaxint))
Hope this helps!