Repository navigation
fix(value): prevent saturation in ToInt8/ToUint8/ToInt16/ToUint16 for… - #5639
Paraspandey-debugs wants to merge 2 commits into
Conversation
Test262 conformance changes
Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5639 +/- ##
===========================================
+ Coverage 47.24% 63.01% +15.76%
===========================================
Files 476 538 +62
Lines 46892 60589 +13697
===========================================
+ Hits 22154 38179 +16025
+ Misses 24738 22410 -2328 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @Paraspandey-debugs, thanks for working on this! The logic here makes a lot of sense. Reusing Because One small suggestion for the tests: Overall, great cleanup and fix! |
…ues in Uint8Array and Int8Array
|
Thanks @abdulhamid999 I've updated the tests to cover large values, boundary cases, and non-finite inputs (NaN, +∞, -∞). |
Fixes : #5632
Fixed integer conversions for
ToInt8,ToUint8,ToInt16, andToUint16.Previously, these conversions cast
f64toi64before applying modulo. Since Rust'sf64 as i64saturates ati64::MAX/i64::MIN, large values (such as1e20) produced incorrect results.Now, the conversions reuse
f64_to_int32andf64_to_uint32, which correctly handle truncation and modulo 2^32 includingNaN,±0, and±∞. The results are then narrowed usingascasts to preserve the lower 8 or 16 bits.Added tests:
value/tests.rs.typed_array/tests.rs.