This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: patch ping Re: [java] Fix BigDecimal ROUND_HALF_EVEN


Mark Wielaard wrote:

All added. Final patch as committed attached.

Thanks!


+	BigInteger posRemainder
+	  = parts[1].signum () < 0 ? parts[1].negate() : parts[1];
+	valIntVal = valIntVal.signum () < 0 ? valIntVal.negate () : valIntVal;
+	int half = posRemainder.shiftLeft(1).compareTo(valIntVal);

Another possible optimization: If parts[1] and valIntVal are both negative, then you can compare their absolute values, and negate half. If they have different signs, you can combine the negate and compare into an addition and signum.
BigInteger twiceRemainder = posRemainder.shiftLeft(1);
boolean remNegative = twiceRemainder.signum() < 0;
boolean valnegative = valIntVal.signum () < 0;
int half = remNegative == valNegative
? twiceRemainder.add(valIntVal).signum()
: twiceRemainder.compareTo(valIntVal);
if (remNegative)
half = - half;
--
--Per Bothner
per@bothner.com http://per.bothner.com/




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]