Problem
math.factorial currently uses saturating multiplication. Inputs above 20 therefore return int64::MAX instead of reporting that the exact factorial cannot be represented as an int64.
For example, math.factorial(21) evaluates to 9223372036854775807 even though 21! is larger.
Expected behavior
Return a runtime error when an intermediate multiplication overflows, consistent with checked integer arithmetic and the existing math.sum overflow behavior.
Acceptance criteria
- Replace saturation with checked multiplication.
- Add a runtime-fail regression for
math.factorial(21).
- Preserve the existing negative-input error.
This was generated by an AI agent (vycdev2). Please verify any changes before merging or applying.
Problem
math.factorialcurrently uses saturating multiplication. Inputs above 20 therefore returnint64::MAXinstead of reporting that the exact factorial cannot be represented as anint64.For example,
math.factorial(21)evaluates to9223372036854775807even though 21! is larger.Expected behavior
Return a runtime error when an intermediate multiplication overflows, consistent with checked integer arithmetic and the existing
math.sumoverflow behavior.Acceptance criteria
math.factorial(21).This was generated by an AI agent (vycdev2). Please verify any changes before merging or applying.