ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
350 stars 41 forks source link

BigDecimal.unaryMinus() drops decimalMode #184

Closed tadfisher closed 3 years ago

tadfisher commented 3 years ago

Describe the bug

abs() and negate() both preserve decimalMode, but unaryMinus() does not, which is unexpected.

To Reproduce Steps to reproduce the behavior:

val value = "20.11".toBigDecimal(decimalMode = DecimalMode.US_CURRENCY)

value.negate().decimalMode
// DecimalMode(decimalPrecision=4, roundingMode=ROUND_HALF_AWAY_FROM_ZERO, scale=2)

(-value).decimalMode
// null

Expected behavior Perhaps naively, I expect negate() to be synonymous with unaryMinus().

Platform JVM

ionspin commented 3 years ago

Thanks for reporting the issue @tadfisher ! The fix will be available in 0.3.2-SNAPSHOT build once the build is complete in an hour or two