Skip to content

Reject out-of-range numeric casts - #804

Merged
aannleax merged 1 commit into
knowsys:mainfrom
mattfaltyn:fix-numeric-cast-bounds
Aug 14, 2026
Merged

aannleax merged 1 commit into
knowsys:mainfrom
mattfaltyn:fix-numeric-cast-bounds

Conversation

@mattfaltyn

Copy link
Copy Markdown
Contributor

Summary

  • reject out-of-range float and double inputs to INT instead of saturating them
  • return no value when narrowing a double to FLOAT produces a non-finite value
  • cover positive and negative overflow alongside representable control and boundary cases

Why

Numeric casts are partial operations: inputs that the target datatype cannot represent should produce no value. Previously, Rust's as i64 conversion silently clamped large floating-point values to i64::MIN or i64::MAX, while double-to-float overflow reached an expect and panicked the process.

The implementation now uses the existing checked numeric conversion for integer targets and propagates the float constructor's error as None.

Fixes #803.

Testing

  • cargo test --workspace
  • cargo test --workspace function::evaluation::test::evaluate_casting -- --exact
  • cargo fmt --all -- --check
  • RUSTFLAGS=-Dwarnings cargo clippy --all-targets --workspace --verbose
  • RUSTFLAGS=-Dwarnings RUSTDOCFLAGS=-Dwarnings cargo doc --workspace
  • pycodestyle nemo-python
  • built nemo-cli and reran both issue reproductions; invalid casts emit no fact, while a valid control still emits 42

Local environment limitations

  • the full Miri suite reaches an existing Apple ARM limitation in bytecount: Miri does not support the invoked AArch64 NEON intrinsic
  • a focused nemo-physical Miri run is blocked before this test by an existing #[tokio::test] expansion error on the local Apple/nightly toolchain
  • Python wheel tests require maturin, which is not installed locally
  • browser WASM tests require wasm-pack and configured Firefox/Chrome executables, which are not installed locally

The repository's Linux CI covers these platform-dependent jobs.

@github-project-automation github-project-automation Bot moved this to Todo in nemo Aug 12, 2026
@mattfaltyn
mattfaltyn marked this pull request as ready for review August 12, 2026 20:01
Return no value when INT or FLOAT cannot represent their input instead of
clamping or panicking.

Fixes knowsys#803
@mattfaltyn
mattfaltyn force-pushed the fix-numeric-cast-bounds branch from 82e0297 to d6bd67f Compare August 12, 2026 20:14

@aannleax aannleax left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you looks good :)

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in nemo Aug 14, 2026
@aannleax
aannleax merged commit d109c69 into knowsys:main Aug 14, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in nemo Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Out-of-range numeric casts panic or clamp

2 participants