Skip to content

Commit 411774d

Browse files
ayomaska18Copilot
andauthored
Update src/tools/local/calculator.py
update calculator factorial exception Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f5f19f1 commit 411774d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/tools/local/calculator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ async def factorial(n: int) -> dict:
5151
"""Calculate factorial of n (must be non-negative)."""
5252
if n < 0:
5353
return _err("Factorial undefined for negative numbers")
54-
return _ok({"operation": "factorial", "n": n, "result": math.factorial(n)})
54+
try:
55+
result = math.factorial(n)
56+
except (OverflowError, MemoryError):
57+
return _err("Factorial result too large to compute")
58+
return _ok({"operation": "factorial", "n": n, "result": result})
5559

5660

5761
@tool("calculator_is_prime")

0 commit comments

Comments
 (0)