Skip to content

Commit e164d38

Browse files
committed
fix: use correct f32 emulation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent fb6710e commit e164d38

File tree

11 files changed

+76
-86
lines changed

11 files changed

+76
-86
lines changed

lib/node_modules/@stdlib/math/base/special/expf/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# expf
2222

23-
> Evaluate the natural [exponential function][exponential-function] as a single-precision floating-point number.
23+
> Evaluate the natural [exponential function][exponential-function] for a single-precision floating-point number.
2424
2525
<section class="intro">
2626

@@ -55,7 +55,7 @@ var expf = require( '@stdlib/math/base/special/expf' );
5555

5656
#### expf( x )
5757

58-
Evaluates the natural [exponential function][exponential-function] as a single-precision floating-point number.
58+
Evaluates the natural [exponential function][exponential-function] for a single-precision floating-point number.
5959

6060
```javascript
6161
var v = expf( 4.0 );
@@ -129,7 +129,7 @@ for ( i = 0; i < 100; i++ ) {
129129

130130
#### stdlib_base_expf( x )
131131

132-
Evaluates the natural [exponential function][exponential-function] as a single-precision floating-point number.
132+
Evaluates the natural [exponential function][exponential-function] for a single-precision floating-point number.
133133

134134
```c
135135
float out = stdlib_base_expf( 4.0f );

lib/node_modules/@stdlib/math/base/special/expf/docs/img/equation_natural_exponential_function.svg

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/node_modules/@stdlib/math/base/special/expf/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{{alias}}( x )
33

4-
Evaluates the natural exponential function as
4+
Evaluates the natural exponential function for
55
a single-precision floating-point number.
66

77
Parameters

lib/node_modules/@stdlib/math/base/special/expf/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TypeScript Version: 4.1
2020

2121
/**
22-
* Evaluates the natural exponential function as a single-precision floating-point number.
22+
* Evaluates the natural exponential function for a single-precision floating-point number.
2323
*
2424
* @param x - input value
2525
* @returns function value

lib/node_modules/@stdlib/math/base/special/expf/lib/expmulti.js renamed to lib/node_modules/@stdlib/math/base/special/expf/lib/expmultif.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,59 @@
1818
*
1919
* ## Notice
2020
*
21-
* The following copyrights, licenses, and long comment were part of the original implementation available as part of{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_expf.c?view=markup}, The implementation follows the original, but has been modified for JavaScript.
21+
* The following copyrights, licenses, and long comment were part of the original implementation available as part of{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_expf.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.
2225
*
23-
* e_expf.c -- float version of e_exp.c.
24-
* Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
25-
* ====================================================
26-
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
2726
* Developed at SunPro, a Sun Microsystems, Inc. business.
2827
* Permission to use, copy, modify, and distribute this
2928
* software is freely granted, provided that this notice
3029
* is preserved.
31-
* ====================================================
30+
* ```
3231
*/
3332

3433
'use strict';
3534

3635
// MODULES //
3736

3837
var ldexpf = require( '@stdlib/math/base/special/ldexpf' );
38+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
3939
var polyvalP = require( './polyval_p.js' );
4040

4141

42+
// VARIABLES //
43+
44+
var ONE = f32( 1.0 );
45+
var TWO = f32( 2.0 );
46+
47+
4248
// MAIN //
4349

4450
/**
45-
* Computes \\(e^{r} 2^k\\) where \\(r = \mathrm{hi} - \mathrm{lo}\\) and \\(|r| \leq \ln(2)/2\\).
51+
* Computes \\(e^{r} 2^k\\) for a single-precision floating-point number, where \\(r = \mathrm{hi} - \mathrm{lo}\\) and \\(|r| \leq \ln(2)/2\\).
4652
*
4753
* @private
4854
* @param {number} hi - upper bound
4955
* @param {number} lo - lower bound
5056
* @param {integer} k - power of 2
5157
* @returns {number} function value
5258
*/
53-
function expmulti( hi, lo, k ) {
54-
var twom100;
59+
function expmultif( hi, lo, k ) {
5560
var r;
5661
var t;
5762
var c;
5863
var y;
5964

60-
twom100 = 7.8886090522e-31;
61-
r = hi - lo;
62-
t = r * r;
63-
c = r - ( t*polyvalP( t ) );
64-
y = 1.0 - ( lo - ( (r*c)/(2.0-c) ) - hi );
65-
66-
if ( k >= -125 ) {
67-
return ldexpf( y, k );
68-
}
65+
r = f32( hi - lo );
66+
t = f32( r * r );
67+
c = f32( r - f32( t*polyvalP( t ) ) );
68+
y = f32( ONE - f32( f32( lo - f32( f32(r*c)/f32(TWO-c) ) ) - hi ) );
6969

70-
return ldexpf( y, k + 100 ) * twom100 * twom100;
70+
return ldexpf( y, k );
7171
}
7272

7373

7474
// EXPORTS //
7575

76-
module.exports = expmulti;
76+
module.exports = expmultif;

lib/node_modules/@stdlib/math/base/special/expf/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Evaluate the natural exponential function as a single-precision floating-point number.
22+
* Evaluate the natural exponential function for a single-precision floating-point number.
2323
*
2424
* @module @stdlib/math/base/special/expf
2525
*

lib/node_modules/@stdlib/math/base/special/expf/lib/main.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,47 @@
1818
*
1919
* ## Notice
2020
*
21-
* The following copyrights, licenses, and long comment were part of the original implementation available as part of{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_expf.c?view=markup}, The implementation follows the original, but has been modified for JavaScript.
21+
* The following copyrights, licenses, and long comment were part of the original implementation available as part of{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/e_expf.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.
2225
*
23-
* e_expf.c -- float version of e_exp.c.
24-
* Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
25-
* ====================================================
26-
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
2726
* Developed at SunPro, a Sun Microsystems, Inc. business.
2827
* Permission to use, copy, modify, and distribute this
2928
* software is freely granted, provided that this notice
3029
* is preserved.
31-
* ====================================================
30+
* ```
3231
*/
3332

3433
'use strict';
3534

3635
// MODULES //
3736

38-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
37+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
3938
var truncf = require( '@stdlib/math/base/special/truncf' );
39+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
4040
var NINF = require( '@stdlib/constants/float32/ninf' );
4141
var PINF = require( '@stdlib/constants/float32/pinf' );
42-
var expmulti = require( './expmulti.js' );
42+
var expmultif = require( './expmultif.js' );
4343

4444

4545
// VARIABLES //
4646

47-
var LN2_HI = 6.9314575195e-01;
48-
var LN2_LO = 1.4286067653e-06;
49-
var halF = [ 0.5, -0.5 ];
50-
var INVLN2 = 1.4426950216e+00;
51-
var OVERFLOW = 8.8721679688e+01;
52-
var UNDERFLOW = -1.0397208405e+02;
53-
var NEARZERO = 1.0 / (1 << 14);
54-
var NEG_NEARZERO = -NEARZERO;
47+
var LN2_HI = f32( 6.9314575195e-01 ); // 0x3F317200
48+
var LN2_LO = f32( 1.4286067653e-06 ); // 0x35BFBE8E
49+
var INVLN2 = f32( 1.4426950216e+00 ); // 0x3FB8AA3B
50+
var OVERFLOW = f32( 8.8721679688e+01 ); // 0x42B17180
51+
var UNDERFLOW = f32( -1.0397208405e+02 ); // 0xC2CFF1B5
52+
var NEARZERO = f32( 1.0 / (1 << 14) ); // 0x39000000
53+
var NEG_NEARZERO = f32( -NEARZERO ); // 0xB9000000
54+
var HALF = f32( 0.5 );
55+
var ONE = f32( 1.0 );
5556

5657

5758
// MAIN //
5859

5960
/**
60-
* Evaluates the natural exponential function as a single-precision floating-point number.
61+
* Evaluates the natural exponential function for a single-precision floating-point number.
6162
*
6263
* ## Method
6364
*
@@ -144,11 +145,11 @@ var NEG_NEARZERO = -NEARZERO;
144145
*
145146
* @example
146147
* var v = expf( 4.0 );
147-
* // returns 54.598148345947266
148+
* // returns ~54.5982
148149
*
149150
* @example
150151
* var v = expf( -9.0 );
151-
* // returns 0.00012340980174485594
152+
* // returns ~1.234e-4
152153
*
153154
* @example
154155
* var v = expf( 0.0 );
@@ -159,14 +160,12 @@ var NEG_NEARZERO = -NEARZERO;
159160
* // returns NaN
160161
*/
161162
function expf( x ) {
162-
var xsb;
163163
var hi;
164164
var lo;
165165
var k;
166166

167-
xsb = ( x < 0.0 ) ? 1 : 0;
168-
169-
if ( isnan( x ) || x === PINF ) {
167+
x = f32( x );
168+
if ( isnanf( x ) || x === PINF ) {
170169
return x;
171170
}
172171
if ( x === NINF ) {
@@ -182,15 +181,18 @@ function expf( x ) {
182181
x > NEG_NEARZERO &&
183182
x < NEARZERO
184183
) {
185-
return 1.0 + x;
184+
return f32( ONE + x );
186185
}
187-
// Argument reduction
188-
189-
k = truncf( (INVLN2 * x) + halF[ xsb ] );
190-
hi = x - (k * LN2_HI);
191-
lo = k * LN2_LO;
186+
// Reduce and compute `r = hi - lo` for extra precision...
187+
if ( x < 0.0 ) {
188+
k = truncf( f32( f32( INVLN2*x ) - HALF ) );
189+
} else {
190+
k = truncf( f32( f32( INVLN2*x ) + HALF ) );
191+
}
192+
hi = f32( x - f32( k*LN2_HI ) );
193+
lo = f32( k * LN2_LO );
192194

193-
return expmulti( hi, lo, k );
195+
return expmultif( hi, lo, k );
194196
}
195197

196198

lib/node_modules/@stdlib/math/base/special/expf/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Evaluates the natural exponential function as a single-precision floating-point number.
29+
* Evaluates the natural exponential function for a single-precision floating-point number.
3030
*
3131
* @private
3232
* @param {number} x - input value

lib/node_modules/@stdlib/math/base/special/expf/lib/polyval_p.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
/* This is a generated file. Do not edit directly. */
2020
'use strict';
2121

22+
// MODULES //
23+
24+
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
25+
26+
2227
// MAIN //
2328

2429
/**
@@ -36,9 +41,9 @@
3641
*/
3742
function evalpoly( x ) {
3843
if ( x === 0.0 ) {
39-
return 0.1666662544;
44+
return 0.16666625440120697;
4045
}
41-
return 0.1666662544 + (x * -0.0027667332906);
46+
return float64ToFloat32(0.16666625440120697 + float64ToFloat32(x * -0.0027667332906275988)); // eslint-disable-line max-len
4247
}
4348

4449

lib/node_modules/@stdlib/math/base/special/expf/scripts/evalpoly.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ function main() {
9393
var str;
9494

9595
opts = {
96-
'encoding': 'utf8'
96+
'encoding': 'utf8',
97+
'dtype': 'float32'
9798
};
9899

99100
fpath = resolve( __dirname, '..', 'lib', 'polyval_p.js' );
100-
str = header + compile( P );
101+
str = header + compile( P, opts );
101102
writeFileSync( fpath, str, opts );
102103

103104
copts = {

0 commit comments

Comments
 (0)