File tree Expand file tree Collapse file tree 6 files changed +29
-38
lines changed
lib/node_modules/@stdlib/math/base/special/expf Expand file tree Collapse file tree 6 files changed +29
-38
lines changed Original file line number Diff line number Diff line change @@ -58,11 +58,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
58
58
b . tic ( ) ;
59
59
for ( i = 0 ; i < b . iterations ; i ++ ) {
60
60
x = ( randu ( ) * 100.0 ) - 50.0 ;
61
- y = Math . expf ( x ) ; // eslint-disable-line stdlib/no-builtin-math
61
+ y = Math . exp ( x ) ; // eslint-disable-line stdlib/no-builtin-math
62
62
if ( isnan ( y ) ) {
63
63
b . fail ( 'should not return NaN' ) ;
64
64
}
65
- } +
65
+ }
66
66
b . toc ( ) ;
67
67
if ( isnan ( y ) ) {
68
68
b . fail ( 'should not return NaN' ) ;
Original file line number Diff line number Diff line change @@ -51,22 +51,23 @@ var polyvalP = require( './polyval_p.js' );
51
51
* @returns {number } function value
52
52
*/
53
53
function expmulti ( hi , lo , k ) {
54
+ var twom100 ;
54
55
var r ;
55
56
var t ;
56
57
var c ;
57
58
var y ;
58
- var twom100 ;
59
59
60
60
twom100 = 7.8886090522e-31 ;
61
61
r = hi - lo ;
62
62
t = r * r ;
63
- c = r - ( t * polyvalP ( t ) ) ;
63
+ c = r - ( t * polyvalP ( t ) ) ;
64
64
y = 1.0 - ( lo - ( ( r * c ) / ( 2.0 - c ) ) - hi ) ;
65
- if ( k >= - 125 ) {
66
- return ldexpf ( y , k ) ;
67
- } else {
68
- return ldexpf ( y , k + 100 ) * twom100 * twom100 ;
65
+
66
+ if ( k >= - 125 ) {
67
+ return ldexpf ( y , k ) ;
69
68
}
69
+
70
+ return ldexpf ( y , k + 100 ) * twom100 * twom100 ;
70
71
}
71
72
72
73
Original file line number Diff line number Diff line change @@ -44,17 +44,16 @@ var expmulti = require( './expmulti.js' );
44
44
45
45
// VARIABLES //
46
46
47
- var LN2_HI = 6.9314575195e-01 ;
48
- var LN2_LO = 1.4286067653e-06 ;
49
- var halF = [ 0.5 , - 0.5 ] ;
47
+ var LN2_HI = 6.9314575195e-01 ;
48
+ var LN2_LO = 1.4286067653e-06 ;
49
+ var halF = [ 0.5 , - 0.5 ] ;
50
50
var INVLN2 = 1.4426950216e+00 ;
51
- var OVERFLOW = 8.8721679688e+01 ;
51
+ var OVERFLOW = 8.8721679688e+01 ;
52
52
var UNDERFLOW = - 1.0397208405e+02 ;
53
- var NEARZERO = 1.0 / ( 1 << 14 ) ;
53
+ var NEARZERO = 1.0 / ( 1 << 14 ) ;
54
54
var NEG_NEARZERO = - NEARZERO ;
55
55
56
56
57
-
58
57
// MAIN //
59
58
60
59
/**
@@ -145,7 +144,7 @@ var NEG_NEARZERO = -NEARZERO;
145
144
*
146
145
* @example
147
146
* var v = expf( 4.0 );
148
- * // returns ~54.5982
147
+ * // returns ~54.598
149
148
*
150
149
* @example
151
150
* var v = expf( -9.0 );
@@ -160,10 +159,10 @@ var NEG_NEARZERO = -NEARZERO;
160
159
* // returns NaN
161
160
*/
162
161
function expf ( x ) {
162
+ var xsb ;
163
163
var hi ;
164
164
var lo ;
165
165
var k ;
166
- var xsb ;
167
166
168
167
xsb = ( x < 0.0 ) ? 1 : 0 ;
169
168
@@ -186,10 +185,10 @@ function expf( x ) {
186
185
return 1.0 + x ;
187
186
}
188
187
// Argument reduction
189
-
190
- k = truncf ( INVLN2 * x + halF [ xsb ] ) ;
191
- hi = x - k * LN2_HI ;
192
- lo = k * LN2_LO ;
188
+
189
+ k = truncf ( ( INVLN2 * x ) + halF [ xsb ] ) ;
190
+ hi = x - ( k * LN2_HI ) ;
191
+ lo = k * LN2_LO ;
193
192
194
193
return expmulti ( hi , lo , k ) ;
195
194
}
Original file line number Diff line number Diff line change 1
1
/**
2
2
* @license Apache-2.0
3
3
*
4
- * Copyright (c) 2022 The Stdlib Authors.
4
+ * Copyright (c) 2024 The Stdlib Authors.
5
5
*
6
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
7
* you may not use this file except in compliance with the License.
35
35
* @returns {number } evaluated polynomial
36
36
*/
37
37
function evalpoly ( x ) {
38
- var P1 = 1.6666625440e-1 ;
39
- var P2 = - 2.7667332906e-3 ;
40
38
if ( x === 0.0 ) {
41
- return P1 ;
39
+ return 0.1666662544 ;
42
40
}
43
- return P1 + x * P2 // eslint-disable-line max-len
41
+ return 0.1666662544 + ( x * - 0.0027667332906 ) ;
44
42
}
45
43
44
+
46
45
// EXPORTS //
47
46
48
47
module . exports = evalpoly ;
Original file line number Diff line number Diff line change @@ -38,12 +38,9 @@ var compileC = require( '@stdlib/math/base/tools/evalpoly-compile-c' );
38
38
// VARIABLES //
39
39
40
40
// Polynomial coefficients ordered in ascending degree...
41
- const P = [
42
- 1.6666667163e-01 , // Approximation of 1/6!
43
- - 2.7777778450e-03 , // Approximation of 1/45!
44
- 6.6137559770e-05 , // Approximation of 1/5040!
45
- - 1.6533901999e-06 , // Approximation of 1/362880!
46
- 4.1381369442e-08 // Approximation of 1/39916800!
41
+ var P = [
42
+ 1.6666625440e-1 ,
43
+ - 2.7667332906e-3
47
44
] ;
48
45
49
46
// Header to add to output files:
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ static const float NEG_NEARZERO = -1.0 / ( 1 << 14 );
53
53
// BEGIN: polyval_p
54
54
55
55
/**
56
- * Evaluates a polynomial for single-precision .
56
+ * Evaluates a polynomial.
57
57
*
58
58
* ## Notes
59
59
*
@@ -65,12 +65,7 @@ static const float NEG_NEARZERO = -1.0 / ( 1 << 14 );
65
65
* @return evaluated polynomial
66
66
*/
67
67
static float polyval_p ( const float x ) {
68
- static const float P1 = 1.6666625440e-1 ;
69
- static const float P2 = -2.7667332906e-3 ;
70
- if ( x == 0.0 ) {
71
- return P1 ;
72
- }
73
- return P1 + x * P2 ;
68
+ return 0.1666662544f + (x * -0.0027667332906f );
74
69
}
75
70
76
71
// END: polyval_p
You can’t perform that action at this time.
0 commit comments