From 1b60f71ed0efbba385c3e8b65ab4147deff013db Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 14 May 2021 09:14:48 +0300 Subject: [PATCH] Revert "fixes to power" This reverts commit bdb9ce6a --- .../kscience/kmath/operations/algebraExtensions.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt index 338dc6a5c..9691c9d17 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/algebraExtensions.kt @@ -108,9 +108,9 @@ public fun Sequence.averageWith(space: S): T where S : Ring, S : Sc * @author Evgeniy Zhelenskiy */ public fun Ring.power(arg: T, power: UInt): T = when { - arg == zero && power > 0U -> zero - arg == one -> arg - arg == -one -> powWithoutOptimization(arg, power % 2U) + this == zero && power > 0U -> zero + this == one -> arg + this == -one -> powWithoutOptimization(arg, power % 2U) else -> powWithoutOptimization(arg, power) } @@ -135,7 +135,7 @@ private fun Ring.powWithoutOptimization(base: T, exponent: UInt): T = whe * @return the base raised to the power. * @author Iaroslav Postovalov, Evgeniy Zhelenskiy */ -public fun Field.power(arg: T, power: UInt): T = when { - power < 0 -> one / (this as Ring).power(arg, power) - else -> (this as Ring).power(arg, power) +public fun Field.power(arg: T, power: Int): T = when { + power < 0 -> one / (this as Ring).power(arg, if (power == Int.MIN_VALUE) Int.MAX_VALUE.toUInt().inc() else (-power).toUInt()) + else -> (this as Ring).power(arg, power.toUInt()) }