* Rounds to the nearest integer, choosing the even integer on ties. * @param {number} x Numeric value. * @returns {number}
(x)
| 183 | * @returns {number} |
| 184 | */ |
| 185 | function evenRound(x) { |
| 186 | // Web IDL ConvertToInt step 7.2: round to the nearest integer, |
| 187 | // choosing the even integer on ties and +0 rather than -0. |
| 188 | const i = integerPart(x); |
| 189 | const remainder = MathAbs(x % 1); |
| 190 | const sign = MathSign(x); |
| 191 | if (remainder === 0.5) { |
| 192 | return i % 2 === 0 ? i : i + sign; |
| 193 | } |
| 194 | const r = remainder < 0.5 ? i : i + sign; |
| 195 | if (r === 0) { |
| 196 | return 0; |
| 197 | } |
| 198 | return r; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Returns 2 to the power of the given exponent. |
no test coverage detected
searching dependent graphs…