MCPcopy Index your code
hub / github.com/nodejs/node / evenRound

Function evenRound

lib/internal/webidl.js:185–199  ·  view source on GitHub ↗

* Rounds to the nearest integer, choosing the even integer on ties. * @param {number} x Numeric value. * @returns {number}

(x)

Source from the content-addressed store, hash-verified

183 * @returns {number}
184 */
185function 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.

Callers 1

convertToIntFunction · 0.85

Calls 1

integerPartFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…