Skip to content

bug: report math.factorial overflow #105

Description

@vycdev2

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions