ionspin / kotlin-multiplatform-bignum

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

Pow doesnt handle Long.MIN_VALUE special case #204

Closed ionspin closed 2 years ago

ionspin commented 2 years ago

Describe the bug When exponentiation with Long.MIN_VALUE is requested, invalid result is returned. This is caused by using `Long.absoluteValue()' internally, which has the following special case:

Long.MIN_VALUE.absoluteValue is Long.MIN_VALUE due to an overflow

This then causes the loop to be skipped because the range has no elements.

To Reproduce Use .pow(Long.MIN_VALUE) and observe immediate return.

Expected behavior Operation is properly calculated

Platform All

ionspin commented 2 years ago

Specifically this is for BigDecimal