[Tim]

Try to spell out what you mean - precisely! - by "this". I can't do that for you. For any plausible way of fleshing it out I've thought of, the answer is "no".

[Marco Sulla Marco.Sulla.Python@gmail.com]

Well, please, don't be so harsh. I'm trying to discuss to someone that co-created Python itself, it's not simple to me :-P

Sorry, I didn't mean to come off as harsh. I did mean to come off as saying that details are important here - indeed, details are darned near everything here. I'm not going to discuss vague wishlists in this area.

The closest you can get to BigDecimal's behavior "by magic" in Python is to set the context precision to its maximum allowed value.

I think there's another "trick" to get the BigDecimal behaviour. If you read the Javadoc, it says that each operation has a default precision. For example, multiplication a*b has precision = a_scale + b_scale. So, in reality, also BigDecimal has a context with finite precision. The difference is that the default context has a variable precision, depending on the operation.

Scale is the conceptual exponent in BigDecimal - it has nothing to do with digits of precision. For example, every normalized odd BigDecimal integer has scale 0, regardless of whether the integer is 1, or 17 to the millionth power. A BigDecimal with significand `sig` (an integer) and scale `s` (also an integer) represents the real number sig * 10**-s.

That's where the motivation for the rule you paraphrased came from: mathematically,

(a_sig * 10**-a_s) * (b_sig * 10**-b_s) = (a_sig * b_sig) * 10**-(a_s + b_s)

So "the natural" scale of the product is the sum of their scales (a_s + b_s), but the significand of the product is the infinite-precision product of their signficands, no matter how many bits that takes.

For example, try this:

BigDecimal a = new BigDecimal("500").multiply(new BigDecimal("100000000")); System.out.println(a); System.out.println(a.scale()); System.out.println(a.precision());

The output:

50000000000 0 11

The precision is 11 (decimal) digits, but the scale is 0. Change it to:

new BigDecimal("5e2").multiply(new BigDecimal("1e8"))

and the output changes to

5E+10 -10 1

Could Python decimal have something similar, maybe by setting prec = -1?

No ;-)