main.js (1569B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2018 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 'use strict'; 20 21 // MODULES // 22 23 var expm1 = require( './../../../../base/special/expm1' ); 24 var abs = require( './../../../../base/special/abs' ); 25 var EPS = require( '@stdlib/constants/float64/eps' ); 26 var PINF = require( '@stdlib/constants/float64/pinf' ); 27 28 29 // VARIABLES // 30 31 var OVERFLOW_THRESHOLD = 7.09782712893383973096e+02; // 0x40862E42 0xFEFA39EF 32 33 34 // MAIN // 35 36 /** 37 * Computes the relative error exponential. 38 * 39 * @param {number} x - input value 40 * @returns {number} function value 41 * 42 * @example 43 * var v = expm1rel( 0.0 ); 44 * // returns 1.0 45 * 46 * @example 47 * var v = expm1rel( 1.0 ); 48 * // returns ~1.718 49 * 50 * @example 51 * var v = expm1rel( -1.0 ); 52 * // returns ~0.632 53 * 54 * @example 55 * var v = expm1rel( NaN ); 56 * // returns NaN 57 */ 58 function expm1rel( x ) { 59 if ( abs( x ) <= EPS ) { 60 return 1.0; // L'Hopital's Rule 61 } 62 if ( x >= OVERFLOW_THRESHOLD ) { 63 return PINF; // L'Hopital's Rule 64 } 65 return expm1( x ) / x; 66 } 67 68 69 // EXPORTS // 70 71 module.exports = expm1rel;