( a: Interval | IntervalResult, b: Interval | IntervalResult )
| 989 | * (`right` when the value at the jump matches the value just above it), so this |
| 990 | * is correct for every tie rule (`RoundingTies`): with `to-even`, the jump at |
| 991 | * `0.5` is continuous from the left and the jump at `1.5` from the right. |
| 992 | */ |
| 993 | function roundStep( |
| 994 | x: Interval, |
| 995 | pointRound: (n: number) => number |
| 996 | ): IntervalResult { |
| 997 | if (isNaNInterval(x)) return ok(NAN_INTERVAL); |
| 998 | const rlo = pointRound(x.lo); |
| 999 | const rhi = pointRound(x.hi); |
| 1000 | if (rlo === rhi) return ok({ lo: rlo, hi: rhi }); |
| 1001 | const at = rlo + 0.5; |
| 1002 | return jump(at, pointRound(at) === rlo + 1 ? 'right' : 'left', { |
| 1003 | lo: Math.min(rlo, rhi), |
| 1004 | hi: Math.max(rlo, rhi), |
| 1005 | }); |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * Round to the nearest integer. A value halfway between two integers is |
| 1010 | * rounded with the rule `ties` (`roundToInteger()` in `numeric.ts`). The |
| 1011 | * compiled code of `Round` passes the rule of `ce.roundingTies` at compile |
| 1012 | * time; the default, away from zero, matches the default of the interpreter |
| 1013 | * (Round(-2.5) = -3, Round(2.5) = 3). |
| 1014 | * |
| 1015 | * Round is a step function with jump discontinuities at every half-integer |
| 1016 | * (±0.5, ±1.5, …); an interval that stays within one step returns that |
no test coverage detected