home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,891 of 2,978   
   Jim Leonard to All   
   longint and/or overflow bug?   
   30 Oct 12 08:56:34   
   
   e1050251   
   From: mobygamer@gmail.com   
      
   When I write and debug programs, it is always with range/stack/arith   
   checking on.  In my current project, I am seeing Arith overflow {$Q+}   
   errors when trying to do legal operations with a longint variable as   
   the destination.  Observe the following code:   
      
   ===begin===   
   {$Q+,R+,S+}   
      
   const   
     val1=$0123; val2=$4567;   
      
   var   
     l:longint;   
     w1,w2:word;   
      
   begin   
     w1:=val1; w2:=val2;   
     l:=w1 * w2; {Throws runtime 215 "arithmetic overflow" if $Q+}   
     if l<>(val1*val2) then writeln('Error in longint math routines!');   
   end.   
   ====end====   
      
   With $Q+, the second main line throws an overflow error even though   
   the source variables and values cannot possibly overflow the target.   
   With $Q-, the third line throws "error in longint math routines" as   
   the end result is wrong.   
      
   What is going on?  Is there a bug in the longint math routines, or a   
   bug in code generation, or something else?  If you run the above code   
   with your copy of TP7, do you see the same behavior?   
      
   (The workaround is to do everything "longhand" like this:   
      
   l:=w1;   
   l:=l * w2;   
      
   This works, but my code is starting to look ugly.)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca