On Mon, Dec 31, 2012 at 07:10:25AM -0800, David Simmons-Duffin wrote:
> The old behavior seems correct to me. (It can be recovered by doing
> something like `(1+z40*z40)(
z40.mc)`, but this is somewhat ugly, and it
> would be nice to have the correct MathContext applied at each stage in a
> computation.) Was this change intentional? If so, what was the reasoning
> behind it, and what is the best way to recover the old behavior?
So, scala.math.BigDecimal is a bit of a fiasco. I agree that in this
case it'd be nice to have the 2.9 behavior, but the 2.9 behavior itself
broke other things (which worked in 2.8). As Paul mentioned on the
ticket, under 2.9 you get behavior like this:
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> BigDecimal("123895823953295832958329582392395923573925") % BigDecimal("3")
java.lang.ArithmeticException: Division impossible
So, the behavior was reverted to the 2.8 case to avoid these kinds of
crashes. I agree that the explosion of precision is bad, but I don't
think it's worth trading for these kinds of runtime errors.
I don't think many people would disagree that BigDecimal (and possibly
BigInt) need a major overhaul to be useful, non-buggy, first-class
members of the Scala ecosystem. I haven't had the time to try to sit
down and come up with a good overall design for it (yet) but would love
to collaborate on this if it's something you're interested in.
-- Erik