[Coin-discuss] arithmetic exception when using Cbc

Matthew Saltzman mjs at ces.clemson.edu
Thu Nov 2 23:11:49 EST 2006


On Thu, 2 Nov 2006, Michael Hennebry wrote:

> On Thu, 2 Nov 2006, Kish Shen wrote:
>
>> On Thursday 02 November 2006 17:27, Matthew Saltzman wrote:
>>> On Thu, 2 Nov 2006, Kish Shen wrote:
>
>>>> I am getting an arithmetic exception when using Cbc/Clp through OsiClp.
>>>> The crash happens in CbcModel.cpp, in gcd (line 84 in the copy I am
>>>> using):
>>>>
>>>>  while (remainder) {
>>>>    remainder = b % a;
>>>>    b = a;
>>>>    a = remainder;
>>>>  }
>>>>  return b;
>>>>
>>>> The crash happens  in doing the % operation, I assume because a = -1.
>>>
>>> Seems like an arithmetic exception should be easy to find.  Do you know
>>> what the args are that cause the crash?  What arch is this on?
>>>
>> The problem was run on 32 bit x86 Linux.
>>
>> By args do you mean the values of b, a etc.? Here are the values:
>>  (gdb) p b
>> $1 = -2147483648
>> (gdb) p a
>> $2 = -1
>> (gdb) p remainder
>> $3 = -1
>
> If evalutating b%a required evaluating b/a,
> that would explain the exception.
> 2147483648==2**31 and isn't representable
> as a signed 32-bit number

But -2147483648 is INT_MIN.  That's due to the assymetry of 2's complement 
representation of integers.

The code works on SPARC (terminates with b = -1) and loops forever on PPC 
with remainder == -2147483648.  Strange.  Looks like one should stay away 
from INT_MIN in this situation, but it's not clear why.  I think i386 and 
PPC are clearly wrong.  Using -2147483647 (-INT_MAX) seems fine on all 
three platforms.

>
>> I guess b looks like it might be wrong. The gcd is called from line 346 of CbcModel.cpp:
>
>

-- 
 		Matthew Saltzman

Clemson University Math Sciences
mjs AT clemson DOT edu
http://www.math.clemson.edu/~mjs



More information about the Coin-discuss mailing list