From d17a3ac6eff3d6c62e99af7e030010846afd413b Mon Sep 17 00:00:00 2001 From: zhelenskiy Date: Mon, 10 May 2021 18:24:13 +0300 Subject: [PATCH] Further optimization of power is added --- .../kotlin/space/kscience/kmath/operations/Algebra.kt | 1 + .../kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt index 49861b543..f7c021998 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/Algebra.kt @@ -254,6 +254,7 @@ public interface Ring : Group, RingOperations { public fun T.pow(exponent: ULong): T = when { this == zero && exponent > 0UL -> zero this == one -> this + this == -one -> powWithoutOptimization(exponent % 2UL) else -> powWithoutOptimization(exponent) } diff --git a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt index 05b73b49d..90cd29758 100644 --- a/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt +++ b/kmath-core/src/commonTest/kotlin/space/kscience/kmath/operations/BigIntAlgebraTest.kt @@ -25,7 +25,7 @@ internal class BigIntAlgebraTest { @Test fun testKBigIntegerRingPow() { BigIntField { - for (num in 0..5) + for (num in -5..5) for (exponent in 0UL..10UL) assertEquals( num.toDouble().pow(exponent.toInt()).toLong().toBigInt(),