Extend integer range#116
Conversation
Merging this PR will improve performance by 29.76%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR updates the Float62 NaN-boxing implementation to expand the effective integer handling range and adjusts arithmetic behavior and tests accordingly.
Changes:
- Removes the prior “upgrade to float when integer math overflows / exceeds a limit” path and makes
from_integerdirectly box integers. - Simplifies integer arithmetic by routing
Add/Sub/Multhrough a singleoperate!macro using wrapping operations. - Updates tests to use a larger
INTEGER_LIMIT(1 << 62) and aligns arithmetic reference expectations with wrapping behavior.
Comments suppressed due to low confidence (1)
src/f62.rs:433
- The unit tests currently don't cover the 63-bit integer boundary behavior implied by
box_integer/unbox_integer. Adding explicit assertions around[-2^62, 2^62-1]and out-of-range inputs would catch silent corruption cases likeFloat62::from_integer(1<<62)(which cannot be represented losslessly withinteger<<1).
const INTEGER_LIMIT: i64 = 1 << 62;
#[test]
fn integer() {
assert!(is_integer(box_integer(0)));
assert_eq!(unbox_integer(box_integer(0)), Some(0));
assert_eq!(unbox_integer(box_integer(1)), Some(1));
assert_eq!(unbox_integer(box_integer(-1)), Some(-1));
assert_eq!(unbox_integer(box_integer(42)), Some(42));
assert_eq!(unbox_integer(box_integer(-42)), Some(-42));
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.