Skip to content

bug: make math.clamp invalid bounds deterministic #98

Description

@vycdev2

Summary

math.clamp delegates directly to Rust f64::clamp. Reversed bounds panic the interpreter instead of returning a controlled Jett runtime error; NaN bounds have the same host-panic behavior.

Reproduction

function main() returns nothing:
    float64 value = math.clamp(1.0, 2.0, 1.0)
    println(value)

cargo run -q -p jett_cli -- run <fixture> exits with Rust panic code 101 (min > max, or either was NaN) on current main.

Scope

  • validate floating-point lower/upper bounds before invoking the host clamp implementation;
  • return deterministic Jett runtime errors for reversed bounds and NaN bounds;
  • add runtime-failure regressions proving invalid bounds no longer unwind the interpreter;
  • preserve valid floating-point clamping behavior.

The public typechecker signature is math.clamp(float64, float64, float64) -> float64; the interpreter also contains an unreachable integer arm, which is outside this narrow fix. This is intentionally separate from #63, which excludes math.clamp pending an explicit invalid-bound/NaN contract.

Acceptance criteria

  • Reversed floating-point bounds produce a controlled runtime error.
  • NaN floating-point bounds produce a controlled runtime error.
  • Existing valid math.clamp cases continue to pass.
  • cargo fmt --check, cargo build, and cargo test -q pass.

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