Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect values for % operator on negative numbers #285

Open
sergeych opened this issue Apr 2, 2024 · 1 comment
Open

incorrect values for % operator on negative numbers #285

sergeych opened this issue Apr 2, 2024 · 1 comment
Assignees

Comments

@sergeych
Copy link

sergeych commented Apr 2, 2024

assertEquals("${-15.5 % 360.0}", ((-15.5).bd % 360.bd).toStringExpanded())

fails:

Expected :-15.5
Actual   :-0.155
  • was like this at least on JVM.

Full test cor convenience:

import com.ionspin.kotlin.bignum.decimal.BigDecimal
import kotlin.test.Test
import kotlin.test.assertEquals

val Double.bd get() = BigDecimal.fromDouble(this)
class BdtoolsTest {
    @Test
    fun testMod2() {
        // OK
        assertEquals("15.5", ((360.bd * 5 + 15.5.bd) % 360.bd).toStringExpanded())
        // NG
        assertEquals("${-15.5 % 360.0}", ((-15.5).bd % 360.bd).toStringExpanded())
    }
}
@ionspin
Copy link
Owner

ionspin commented Apr 2, 2024

Thanks for reporting!

@ionspin ionspin self-assigned this Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants