@@ -2803,13 +2803,30 @@ let rec expBySquaring = (y, x, n) => {
28032803provide let (**) = (base, power) => {
28042804 let (==) = numberEq
28052805 let (!=) = (x, y) => !numberEq(x, y)
2806+ let basePtr = WasmI32.fromGrain(base)
2807+ let powerPtr = WasmI32.fromGrain(power)
28062808 if (base == 1 && power != 0) {
28072809 return 1
2808- } else if (
2809- isInteger(WasmI32.fromGrain(base)) && isInteger(WasmI32.fromGrain(power))
2810- ) {
2810+ } else if (isInteger(basePtr) && isInteger(powerPtr)) {
28112811 if (power < 0) return expBySquaring(1, 1 / base, power * -1)
28122812 else return expBySquaring(1, base, power)
2813+ } else if (isRational(basePtr) && isInteger(powerPtr)) {
2814+ // Apply expBySquaring to numerator and denominator
2815+ let numerator = WasmI32.fromGrain(base)
2816+ Memory.incRef(numerator)
2817+ let numerator = WasmI32.toGrain(numerator): Rational
2818+ let numerator = rationalNumerator(numerator)
2819+ let denominator = WasmI32.fromGrain(base)
2820+ Memory.incRef(denominator)
2821+ let denominator = WasmI32.toGrain(denominator): Rational
2822+ let denominator = rationalDenominator(denominator)
2823+ let numerator =
2824+ if (power < 0) expBySquaring(1, 1 / numerator, power * -1)
2825+ else expBySquaring(1, numerator, power)
2826+ let denominator =
2827+ if (power < 0) expBySquaring(1, 1 / denominator, power * -1)
2828+ else expBySquaring(1, denominator, power)
2829+ return numerator / denominator
28132830 } else {
28142831 // Based on https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c
28152832 from WasmF64 use {
0 commit comments