-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
Describe the bug
For a specific overflow byte array, initialising creates a different value comapred to java's BigInteger.
To Reproduce
Steps to reproduce the behavior:
sample unit test:
@Test
fun foo() {
val bytes = byteArrayOf(-128, 0, 0, 0, 0, 0, 0, 0) // bytes: [-128, 0, 0, 0, 0, 0, 0, 0]
val javaBig = BigInteger(1, bytes) // javaBig: "9223372036854775808"
val kotlinBig = IonSpinBigInteger.fromByteArray(bytes, Sign.POSITIVE) // bytes: [-128, 0, 0, 0, 0, 0, 0, 0], kotlinBig: "0"
Assert.assertArrayEquals(javaBig.toByteArray(), kotlinBig.toByteArray()) // javaBig: "9223372036854775808", kotlinBig: "0"
}Expected behavior
Expected same numeric value as with java's BigInteger but it differs and this test fails.
Platform
JVM
Additional context
Although i encountered this issue for these specific values, there obviously could be more and randomised testing can help here.
Metadata
Metadata
Assignees
Labels
No labels