Commit bbe8e9a
committed
Fix NaN handling in ttftBucketIndex
The function didn't validate that ttftMs is a finite number. If ttftMs was
NaN, Math.max(NaN, 1) would return NaN, causing Math.log(NaN) to return NaN,
and the entire calculation would produce NaN.
Fixed by:
- Special-casing only Number.isNaN(ttftMs) → 0 (not all non-finite values)
- Letting Infinity flow through the normal path (Math.max/Math.log) which
correctly clamps it to the top bucket via Math.min
- Preserving correct behavior: NaN → bucket 0, ±Infinity → appropriate buckets
Added test coverage for:
- NaN input → bucket 0
- ±Infinity input → appropriate buckets (0 for -Infinity, top for +Infinity)
- Normal values work as before
The existing test suite (11 tests, 995 assertions) passes with this change.
All 12 tests pass now.1 parent 7b65652 commit bbe8e9a
2 files changed
Lines changed: 16 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
73 | 83 | | |
74 | 84 | | |
75 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
| |||
0 commit comments