|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Tue May 26, 2020 1:49 am Post subject: Missing trap on integer overflow |
|
|
In the process of stress testing some code, I came across the following. If the result of a double precision operation to be stored in an integer exceeds the possible range of that integer, there is no exception generated, and the program terminates (and it takes a long time to do so). The following code illustrates the issue. I perform the calculation with the result being a 64-bit integer (stored into a 32-bit), the result calculated as a 32-bit integer (fails), and an implicit conversion across the equals sign (never gets here, actually). Only the first result gets output, and no overflow is detected with the conversion across the equals sign. /CHECKMATE and /RELEASE operate the same way.
Code: | program main
integer:: i_xx,i_yy,i_zz
real*8:: ddx
ddx = 9999999.d0
i_xx = int(ddx*1000.d0,4)
print *,i_xx
i_zz = int(ddx*1000.d0,3)
print *,i_zz
i_yy = ddx*1000.d0
print *,i_yy
end
|
Is there a compiler option to enforce the checking? Or, is there no run-time exception handler?
Bill |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Tue May 26, 2020 7:04 am Post subject: |
|
|
The quick answer is that integer overflow is detected for integer calculations when /debug is applied. This is true for both 32 bits and 64 bits.
Code: | integer k
k = 10
do i = 1,100
k = 10*k
end do
end |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Tue May 26, 2020 9:28 am Post subject: |
|
|
Floating point overflow is detected (both 32 bits and 64 bits) without any options applied...
Code: | real k
k = 10.0
do i = 1,100
k = k*k
end do
end |
|
|
Back to top |
|
|
wahorger
Joined: 13 Oct 2014 Posts: 1217 Location: Morrison, CO, USA
|
Posted: Tue May 26, 2020 1:18 pm Post subject: |
|
|
Paul, this is good news. For my /CHECKMATE version, I'll apply /DEBUG as well.
Thanks!
Bill |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|