Commit cc729e8
lib: fix
`evenRound` derived the rounding direction from `MathSign(i)` where
`i = integerPart(x)`. For any `x` whose truncated integer part is zero
(e.g. `0.7`, `-0.7`), `sign` was `0`, so the non-halfway branch returned
`i + sign === 0` instead of rounding away from zero. This produced
incorrect `[Clamp]` WebIDL integer conversions for fractional inputs in
`(-1, 0) ∪ (0, 1)` that are not exactly `±0.5`, observable e.g. via
`new Blob([Uint8Array.of(1,2,3)]).slice(-0.9999999)` returning the whole
blob instead of a 1-byte slice. Use `MathSign(x)` so the rounding
direction follows the sign of the original value.
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: DeepView Autofix <276251120+deepview-autofix@users.noreply.github.com>
Co-Authored-By: Nikita Skovoroda <chalkerx@gmail.com>
Signed-off-by: Nikita Skovoroda <chalkerx@gmail.com>evenRound sign for fractional values in (-1, 1)1 parent 14e16db commit cc729e8
2 files changed
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
| |||
0 commit comments