forked from kscience/kmath
Further optimization of power is added
This commit is contained in:
parent
1716b7f5d1
commit
d17a3ac6ef
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(),
|
||||||
|
Loading…
Reference in New Issue
Block a user