forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Missing trap on integer overflow

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
wahorger



Joined: 13 Oct 2014
Posts: 801
Location: Morrison, CO, USA

PostPosted: Tue May 26, 2020 1:49 am    Post subject: Missing trap on integer overflow Reply with quote

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
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6531
Location: Salford, UK

PostPosted: Tue May 26, 2020 7:04 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6531
Location: Salford, UK

PostPosted: Tue May 26, 2020 9:28 am    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 801
Location: Morrison, CO, USA

PostPosted: Tue May 26, 2020 1:18 pm    Post subject: Reply with quote

Paul, this is good news. For my /CHECKMATE version, I'll apply /DEBUG as well.

Thanks!
Bill
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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