From ee4d22265c17bdd721972fc2a4bee259972a7e07 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 12 Nov 2025 21:51:05 +0100 Subject: [PATCH] python pow function fixed and changed to musl implementation --- src/copapy/_basic_types.py | 2 +- src/copapy/_math.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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