Showing posts with label BigDecimal. Show all posts
Showing posts with label BigDecimal. Show all posts

Thursday, August 30, 2007

Decimal syntax

On this topic, Danny Coward recently referred to a limited form of operator overloading specifically for BigDecimal. Good to know this is still in Sun's thinking.

I'm continuing to look for users and companies who are willing to back the requirement for decimal syntax in Java, regardless of whether this is via limited operator overloading or decimal-specific support, so if anyone is interested, I'm all ears.

Thursday, February 22, 2007

Decimal syntax and operator overloading

As mentioned previously, I'm keen for Java to provide nice syntax for BigDecimal types. Someone asked me whether I was trying to sneak full operator overloading into Java through the back door. It's a reasonable concern.

Much as I like some other features of C++, I was very comfortable that Java omitted general operator overloading. So I am definitely not suggesting that BigDecimal syntax be introduced along with general operator overloading.

Of course, if these syntax improvements go ahead, Sun are free to add them via a limited form of operator overloading mechanism, but that's an implementation choice from my perspective and certainly not part of the requirement.

Friday, February 02, 2007

BigDecimal operator support in Java 7

One of the candidate items for Java 7 helpfully listed by Alex Miller is BigDecimal operator support. I'm keen to see this go in as it would really help customers who use decimals.

Mike Cowlishaw's General Decimal Arithmetic page is a rich source of information on this subject. It contains an example 'telco' benchmark coded in Java and C# which provide a helpful comparison when thinking about syntax support for BigDecimal.

Take the following sequence (massaged a little for display here) from the Java version:


b = p.multiply(basetax);
b = b.setScale(2, BigDecimal.ROUND_DOWN);
sumB = sumB.add(b);
t = p.add(b);

if (calltype != 0) {
d = p.multiply(disttax);
d = d.setScale(2, BigDecimal.ROUND_DOWN);
sumD = sumD.add(d);
t = t.add(d);
}

and compare the C# version for readability:

b = p * basetax * 100;
b = Decimal.Truncate(b) / 100;
sumB = sumB + b;
t = p + b;

if (calltype != 0) {
d = p * disttax * 100;
d = Decimal.Truncate(d) / 100;
sumD = sumD + d;
t = t + d;
}

Enough said?