ionspin / kotlin-multiplatform-bignum

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

BigDecimal floor() throws ArithmeticException if current exponent is negative #212

Closed mihbor closed 2 years ago

mihbor commented 2 years ago

Describe the bug https://github.com/ionspin/kotlin-multiplatform-bignum/blob/main/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt#L1445

    fun floor(): BigDecimal {
        return roundSignificand(DecimalMode(exponent + 1, RoundingMode.FLOOR))
    }

but DecimalMode doesn't accept neither 0 (with roundingMode != RoundingMode.NONE) nor negative precision.

To Reproduce Steps to reproduce the behavior: call floor() on a BigDecimal with negative exponent

Expected behavior A clear and concise description of what you expected to happen.

Platform JS

If JS (please complete the following information): chrome

Additional context bignum version 0.3.4

mihbor commented 2 years ago

A workaround is to instead call roundToDigitPositionAfterDecimalPoint(0, RoundingMode.FLOOR)

ionspin commented 2 years ago

Thanks for reporting!