diff --git a/src/main/kotlin/hm/binkley/math/BigRationalBase.kt b/src/main/kotlin/hm/binkley/math/BigRationalBase.kt index 54fd703e..0dc218ce 100644 --- a/src/main/kotlin/hm/binkley/math/BigRationalBase.kt +++ b/src/main/kotlin/hm/binkley/math/BigRationalBase.kt @@ -749,6 +749,10 @@ fun > T.pow(exponent: Int): T = when { else -> reciprocal.pow(-exponent) } +/** Provides a pseudo-operator for exponentiation. */ +@Suppress("FunctionName") +infix fun > T.`**`(exponent: Int) = pow(exponent) + /** * Returns the rational square root. * diff --git a/src/test/kotlin/hm/binkley/math/fixed/FixedBigRationalTest.kt b/src/test/kotlin/hm/binkley/math/fixed/FixedBigRationalTest.kt index 94e83125..e0075cd0 100644 --- a/src/test/kotlin/hm/binkley/math/fixed/FixedBigRationalTest.kt +++ b/src/test/kotlin/hm/binkley/math/fixed/FixedBigRationalTest.kt @@ -4,6 +4,7 @@ package hm.binkley.math.fixed import hm.binkley.math.BDouble import hm.binkley.math.BInt +import hm.binkley.math.`**` // ktlint-disable no-wildcard-imports import hm.binkley.math.ceil import hm.binkley.math.compareTo import hm.binkley.math.div @@ -21,13 +22,12 @@ import hm.binkley.math.isZero import hm.binkley.math.lcm import hm.binkley.math.minus import hm.binkley.math.plus -import hm.binkley.math.pow import hm.binkley.math.rangeTo import hm.binkley.math.rem -import hm.binkley.math.truncate import hm.binkley.math.sqrt import hm.binkley.math.step import hm.binkley.math.times +import hm.binkley.math.truncate import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertNotEquals @@ -1085,15 +1085,15 @@ internal class FixedBigRationalTest { fun `should raise`() { assertEquals( 9 over 25, - (3 over 5).pow(2) + (3 over 5) `**` 2 ) assertEquals( ONE, - (3 over 5).pow(0) + (3 over 5) `**` 0 ) assertEquals( 25 over 9, - (3 over 5).pow(-2) + (3 over 5) `**` -2 ) } diff --git a/src/test/kotlin/hm/binkley/math/floating/FloatingBigRationalTest.kt b/src/test/kotlin/hm/binkley/math/floating/FloatingBigRationalTest.kt index 75b52881..9676250b 100644 --- a/src/test/kotlin/hm/binkley/math/floating/FloatingBigRationalTest.kt +++ b/src/test/kotlin/hm/binkley/math/floating/FloatingBigRationalTest.kt @@ -4,6 +4,7 @@ package hm.binkley.math.floating import hm.binkley.math.BDouble import hm.binkley.math.BInt +import hm.binkley.math.`**` // ktlint-disable no-wildcard-imports import hm.binkley.math.backAgain import hm.binkley.math.ceil import hm.binkley.math.compareTo @@ -25,7 +26,6 @@ import hm.binkley.math.isZero import hm.binkley.math.lcm import hm.binkley.math.minus import hm.binkley.math.plus -import hm.binkley.math.pow import hm.binkley.math.rangeTo import hm.binkley.math.rem import hm.binkley.math.sqrt @@ -1461,15 +1461,15 @@ internal class FloatingBigRationalTest { fun `should raise`() { assertEquals( 9 over 25, - (3 over 5).pow(2) + (3 over 5) `**` 2 ) assertEquals( ONE, - (3 over 5).pow(0) + (3 over 5) `**` 0 ) assertEquals( 25 over 9, - (3 over 5).pow(-2) + (3 over 5) `**` -2 ) }