Skip to content

Commit a179c6d

Browse files
Resolved coeffiecients in evalpoly
1 parent 8415ab6 commit a179c6d

File tree

6 files changed

+29
-38
lines changed

6 files changed

+29
-38
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ bench( pkg+'::built-in', function benchmark( b ) {
5858
b.tic();
5959
for ( i = 0; i < b.iterations; i++ ) {
6060
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
6262
if ( isnan( y ) ) {
6363
b.fail( 'should not return NaN' );
6464
}
65-
}+
65+
}
6666
b.toc();
6767
if ( isnan( y ) ) {
6868
b.fail( 'should not return NaN' );

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,23 @@ var polyvalP = require( './polyval_p.js' );
5151
* @returns {number} function value
5252
*/
5353
function expmulti( hi, lo, k ) {
54+
var twom100;
5455
var r;
5556
var t;
5657
var c;
5758
var y;
58-
var twom100;
5959

6060
twom100 = 7.8886090522e-31;
6161
r = hi - lo;
6262
t = r * r;
63-
c = r - ( t*polyvalP( t ) );
63+
c = r - ( t*polyvalP( t ) );
6464
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 );
6968
}
69+
70+
return ldexpf( y, k + 100 ) * twom100 * twom100;
7071
}
7172

7273

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,16 @@ var expmulti = require( './expmulti.js' );
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];
47+
var LN2_HI = 6.9314575195e-01;
48+
var LN2_LO = 1.4286067653e-06;
49+
var halF = [ 0.5, -0.5 ];
5050
var INVLN2 = 1.4426950216e+00;
51-
var OVERFLOW = 8.8721679688e+01;
51+
var OVERFLOW = 8.8721679688e+01;
5252
var UNDERFLOW = -1.0397208405e+02;
53-
var NEARZERO = 1.0 / (1 << 14);
53+
var NEARZERO = 1.0 / (1 << 14);
5454
var NEG_NEARZERO = -NEARZERO;
5555

5656

57-
5857
// MAIN //
5958

6059
/**
@@ -145,7 +144,7 @@ var NEG_NEARZERO = -NEARZERO;
145144
*
146145
* @example
147146
* var v = expf( 4.0 );
148-
* // returns ~54.5982
147+
* // returns ~54.598
149148
*
150149
* @example
151150
* var v = expf( -9.0 );
@@ -160,10 +159,10 @@ var NEG_NEARZERO = -NEARZERO;
160159
* // returns NaN
161160
*/
162161
function expf( x ) {
162+
var xsb;
163163
var hi;
164164
var lo;
165165
var k;
166-
var xsb;
167166

168167
xsb = ( x < 0.0 ) ? 1 : 0;
169168

@@ -186,10 +185,10 @@ function expf( x ) {
186185
return 1.0 + x;
187186
}
188187
// 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;
193192

194193
return expmulti( hi, lo, k );
195194
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2022 The Stdlib Authors.
4+
* Copyright (c) 2024 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -35,14 +35,13 @@
3535
* @returns {number} evaluated polynomial
3636
*/
3737
function evalpoly( x ) {
38-
var P1 = 1.6666625440e-1;
39-
var P2 = -2.7667332906e-3;
4038
if ( x === 0.0 ) {
41-
return P1;
39+
return 0.1666662544;
4240
}
43-
return P1 + x*P2 // eslint-disable-line max-len
41+
return 0.1666662544 + (x * -0.0027667332906);
4442
}
4543

44+
4645
// EXPORTS //
4746

4847
module.exports = evalpoly;

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ var compileC = require( '@stdlib/math/base/tools/evalpoly-compile-c' );
3838
// VARIABLES //
3939

4040
// 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
4744
];
4845

4946
// Header to add to output files:

lib/node_modules/@stdlib/math/base/special/expf/src/main.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static const float NEG_NEARZERO = -1.0 / ( 1 << 14 );
5353
// BEGIN: polyval_p
5454

5555
/**
56-
* Evaluates a polynomial for single-precision.
56+
* Evaluates a polynomial.
5757
*
5858
* ## Notes
5959
*
@@ -65,12 +65,7 @@ static const float NEG_NEARZERO = -1.0 / ( 1 << 14 );
6565
* @return evaluated polynomial
6666
*/
6767
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);
7469
}
7570

7671
// END: polyval_p

0 commit comments

Comments
 (0)