locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
14 lines (13 loc) • 550 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.expm1 = expm1;
function expm1(x) {
// discuss at: https://locutus.io/php/expm1/
// parity verified: PHP 8.3
// original by: Brett Zamir (https://brett-zamir.me)
// improved by: Robert Eisele (https://www.xarg.org/)
// note 1: Precision 'n' can be adjusted as desired
// example 1: expm1(1e-15)
// returns 1: 1.0000000000000007e-15
return x < 1e-5 && x > -1e-5 ? x + 0.5 * x * x : Math.exp(x) - 1;
}