| 82 | export function nextUp(x: number): number { |
| 83 | if (x !== x) return x; |
| 84 | if (x === -1 / 0) return -Number.MAX_VALUE; |
| 85 | if (x === 1 / 0) return +1 / 0; |
| 86 | if (x === Number.MAX_VALUE) return +1 / 0; |
| 87 | let y = x * (x < 0 ? 1 - Number.EPSILON / 2 : 1 + Number.EPSILON); |
| 88 | if (y === x) |
| 89 | y = |
| 90 | Number.MIN_VALUE * Number.EPSILON > 0 |
| 91 | ? x + Number.MIN_VALUE * Number.EPSILON |
| 92 | : x + Number.MIN_VALUE; |
| 93 | if (y === +1 / 0) y = +Number.MAX_VALUE; |
| 94 | const b = x + (y - x) / 2; |
| 95 | if (x < b && b < y) y = b; |
| 96 | const c = (y + x) / 2; |
| 97 | if (x < c && c < y) y = c; |
| 98 | return y === 0 ? -0 : y; |
| 99 | } |
| 100 | |
| 101 | export function nextDown(x: number): number { |
| 102 | return -nextUp(-x); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Whether `Round` of a value exactly halfway between two integers (a tie) |
| 107 | * takes the integer that is farther from zero. |
| 108 | * |
| 109 | * The two candidates are the truncated value `t` (the integer nearer to |
| 110 | * zero) and the integer one step farther from zero. `negative` is the sign |