expmulti.js (1827B)
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 * ## Notice 20 * 21 * The following copyright, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/e_exp.c}. The implementation follows the original, but has been modified for JavaScript. 22 * 23 * ```text 24 * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. 25 * 26 * Developed at SunPro, a Sun Microsystems, Inc. business. 27 * Permission to use, copy, modify, and distribute this 28 * software is freely granted, provided that this notice 29 * is preserved. 30 * ``` 31 */ 32 33 'use strict'; 34 35 // MODULES // 36 37 var ldexp = require( './../../../../base/special/ldexp' ); 38 var polyvalP = require( './polyval_p.js' ); 39 40 41 // MAIN // 42 43 /** 44 * Computes \\(e^{r} 2^k\\) where \\(r = \mathrm{hi} - \mathrm{lo}\\) and \\(|r| \leq \ln(2)/2\\). 45 * 46 * @private 47 * @param {number} hi - upper bound 48 * @param {number} lo - lower bound 49 * @param {integer} k - power of 2 50 * @returns {number} function value 51 */ 52 function expmulti( hi, lo, k ) { 53 var r; 54 var t; 55 var c; 56 var y; 57 58 r = hi - lo; 59 t = r * r; 60 c = r - ( t*polyvalP( t ) ); 61 y = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi); 62 63 return ldexp( y, k ); 64 } 65 66 67 // EXPORTS // 68 69 module.exports = expmulti;