Skip to content

fix(runtime): TypedArray element-store coercion (ToUint32 modular) + f16 rounding#4746

Merged
proggeramlug merged 1 commit into
mainfrom
bi-typedarray-parity
Jun 7, 2026
Merged

fix(runtime): TypedArray element-store coercion (ToUint32 modular) + f16 rounding#4746
proggeramlug merged 1 commit into
mainfrom
bi-typedarray-parity

Conversation

@proggeramlug

Copy link
Copy Markdown
Contributor

What

Fixes built-ins/TypedArray (baseline 945/1328, 71.2%) — two element-store coercion bugs, with unit tests.

Root causes

  1. Integer element store saturated instead of wrapping. Storing into Int/Uint typed arrays now uses a spec ToUint32/ToInt8/16/32 computed in f64 space (NaN/±Inf/±0 → 0; truncate toward zero; reduce mod 2³²). The old value as i64 path saturated at i64::MAX, so values past i64::MAX (e.g. 1e21) produced wrong low bits instead of the spec's modular wrap.
  2. Float16 double-rounding. f16 store converted via an intermediate f32, double-rounding at half-ulp boundaries (the smallest f16 subnormal collapsed to 0 instead of 2⁻²⁴). Now converts directly from the f64 mantissa, preserving sticky bits.

Files

typedarray/mod.rs, typedarray_half.rs (+ unit tests)

Delta confirmed by post-merge resweep. (No version/CHANGELOG bump — maintainer folds in.)

…f16 rounding

- Element store for integer kinds now goes through a spec ToUint32/ToInt8/16/32
  computed in f64 space: NaN/Inf/0 -> 0, truncate-toward-zero, reduce mod 2^32.
  The old `value as i64` path saturated at i64::MAX, so values past i64::MAX
  (e.g. 1e21) produced wrong low bits instead of wrapping modularly.
- Float16 store converts directly from the f64 mantissa instead of via an
  intermediate f32, eliminating a double-rounding error at half-ulp boundaries
  (e.g. the smallest f16 subnormal collapsed to 0 instead of 2^-24).
- Added unit tests for both.
@proggeramlug proggeramlug merged commit 3c46cd0 into main Jun 7, 2026
13 checks passed
@proggeramlug proggeramlug deleted the bi-typedarray-parity branch June 7, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant