ionspin / kotlin-multiplatform-bignum

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

BigInteger.longValue() doesn't take sign into account #186

Closed dsvdmeer closed 3 years ago

dsvdmeer commented 3 years ago

Describe the bug When converting a BigInteger with a negative value to a Long using longValue(), it produces a positive result.

To Reproduce Steps to reproduce the behavior:

val bigInteger = (-12L).toBigInteger()
val asLong = bigInteger.longValue(exactRequired = true)
assertEquals(-12L, asLong) // Fails here

Expected behavior In the above example, asLong should equal -12.

Platform

ionspin commented 3 years ago

@dsvdmeer Thanks for reporting the issue! The fix should be available in snapshot version once the master branch build request is completed, in an hour or so barring any issues.