Skip to content

Commit

Permalink
fix: panic on negative exponent in ipow (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Jan 8, 2025
1 parent 4ae3032 commit 821771a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions guppylang/std/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,18 @@ def __or__(self: int, other: int) -> int: ...
@guppy.custom(NoopCompiler())
def __pos__(self: int) -> int: ...

# TODO replace with @guppy.hugr_op(int_op("ipow"))
# TODO use hugr int op "ipow"
# once lowering available
@guppy
@no_type_check
def __pow__(self: int, other: int) -> int:
# only positive exponents are supported
# TODO add panic for negative exponents once #756 is resolved
def __pow__(self: int, exponent: int) -> int:
if exponent < 0:
panic(
"Negative exponent not supported in"
"__pow__ with int type base. Try casting the base to float."
)
res = 1
for _ in range(other):
for _ in range(exponent):
res *= self
return res

Expand Down

0 comments on commit 821771a

Please sign in to comment.