ionspin / kotlin-multiplatform-bignum

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

[BUG] Exponentiating a zero BigDecimal by any negative long yields division by zero #206

Closed JoonasC closed 2 years ago

JoonasC commented 2 years ago

Describe the bug Exponentiating a zero BigDecimal by any negative long yields division by zero.

To Reproduce Run the following code:

val a = 0.0.toBigDecimal(decimalMode = DecimalMode(6L, RoundingMode.CEILING, -1L))
val b = (-1.0).toBigDecimal(decimalMode = DecimalMode(6L, RoundingMode.CEILING, -1L))

a.pow(b.longValue(false)) // Division by zero

Expected behavior Throw a more concise exception, explaining that the negative exponentiation of zero is not defined.

Platform

ionspin commented 2 years ago

Thanks!