Karatsuba added, 2 bugs are fixed #328

Merged
zhelenskiy merged 15 commits from dev into dev 2021-05-14 09:12:26 +03:00
2 changed files with 2 additions and 1 deletions
Showing only changes of commit d17a3ac6ef - Show all commits

View File

@ -254,6 +254,7 @@ public interface Ring<T> : Group<T>, RingOperations<T> {
public fun T.pow(exponent: ULong): T = when { public fun T.pow(exponent: ULong): T = when {
this == zero && exponent > 0UL -> zero this == zero && exponent > 0UL -> zero
this == one -> this this == one -> this
this == -one -> powWithoutOptimization(exponent % 2UL)
else -> powWithoutOptimization(exponent) else -> powWithoutOptimization(exponent)
} }

View File

@ -25,7 +25,7 @@ internal class BigIntAlgebraTest {
@Test @Test
fun testKBigIntegerRingPow() { fun testKBigIntegerRingPow() {
BigIntField { BigIntField {
for (num in 0..5) for (num in -5..5)
for (exponent in 0UL..10UL) for (exponent in 0UL..10UL)
assertEquals( assertEquals(
num.toDouble().pow(exponent.toInt()).toLong().toBigInt(), num.toDouble().pow(exponent.toInt()).toLong().toBigInt(),