ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
339 stars 40 forks source link

Incorrect values for the "or" function #290

Open HoangNguyen219 opened 1 month ago

HoangNguyen219 commented 1 month ago

Describe the bug Incorrect values for the "or" function

Issue 1: Incorrect values To Reproduce

    @Test
    fun testOr() {
        val a = BigInteger.parseString("-1")
            .or(BigInteger.parseString("11"))

        assertEquals(
            BigInteger.parseString("-1"),
            a
        )
    }
Expected :-1
Actual   :-11

Expected behavior In java.math this test is successful:

    @Test
    public void testOr() {
        BigInteger a = new BigInteger("-1")
                .or(new BigInteger("11"));
        assertEquals(new BigInteger("-1"), a);
    }

Issue 2: When perform or function between a Number and Zero throw an exception To Reproduce

    @Test
    fun testOr() {
        val a = BigInteger.parseString("0")
            .or(BigInteger.parseString("11"))

        assertEquals(
            BigInteger.parseString("11"),
            a
        )
    }
sign should be Sign.ZERO iff magnitude has a value of 0
java.lang.IllegalArgumentException: sign should be Sign.ZERO iff magnitude has a value of 0

Expected behavior In java.math this test is successful:

    @Test
    public void testOr() {
        BigInteger a = new BigInteger("0")
                .or(new BigInteger("11"));
        assertEquals(new BigInteger("11"), a);
    }
ionspin commented 1 month ago

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