@stdlib/math-base-special-exp 0.2.3 → 0.2.5
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/NOTICE +1 -1
- package/README.md +13 -13
- package/dist/index.js.map +1 -1
- package/lib/expmulti.js +1 -1
- package/manifest.json +24 -1
- package/package.json +8 -8
- package/src/addon.c +0 -1
- package/src/main.c +1 -1
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -101,16 +101,16 @@ v = exp( NaN );
|
|
|
101
101
|
<!-- eslint no-undef: "error" -->
|
|
102
102
|
|
|
103
103
|
```javascript
|
|
104
|
-
var
|
|
104
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
105
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
105
106
|
var exp = require( '@stdlib/math-base-special-exp' );
|
|
106
107
|
|
|
107
|
-
var
|
|
108
|
-
|
|
108
|
+
var opts = {
|
|
109
|
+
'dtype': 'float64'
|
|
110
|
+
};
|
|
111
|
+
var x = uniform( 100, -50.0, 50.0, opts );
|
|
109
112
|
|
|
110
|
-
|
|
111
|
-
x = (randu()*100.0) - 50.0;
|
|
112
|
-
console.log( 'e^%d = %d', x, exp( x ) );
|
|
113
|
-
}
|
|
113
|
+
logEachMap( 'e^%0.4f = %0.4f', x, exp );
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
</section>
|
|
@@ -190,7 +190,7 @@ int main( void ) {
|
|
|
190
190
|
double x;
|
|
191
191
|
double v;
|
|
192
192
|
int i;
|
|
193
|
-
|
|
193
|
+
|
|
194
194
|
for ( i = 0; i < 100; i++ ) {
|
|
195
195
|
x = ( (double)rand() / (double)RAND_MAX ) * 100.0;
|
|
196
196
|
v = stdlib_base_exp( x );
|
|
@@ -245,7 +245,7 @@ For more information on the project, filing bug reports and feature requests, an
|
|
|
245
245
|
|
|
246
246
|
## Copyright
|
|
247
247
|
|
|
248
|
-
Copyright © 2016-
|
|
248
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
249
249
|
|
|
250
250
|
</section>
|
|
251
251
|
|
|
@@ -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.
|
|
262
|
-
[test-url]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml?query=branch:v0.2.
|
|
261
|
+
[test-image]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml/badge.svg?branch=v0.2.5
|
|
262
|
+
[test-url]: https://github.com/stdlib-js/math-base-special-exp/actions/workflows/test.yml?query=branch:v0.2.5
|
|
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
|
|
@@ -271,8 +271,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
271
271
|
|
|
272
272
|
-->
|
|
273
273
|
|
|
274
|
-
[chat-image]: https://img.shields.io/
|
|
275
|
-
[chat-url]: https://
|
|
274
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
275
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
276
276
|
|
|
277
277
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
278
278
|
|
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
package/manifest.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"options": {
|
|
3
|
-
"task": "build"
|
|
3
|
+
"task": "build",
|
|
4
|
+
"wasm": false
|
|
4
5
|
},
|
|
5
6
|
"fields": [
|
|
6
7
|
{
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
"confs": [
|
|
28
29
|
{
|
|
29
30
|
"task": "build",
|
|
31
|
+
"wasm": false,
|
|
30
32
|
"src": [
|
|
31
33
|
"./src/main.c"
|
|
32
34
|
],
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
},
|
|
47
49
|
{
|
|
48
50
|
"task": "benchmark",
|
|
51
|
+
"wasm": false,
|
|
49
52
|
"src": [
|
|
50
53
|
"./src/main.c"
|
|
51
54
|
],
|
|
@@ -64,6 +67,26 @@
|
|
|
64
67
|
},
|
|
65
68
|
{
|
|
66
69
|
"task": "examples",
|
|
70
|
+
"wasm": false,
|
|
71
|
+
"src": [
|
|
72
|
+
"./src/main.c"
|
|
73
|
+
],
|
|
74
|
+
"include": [
|
|
75
|
+
"./include"
|
|
76
|
+
],
|
|
77
|
+
"libraries": [],
|
|
78
|
+
"libpath": [],
|
|
79
|
+
"dependencies": [
|
|
80
|
+
"@stdlib/math-base-assert-is-nan",
|
|
81
|
+
"@stdlib/constants-float64-ninf",
|
|
82
|
+
"@stdlib/constants-float64-pinf",
|
|
83
|
+
"@stdlib/math-base-special-trunc",
|
|
84
|
+
"@stdlib/math-base-special-ldexp"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"task": "build",
|
|
89
|
+
"wasm": true,
|
|
67
90
|
"src": [
|
|
68
91
|
"./src/main.c"
|
|
69
92
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/math-base-special-exp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Natural exponential function.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@stdlib/constants-float64-ninf": "^0.2.
|
|
38
|
-
"@stdlib/constants-float64-pinf": "^0.2.
|
|
39
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
40
|
-
"@stdlib/math-base-napi-unary": "^0.2.
|
|
41
|
-
"@stdlib/math-base-special-ldexp": "^0.2.
|
|
42
|
-
"@stdlib/math-base-special-trunc": "^0.2.
|
|
43
|
-
"@stdlib/utils-library-manifest": "^0.2.
|
|
37
|
+
"@stdlib/constants-float64-ninf": "^0.2.3",
|
|
38
|
+
"@stdlib/constants-float64-pinf": "^0.2.3",
|
|
39
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.3",
|
|
40
|
+
"@stdlib/math-base-napi-unary": "^0.2.7",
|
|
41
|
+
"@stdlib/math-base-special-ldexp": "^0.2.4",
|
|
42
|
+
"@stdlib/math-base-special-trunc": "^0.2.3",
|
|
43
|
+
"@stdlib/utils-library-manifest": "^0.2.4"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {},
|
|
46
46
|
"engines": {
|
package/src/addon.c
CHANGED
package/src/main.c
CHANGED
|
@@ -214,7 +214,7 @@ static double expmulti( const double hi, const double lo, const int32_t k ) {
|
|
|
214
214
|
* - 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.
|
|
215
215
|
*
|
|
216
216
|
* @param x input value
|
|
217
|
-
* @return
|
|
217
|
+
* @return output value
|
|
218
218
|
*
|
|
219
219
|
* @example
|
|
220
220
|
* double out = stdlib_base_exp( 0.0 );
|