@stdlib/math-base-special-exp 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -258,8 +258,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
258
258
  [npm-image]: http://img.shields.io/npm/v/@stdlib/math-base-special-exp.svg
259
259
  [npm-url]: https://npmjs.org/package/@stdlib/math-base-special-exp
260
260
 
261
- [test-image]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml/badge.svg?branch=v0.2.2
262
- [test-url]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml?query=branch:v0.2.2
261
+ [test-image]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml/badge.svg?branch=v0.2.4
262
+ [test-url]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml?query=branch:v0.2.4
263
263
 
264
264
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/math-base-special-exp/main.svg
265
265
  [coverage-url]: https://codecov.io/github/stdlib-js/math-base-special-exp?branch=main
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/polyval_p.js", "../lib/expmulti.js", "../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.16666666666666602;\n\t}\n\treturn 0.16666666666666602 + (x * (-0.0027777777777015593 + (x * (0.00006613756321437934 + (x * (-0.0000016533902205465252 + (x * 4.1381367970572385e-8))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyrights, licenses, and long comment were part of the original implementation available as part of [Go]{@link https://github.com/golang/go/blob/cb07765045aed5104a3df31507564ac99e6ddce8/src/math/exp.go}, which in turn was based on an 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.\n*\n* ```text\n* Copyright (c) 2009 The Go Authors. All rights reserved.\n*\n* Redistribution and use in source and binary forms, with or without\n* modification, are permitted provided that the following conditions are\n* met:\n*\n* * Redistributions of source code must retain the above copyright\n* notice, this list of conditions and the following disclaimer.\n* * Redistributions in binary form must reproduce the above\n* copyright notice, this list of conditions and the following disclaimer\n* in the documentation and/or other materials provided with the\n* distribution.\n* * Neither the name of Google Inc. nor the names of its\n* contributors may be used to endorse or promote products derived from\n* this software without specific prior written permission.\n*\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n* \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n* ```\n*\n* ```text\n* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ldexp = require( '@stdlib/math-base-special-ldexp' );\nvar polyvalP = require( './polyval_p.js' );\n\n\n// MAIN //\n\n/**\n* Computes \\\\(e^{r} 2^k\\\\) where \\\\(r = \\mathrm{hi} - \\mathrm{lo}\\\\) and \\\\(|r| \\leq \\ln(2)/2\\\\).\n*\n* @private\n* @param {number} hi - upper bound\n* @param {number} lo - lower bound\n* @param {integer} k - power of 2\n* @returns {number} function value\n*/\nfunction expmulti( hi, lo, k ) {\n\tvar r;\n\tvar t;\n\tvar c;\n\tvar y;\n\n\tr = hi - lo;\n\tt = r * r;\n\tc = r - ( t*polyvalP( t ) );\n\ty = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi);\n\n\treturn ldexp( y, k );\n}\n\n\n// EXPORTS //\n\nmodule.exports = expmulti;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyrights, licenses, and long comment were part of the original implementation available as part of [Go]{@link https://github.com/golang/go/blob/cb07765045aed5104a3df31507564ac99e6ddce8/src/math/exp.go}, which in turn was based on an 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.\n*\n* ```text\n* Copyright (c) 2009 The Go Authors. All rights reserved.\n*\n* Redistribution and use in source and binary forms, with or without\n* modification, are permitted provided that the following conditions are\n* met:\n*\n* * Redistributions of source code must retain the above copyright\n* notice, this list of conditions and the following disclaimer.\n* * Redistributions in binary form must reproduce the above\n* copyright notice, this list of conditions and the following disclaimer\n* in the documentation and/or other materials provided with the\n* distribution.\n* * Neither the name of Google Inc. nor the names of its\n* contributors may be used to endorse or promote products derived from\n* this software without specific prior written permission.\n*\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n* \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n* ```\n*\n* ```text\n* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar trunc = require( '@stdlib/math-base-special-trunc' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar expmulti = require( './expmulti.js' );\n\n\n// VARIABLES //\n\nvar LN2_HI = 6.93147180369123816490e-01;\nvar LN2_LO = 1.90821492927058770002e-10;\nvar LOG2_E = 1.44269504088896338700e+00;\nvar OVERFLOW = 7.09782712893383973096e+02;\nvar UNDERFLOW = -7.45133219101941108420e+02;\nvar NEARZERO = 1.0 / (1 << 28); // 2^-28\nvar NEG_NEARZERO = -NEARZERO;\n\n\n// MAIN //\n\n/**\n* Evaluates the natural exponential function.\n*\n* ## Method\n*\n* 1. We reduce \\\\( x \\\\) to an \\\\( r \\\\) so that \\\\( |r| \\leq 0.5 \\cdot \\ln(2) \\approx 0.34658 \\\\). Given \\\\( x \\\\), we find an \\\\( r \\\\) and integer \\\\( k \\\\) such that\n*\n* ```tex\n* \\begin{align*}\n* x &= k \\cdot \\ln(2) + r \\\\\n* |r| &\\leq 0.5 \\cdot \\ln(2)\n* \\end{align*}\n* ```\n*\n* <!-- <note> -->\n*\n* \\\\( r \\\\) can be represented as \\\\( r = \\mathrm{hi} - \\mathrm{lo} \\\\) for better accuracy.\n*\n* <!-- </note> -->\n*\n* 2. We approximate of \\\\( e^{r} \\\\) by a special rational function on the interval \\\\(\\[0,0.34658]\\\\):\n*\n* ```tex\n* \\begin{align*}\n* R\\left(r^2\\right) &= r \\cdot \\frac{ e^{r}+1 }{ e^{r}-1 } \\\\\n* &= 2 + \\frac{r^2}{6} - \\frac{r^4}{360} + \\ldots\n* \\end{align*}\n* ```\n*\n* We use a special Remes algorithm on \\\\(\\[0,0.34658]\\\\) to generate a polynomial of degree \\\\(5\\\\) to approximate \\\\(R\\\\). The maximum error of this polynomial approximation is bounded by \\\\(2^{-59}\\\\). In other words,\n*\n* ```tex\n* R(z) \\sim 2 + P_1 z + P_2 z^2 + P_3 z^3 + P_4 z^4 + P_5 z^5\n* ```\n*\n* where \\\\( z = r^2 \\\\) and\n*\n* ```tex\n* \\left| 2 + P_1 z + \\ldots + P_5 z^5 - R(z) \\right| \\leq 2^{-59}\n* ```\n*\n* <!-- <note> -->\n*\n* The values of \\\\( P_1 \\\\) to \\\\( P_5 \\\\) are listed in the source code.\n*\n* <!-- </note> -->\n*\n* The computation of \\\\( e^{r} \\\\) thus becomes\n*\n* ```tex\n* \\begin{align*}\n* e^{r} &= 1 + \\frac{2r}{R-r} \\\\\n* &= 1 + r + \\frac{r \\cdot R_1(r)}{2 - R_1(r)}\\ \\text{for better accuracy}\n* \\end{align*}\n* ```\n*\n* where\n*\n* ```tex\n* R_1(r) = r - P_1\\ r^2 + P_2\\ r^4 + \\ldots + P_5\\ r^{10}\n* ```\n*\n* 3. We scale back to obtain \\\\( e^{x} \\\\). From step 1, we have\n*\n* ```tex\n* e^{x} = 2^k e^{r}\n* ```\n*\n* ## Special Cases\n*\n* ```tex\n* \\begin{align*}\n* e^\\infty &= \\infty \\\\\n* e^{-\\infty} &= 0 \\\\\n* e^{\\mathrm{NaN}} &= \\mathrm{NaN} \\\\\n* e^0 &= 1\\ \\mathrm{is\\ exact\\ for\\ finite\\ argument\\ only}\n* \\end{align*}\n* ```\n*\n* ## Notes\n*\n* - According to an error analysis, the error is always less than \\\\(1\\\\) ulp (unit in the last place).\n*\n* - For an IEEE double,\n*\n* - if \\\\(x > 7.09782712893383973096\\mbox{e+}02\\\\), then \\\\(e^{x}\\\\) overflows\n* - if \\\\(x < -7.45133219101941108420\\mbox{e+}02\\\\), then \\\\(e^{x}\\\\) underflows\n*\n* - The hexadecimal values included in the source code are the intended ones for the used constants. Decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the intended hexadecimal values.\n*\n* @param {number} x - input value\n* @returns {number} function value\n*\n* @example\n* var v = exp( 4.0 );\n* // returns ~54.5982\n*\n* @example\n* var v = exp( -9.0 );\n* // returns ~1.234e-4\n*\n* @example\n* var v = exp( 0.0 );\n* // returns 1.0\n*\n* @example\n* var v = exp( NaN );\n* // returns NaN\n*/\nfunction exp( x ) {\n\tvar hi;\n\tvar lo;\n\tvar k;\n\n\tif ( isnan( x ) || x === PINF ) {\n\t\treturn x;\n\t}\n\tif ( x === NINF ) {\n\t\treturn 0.0;\n\t}\n\tif ( x > OVERFLOW ) {\n\t\treturn PINF;\n\t}\n\tif ( x < UNDERFLOW ) {\n\t\treturn 0.0;\n\t}\n\tif (\n\t\tx > NEG_NEARZERO &&\n\t\tx < NEARZERO\n\t) {\n\t\treturn 1.0 + x;\n\t}\n\t// Reduce and compute `r = hi - lo` for extra precision...\n\tif ( x < 0.0 ) {\n\t\tk = trunc( (LOG2_E*x) - 0.5 );\n\t} else {\n\t\tk = trunc( (LOG2_E*x) + 0.5 );\n\t}\n\thi = x - (k*LN2_HI);\n\tlo = k * LN2_LO;\n\n\treturn expmulti( hi, lo, k );\n}\n\n\n// EXPORTS //\n\nmodule.exports = exp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Evaluate the natural exponential function.\n*\n* @module @stdlib/math-base-special-exp\n*\n* @example\n* var exp = require( '@stdlib/math-base-special-exp' );\n*\n* var v = exp( 4.0 );\n* // returns ~54.5982\n*\n* v = exp( -9.0 );\n* // returns ~1.234e-4\n*\n* v = exp( 0.0 );\n* // returns 1.0\n*\n* v = exp( NaN );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n/* This is a generated file. Do not edit directly. */\n'use strict';\n\n// MAIN //\n\n/**\n* Evaluates a polynomial.\n*\n* ## Notes\n*\n* - The implementation uses [Horner's rule][horners-method] for efficient computation.\n*\n* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method\n*\n* @private\n* @param {number} x - value at which to evaluate the polynomial\n* @returns {number} evaluated polynomial\n*/\nfunction evalpoly( x ) {\n\tif ( x === 0.0 ) {\n\t\treturn 0.16666666666666602;\n\t}\n\treturn 0.16666666666666602 + (x * (-0.0027777777777015593 + (x * (0.00006613756321437934 + (x * (-0.0000016533902205465252 + (x * 4.1381367970572385e-8))))))); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = evalpoly;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyrights, licenses, and long comment were part of the original implementation available as part of [Go]{@link https://github.com/golang/go/blob/cb07765045aed5104a3df31507564ac99e6ddce8/src/math/exp.go}, which in turn was based on an 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.\n*\n* ```text\n* Copyright (c) 2009 The Go Authors. All rights reserved.\n*\n* Redistribution and use in source and binary forms, with or without\n* modification, are permitted provided that the following conditions are\n* met:\n*\n* * Redistributions of source code must retain the above copyright\n* notice, this list of conditions and the following disclaimer.\n* * Redistributions in binary form must reproduce the above\n* copyright notice, this list of conditions and the following disclaimer\n* in the documentation and/or other materials provided with the\n* distribution.\n* * Neither the name of Google Inc. nor the names of its\n* contributors may be used to endorse or promote products derived from\n* this software without specific prior written permission.\n*\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n* \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n* ```\n*\n* ```text\n* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar ldexp = require( '@stdlib/math-base-special-ldexp' );\nvar polyvalP = require( './polyval_p.js' );\n\n\n// MAIN //\n\n/**\n* Computes \\\\(e^{r} 2^k\\\\) where \\\\(r = \\mathrm{hi} - \\mathrm{lo}\\\\) and \\\\(|r| \\leq \\ln(2)/2\\\\).\n*\n* @private\n* @param {number} hi - upper bound\n* @param {number} lo - lower bound\n* @param {integer} k - power of 2\n* @returns {number} function value\n*/\nfunction expmulti( hi, lo, k ) {\n\tvar r;\n\tvar t;\n\tvar c;\n\tvar y;\n\n\tr = hi - lo;\n\tt = r * r;\n\tc = r - ( t*polyvalP( t ) );\n\ty = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi );\n\n\treturn ldexp( y, k );\n}\n\n\n// EXPORTS //\n\nmodule.exports = expmulti;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*\n*\n* ## Notice\n*\n* The following copyrights, licenses, and long comment were part of the original implementation available as part of [Go]{@link https://github.com/golang/go/blob/cb07765045aed5104a3df31507564ac99e6ddce8/src/math/exp.go}, which in turn was based on an 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.\n*\n* ```text\n* Copyright (c) 2009 The Go Authors. All rights reserved.\n*\n* Redistribution and use in source and binary forms, with or without\n* modification, are permitted provided that the following conditions are\n* met:\n*\n* * Redistributions of source code must retain the above copyright\n* notice, this list of conditions and the following disclaimer.\n* * Redistributions in binary form must reproduce the above\n* copyright notice, this list of conditions and the following disclaimer\n* in the documentation and/or other materials provided with the\n* distribution.\n* * Neither the name of Google Inc. nor the names of its\n* contributors may be used to endorse or promote products derived from\n* this software without specific prior written permission.\n*\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n* \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n* ```\n*\n* ```text\n* Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved.\n*\n* Developed at SunPro, a Sun Microsystems, Inc. business.\n* Permission to use, copy, modify, and distribute this\n* software is freely granted, provided that this notice\n* is preserved.\n* ```\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar trunc = require( '@stdlib/math-base-special-trunc' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar expmulti = require( './expmulti.js' );\n\n\n// VARIABLES //\n\nvar LN2_HI = 6.93147180369123816490e-01;\nvar LN2_LO = 1.90821492927058770002e-10;\nvar LOG2_E = 1.44269504088896338700e+00;\nvar OVERFLOW = 7.09782712893383973096e+02;\nvar UNDERFLOW = -7.45133219101941108420e+02;\nvar NEARZERO = 1.0 / (1 << 28); // 2^-28\nvar NEG_NEARZERO = -NEARZERO;\n\n\n// MAIN //\n\n/**\n* Evaluates the natural exponential function.\n*\n* ## Method\n*\n* 1. We reduce \\\\( x \\\\) to an \\\\( r \\\\) so that \\\\( |r| \\leq 0.5 \\cdot \\ln(2) \\approx 0.34658 \\\\). Given \\\\( x \\\\), we find an \\\\( r \\\\) and integer \\\\( k \\\\) such that\n*\n* ```tex\n* \\begin{align*}\n* x &= k \\cdot \\ln(2) + r \\\\\n* |r| &\\leq 0.5 \\cdot \\ln(2)\n* \\end{align*}\n* ```\n*\n* <!-- <note> -->\n*\n* \\\\( r \\\\) can be represented as \\\\( r = \\mathrm{hi} - \\mathrm{lo} \\\\) for better accuracy.\n*\n* <!-- </note> -->\n*\n* 2. We approximate of \\\\( e^{r} \\\\) by a special rational function on the interval \\\\(\\[0,0.34658]\\\\):\n*\n* ```tex\n* \\begin{align*}\n* R\\left(r^2\\right) &= r \\cdot \\frac{ e^{r}+1 }{ e^{r}-1 } \\\\\n* &= 2 + \\frac{r^2}{6} - \\frac{r^4}{360} + \\ldots\n* \\end{align*}\n* ```\n*\n* We use a special Remes algorithm on \\\\(\\[0,0.34658]\\\\) to generate a polynomial of degree \\\\(5\\\\) to approximate \\\\(R\\\\). The maximum error of this polynomial approximation is bounded by \\\\(2^{-59}\\\\). In other words,\n*\n* ```tex\n* R(z) \\sim 2 + P_1 z + P_2 z^2 + P_3 z^3 + P_4 z^4 + P_5 z^5\n* ```\n*\n* where \\\\( z = r^2 \\\\) and\n*\n* ```tex\n* \\left| 2 + P_1 z + \\ldots + P_5 z^5 - R(z) \\right| \\leq 2^{-59}\n* ```\n*\n* <!-- <note> -->\n*\n* The values of \\\\( P_1 \\\\) to \\\\( P_5 \\\\) are listed in the source code.\n*\n* <!-- </note> -->\n*\n* The computation of \\\\( e^{r} \\\\) thus becomes\n*\n* ```tex\n* \\begin{align*}\n* e^{r} &= 1 + \\frac{2r}{R-r} \\\\\n* &= 1 + r + \\frac{r \\cdot R_1(r)}{2 - R_1(r)}\\ \\text{for better accuracy}\n* \\end{align*}\n* ```\n*\n* where\n*\n* ```tex\n* R_1(r) = r - P_1\\ r^2 + P_2\\ r^4 + \\ldots + P_5\\ r^{10}\n* ```\n*\n* 3. We scale back to obtain \\\\( e^{x} \\\\). From step 1, we have\n*\n* ```tex\n* e^{x} = 2^k e^{r}\n* ```\n*\n* ## Special Cases\n*\n* ```tex\n* \\begin{align*}\n* e^\\infty &= \\infty \\\\\n* e^{-\\infty} &= 0 \\\\\n* e^{\\mathrm{NaN}} &= \\mathrm{NaN} \\\\\n* e^0 &= 1\\ \\mathrm{is\\ exact\\ for\\ finite\\ argument\\ only}\n* \\end{align*}\n* ```\n*\n* ## Notes\n*\n* - According to an error analysis, the error is always less than \\\\(1\\\\) ulp (unit in the last place).\n*\n* - For an IEEE double,\n*\n* - if \\\\(x > 7.09782712893383973096\\mbox{e+}02\\\\), then \\\\(e^{x}\\\\) overflows\n* - if \\\\(x < -7.45133219101941108420\\mbox{e+}02\\\\), then \\\\(e^{x}\\\\) underflows\n*\n* - The hexadecimal values included in the source code are the intended ones for the used constants. Decimal values may be used, provided that the compiler will convert from decimal to binary accurately enough to produce the intended hexadecimal values.\n*\n* @param {number} x - input value\n* @returns {number} function value\n*\n* @example\n* var v = exp( 4.0 );\n* // returns ~54.5982\n*\n* @example\n* var v = exp( -9.0 );\n* // returns ~1.234e-4\n*\n* @example\n* var v = exp( 0.0 );\n* // returns 1.0\n*\n* @example\n* var v = exp( NaN );\n* // returns NaN\n*/\nfunction exp( x ) {\n\tvar hi;\n\tvar lo;\n\tvar k;\n\n\tif ( isnan( x ) || x === PINF ) {\n\t\treturn x;\n\t}\n\tif ( x === NINF ) {\n\t\treturn 0.0;\n\t}\n\tif ( x > OVERFLOW ) {\n\t\treturn PINF;\n\t}\n\tif ( x < UNDERFLOW ) {\n\t\treturn 0.0;\n\t}\n\tif (\n\t\tx > NEG_NEARZERO &&\n\t\tx < NEARZERO\n\t) {\n\t\treturn 1.0 + x;\n\t}\n\t// Reduce and compute `r = hi - lo` for extra precision...\n\tif ( x < 0.0 ) {\n\t\tk = trunc( (LOG2_E*x) - 0.5 );\n\t} else {\n\t\tk = trunc( (LOG2_E*x) + 0.5 );\n\t}\n\thi = x - (k*LN2_HI);\n\tlo = k * LN2_LO;\n\n\treturn expmulti( hi, lo, k );\n}\n\n\n// EXPORTS //\n\nmodule.exports = exp;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Evaluate the natural exponential function.\n*\n* @module @stdlib/math-base-special-exp\n*\n* @example\n* var exp = require( '@stdlib/math-base-special-exp' );\n*\n* var v = exp( 4.0 );\n* // returns ~54.5982\n*\n* v = exp( -9.0 );\n* // returns ~1.234e-4\n*\n* v = exp( 0.0 );\n* // returns 1.0\n*\n* v = exp( NaN );\n* // returns NaN\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
5
  "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAoCA,SAASC,EAAUC,EAAI,CACtB,OAAKA,IAAM,EACH,mBAED,mBAAuBA,GAAK,sBAA0BA,GAAK,qBAA0BA,GAAK,uBAA6BA,EAAI,wBACnI,CAKAF,EAAO,QAAUC,IC9CjB,IAAAE,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAkEA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAW,IAcf,SAASC,EAAUC,EAAIC,EAAIC,EAAI,CAC9B,IAAIC,EACAC,EACAC,EACAC,EAEJ,OAAAH,EAAIH,EAAKC,EACTG,EAAID,EAAIA,EACRE,EAAIF,EAAMC,EAAEN,EAAUM,CAAE,EACxBE,EAAI,GAAQL,EAAQE,EAAEE,GAAI,EAAIA,GAAOL,GAE9BH,EAAOS,EAAGJ,CAAE,CACpB,CAKAN,EAAO,QAAUG,IClGjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAkEA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAO,QAAS,gCAAiC,EACjDC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IAKXC,EAAS,kBACTC,EAAS,sBACTC,EAAS,mBACTC,EAAW,iBACXC,EAAY,mBACZC,EAAW,GAAO,GAAK,IACvBC,EAAe,CAACD,EAkHpB,SAASE,EAAKC,EAAI,CACjB,IAAIC,EACAC,EACAC,EAEJ,OAAKhB,EAAOa,CAAE,GAAKA,IAAMV,EACjBU,EAEHA,IAAMX,EACH,EAEHW,EAAIL,EACDL,EAEHU,EAAIJ,EACD,EAGPI,EAAIF,GACJE,EAAIH,EAEG,EAAMG,GAGTA,EAAI,EACRG,EAAIf,EAAQM,EAAOM,EAAK,EAAI,EAE5BG,EAAIf,EAAQM,EAAOM,EAAK,EAAI,EAE7BC,EAAKD,EAAKG,EAAEX,EACZU,EAAKC,EAAIV,EAEFF,EAAUU,EAAIC,EAAIC,CAAE,EAC5B,CAKAjB,EAAO,QAAUa,IC9LjB,IAAIK,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_polyval_p", "__commonJSMin", "exports", "module", "evalpoly", "x", "require_expmulti", "__commonJSMin", "exports", "module", "ldexp", "polyvalP", "expmulti", "hi", "lo", "k", "r", "t", "c", "y", "require_main", "__commonJSMin", "exports", "module", "isnan", "trunc", "NINF", "PINF", "expmulti", "LN2_HI", "LN2_LO", "LOG2_E", "OVERFLOW", "UNDERFLOW", "NEARZERO", "NEG_NEARZERO", "exp", "x", "hi", "lo", "k", "main"]
7
7
  }
package/lib/expmulti.js CHANGED
@@ -88,7 +88,7 @@ function expmulti( hi, lo, k ) {
88
88
  r = hi - lo;
89
89
  t = r * r;
90
90
  c = r - ( t*polyvalP( t ) );
91
- y = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi);
91
+ y = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi );
92
92
 
93
93
  return ldexp( y, k );
94
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/math-base-special-exp",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Natural exponential function.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -14,6 +14,7 @@
14
14
  }
15
15
  ],
16
16
  "main": "./lib",
17
+ "gypfile": false,
17
18
  "directories": {
18
19
  "doc": "./docs",
19
20
  "include": "./include",
@@ -33,13 +34,13 @@
33
34
  "url": "https://github.com/stdlib-js/stdlib/issues"
34
35
  },
35
36
  "dependencies": {
36
- "@stdlib/constants-float64-ninf": "^0.2.1",
37
- "@stdlib/constants-float64-pinf": "^0.2.1",
38
- "@stdlib/math-base-assert-is-nan": "^0.2.1",
39
- "@stdlib/math-base-napi-unary": "^0.2.1",
40
- "@stdlib/math-base-special-ldexp": "^0.2.1",
41
- "@stdlib/math-base-special-trunc": "^0.2.1",
42
- "@stdlib/utils-library-manifest": "^0.2.1"
37
+ "@stdlib/constants-float64-ninf": "^0.2.2",
38
+ "@stdlib/constants-float64-pinf": "^0.2.2",
39
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
40
+ "@stdlib/math-base-napi-unary": "^0.2.3",
41
+ "@stdlib/math-base-special-ldexp": "^0.2.3",
42
+ "@stdlib/math-base-special-trunc": "^0.2.2",
43
+ "@stdlib/utils-library-manifest": "^0.2.2"
43
44
  },
44
45
  "devDependencies": {},
45
46
  "engines": {