ionspin / kotlin-multiplatform-bignum

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

moveDecimalPoint 9 returns wrong longValue for some BigDecimals #237

Closed MrStahlfelge closed 1 year ago

MrStahlfelge commented 2 years ago

Describe the bug moveDecimalPoint(9) gives wrong results for some BigDecimals.

To Reproduce The following Unit Test demonstrates the problem:

        val bigDecimal = "1.123456780".toBigDecimal()
        assertEquals(112345678L, bigDecimal.moveDecimalPoint(8).longValue())
        assertEquals(11234567800L, bigDecimal.moveDecimalPoint(10).longValue())
        assertEquals(1123456780L, bigDecimal.moveDecimalPoint(9).longValue())

It fails on the last line.

Expected behavior Unit Test completing successful.

It works when providing a DecimalMode with a scale.

Platform