Further optimization of power is added

This commit is contained in:
zhelenskiy 2021-05-10 18:24:13 +03:00
parent 1716b7f5d1
commit d17a3ac6ef
2 changed files with 2 additions and 1 deletions

View File

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

View File

@ -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(),