-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
22.0.1
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
JDK 22.0.1
A DESCRIPTION OF THE PROBLEM :
The methods compare and compareShifted implicitly assume that the operands have no leading zeros, but the the method compare is invoked by subtract, in which there isn't this assuption. Indeed, this leaded to several failures in an algorithm I was trying to implement for square root of MutableBigIntegers.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
MutableBigInteger a = new MutableBigInteger(new int[] { 0, 0 });
MutableBigInteger b = new MutableBigInteger(new int[] { 1 });
int comp = a.compare(b);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
comp == -1
ACTUAL -
comp == 1
---------- BEGIN SOURCE ----------
To execute this code, you must place this method in package java.math:
public static void main(String[] args) {
MutableBigInteger a = new MutableBigInteger(new int[] { 0, 0 });
MutableBigInteger b = new MutableBigInteger(new int[] { 1 });
if (a.compare(b) != a.toBigInteger().compareTo(b.toBigInteger()))
System.out.println("comparison failure");
}
---------- END SOURCE ----------
FREQUENCY : occasionally
JDK 22.0.1
A DESCRIPTION OF THE PROBLEM :
The methods compare and compareShifted implicitly assume that the operands have no leading zeros, but the the method compare is invoked by subtract, in which there isn't this assuption. Indeed, this leaded to several failures in an algorithm I was trying to implement for square root of MutableBigIntegers.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
MutableBigInteger a = new MutableBigInteger(new int[] { 0, 0 });
MutableBigInteger b = new MutableBigInteger(new int[] { 1 });
int comp = a.compare(b);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
comp == -1
ACTUAL -
comp == 1
---------- BEGIN SOURCE ----------
To execute this code, you must place this method in package java.math:
public static void main(String[] args) {
MutableBigInteger a = new MutableBigInteger(new int[] { 0, 0 });
MutableBigInteger b = new MutableBigInteger(new int[] { 1 });
if (a.compare(b) != a.toBigInteger().compareTo(b.toBigInteger()))
System.out.println("comparison failure");
}
---------- END SOURCE ----------
FREQUENCY : occasionally