ionspin / kotlin-multiplatform-bignum

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

Incorrect values for modInverse function #289

Closed HoangNguyen219 closed 2 months ago

HoangNguyen219 commented 4 months ago

Describe the bug Incorrect values for modInverse function

To Reproduce Steps to reproduce the behavior:

    @Test
    fun testModInverse() {
        val a = BigInteger.parseString("54647")
            .modInverse(BigInteger.parseString("1157920"))

        assertEquals(
            BigInteger.parseString("1141223"),
            a
        )
Expected :1141223
Actual   :-16697

Expected behavior In java.math this test is successful:

    @Test
    public void testModInverse() {
        BigInteger a = new BigInteger("54647")
                .modInverse(new BigInteger("1157920"));
        assertEquals(new BigInteger("1141223"), a);
    }
ionspin commented 4 months ago

Thanks for reporting, I'll give it a look when I have some free time.

ionspin commented 2 months ago

Fixed in #306