toFinite
Is your feature request related to a problem? Please describe.
Converts value to a finite number.
Describe the solution you'd like
toFinite(3.2); // => 3.2
toFinite(Number.MIN_VALUE); // => 5e-324
toFinite(Infinity); // => 1.7976931348623157e+308
toFinite('3.2'); // => 3.2
Possible implementation:
const toFinite = curry1((value) {
if (!value) return value === 0 ? value : 0;
const result = toNumber(value);
if (!isFinite(result)) {
const sign = (value < 0 ? -1 : 1);
return sign * Number.MAX_SAFE_INTEGER;
}
return result === result ? result : 0;
});
Describe alternatives you've considered
--
Additional context
Currently blocked by toNumber issue.
Working on this now, just waiting on #788. Question about the functionality: Should Infinity values return MAX_VALUE /MIN_VALUE or MAX_SAFE_INTEGER/MIN_SAFE_INTEGER? Should all NaN values be converted to the max value, or to 0?
Thanks
Code review for #788 has been provided, will take probably couple of days to merge it. Regarding your questions:
Should Infinity values return MAX_VALUE /MIN_VALUE or MAX_SAFE_INTEGER/MIN_SAFE_INTEGER?
we need to use MAX_VALUE/MIN_VALUE, proof lies in:
Number.isFinite(Number.MAX_VALUE);
isFinite(Number.MAX_VALUE);
Should all NaN values be converted to the max value, or to 0?
to 0 as proposed in possible implementation
@mellero I'd say that https://github.com/char0n/ramda-adjunct/pull/1454 seems like a dead PR (no response from author), so to unblock this issue feel free to issue another PR for #788 and take a look at my code review comments on current PR https://github.com/char0n/ramda-adjunct/pull/1454
Sure I'll get on that asap