patch ping Re: [java] Fix BigDecimal ROUND_HALF_EVEN
Per Bothner
per@bothner.com
Fri Aug 1 16:33:00 GMT 2003
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/
More information about the Java
mailing list