diff --git a/src/copapy/_basic_types.py b/src/copapy/_basic_types.py index acafd77..044203e 100644 --- a/src/copapy/_basic_types.py +++ b/src/copapy/_basic_types.py @@ -243,7 +243,7 @@ class variable(Generic[TNum], Net): @overload def __rpow__(self, other: float) -> 'variable[float]': ... def __rpow__(self, other: NumLike) -> Any: - return add_op('rpow', [other, self]) + return cp.pow(other, self) def __hash__(self) -> int: return super().__hash__() diff --git a/src/copapy/_math.py b/src/copapy/_math.py index ae8b4f5..dfa251c 100644 --- a/src/copapy/_math.py +++ b/src/copapy/_math.py @@ -57,7 +57,7 @@ def pow(x: NumLike, y: NumLike) -> NumLike: Returns: result of x**y """ - if isinstance(y, int) and 0 <= y < 16: + if isinstance(y, int) and 0 <= y < 8: if y == 0: return 1 m = x @@ -66,7 +66,10 @@ def pow(x: NumLike, y: NumLike) -> NumLike: return m if y == -1: return 1 / x - return exp(y * log(x)) + if isinstance(x, variable) or isinstance(y, variable): + return add_op('pow', [x, y]) + else: + return float(x ** y) @overload