Doubles are contaminating my BigDecimal math

Viewed 246

I'm writing a Mandelbrot Set explorer. I need as much precision as possible so I can zoom in as far as possible.

I noticed an unfortunate side-effect of mixing doubles and BigDecimals: they "contaminate" the type returned:

(type (* 1M 2))
=> java.math.BigDecimal

(type (* 1M 2.0))
=> java.lang.Double

I expected the opposite. BigDecimals, being potentially more precise, should contaminate the doubles.

Besides manually calling bigdec on every number that may come in contact with a BigDecimal, is there a way of preventing the auto-downgrade to double when doing math on doubles and BigDecimals?

2 Answers
Related