[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[imp-commit] r22946 - trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/impl/fast
|
- From: genie@xxxxxxxxxxx
- Date: Thu, 22 Dec 2011 04:51:54 -0500 (EST)
- Delivered-to: imp-commit@eclipse.org
Author: jvinju
Date: 2011-12-22 04:51:54 -0500 (Thu, 22 Dec 2011)
New Revision: 22946
Modified:
trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/impl/fast/IntegerValue.java
Log:
fixed bug #366197, patch by Atze van der Ploeg to fix modulo implementation
Modified: trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/impl/fast/IntegerValue.java
===================================================================
--- trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/impl/fast/IntegerValue.java 2011-12-20 12:23:36 UTC (rev 22945)
+++ trunk/org.eclipse.imp.pdb.values/src/org/eclipse/imp/pdb/facts/impl/fast/IntegerValue.java 2011-12-22 09:51:54 UTC (rev 22946)
@@ -269,14 +269,16 @@
public IInteger mod(IInteger other){
if(other instanceof BigIntegerValue){
if(value < 0){
- return ValueFactory.getInstance().integer((~value) + 1);
+ BigInteger m = ((BigIntegerValue)other).toBigInteger();
+ // i.e. -1 % m = m + (-1)
+ BigInteger res = m.add(toBigInteger());
+ return ValueFactory.getInstance().integer(res);
}
return this;
}
-
+ int otherVal = other.intValue();
int newValue = value % other.intValue();
- newValue = newValue >= 0 ? newValue : ((~newValue) + 1);
-
+ newValue = newValue >= 0 ? newValue : newValue + otherVal;
return ValueFactory.getInstance().integer(newValue);
}