ionspin / kotlin-multiplatform-bignum

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

Unary minus (and `negate`) are incorrect for `ModularBigInteger` #292

Closed iaik-jheher closed 1 month ago

iaik-jheher commented 1 month ago

ModularBigInteger::negate simply returns this. It should return the additive inverse (modulus - residue).

MWE:

val creator = ModularBigInteger.creatorForModulo(7)
val a = creator.fromInt(6)
val b = creator.fromInt(3)
require ((a-b) == (a+(-b)))