You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
785 B
23 lines
785 B
'use strict';
|
|
var sign = require('../internals/math-sign');
|
|
|
|
var abs = Math.abs;
|
|
|
|
var EPSILON = 2.220446049250313e-16; // Number.EPSILON
|
|
var INVERSE_EPSILON = 1 / EPSILON;
|
|
|
|
var roundTiesToEven = function (n) {
|
|
return n + INVERSE_EPSILON - INVERSE_EPSILON;
|
|
};
|
|
|
|
module.exports = function (x, FLOAT_EPSILON, FLOAT_MAX_VALUE, FLOAT_MIN_VALUE) {
|
|
var n = +x;
|
|
var absolute = abs(n);
|
|
var s = sign(n);
|
|
if (absolute < FLOAT_MIN_VALUE) return s * roundTiesToEven(absolute / FLOAT_MIN_VALUE / FLOAT_EPSILON) * FLOAT_MIN_VALUE * FLOAT_EPSILON;
|
|
var a = (1 + FLOAT_EPSILON / EPSILON) * absolute;
|
|
var result = a - (a - absolute);
|
|
// eslint-disable-next-line no-self-compare -- NaN check
|
|
if (result > FLOAT_MAX_VALUE || result !== result) return s * Infinity;
|
|
return s * result;
|
|
};
|
|
|