We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f5f19f1 commit 411774dCopy full SHA for 411774d
src/tools/local/calculator.py
@@ -51,7 +51,11 @@ async def factorial(n: int) -> dict:
51
"""Calculate factorial of n (must be non-negative)."""
52
if n < 0:
53
return _err("Factorial undefined for negative numbers")
54
- return _ok({"operation": "factorial", "n": n, "result": math.factorial(n)})
+ 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})
59
60
61
@tool("calculator_is_prime")
0 commit comments