Skip to content

Commit e6bc375

Browse files
committed
refactor: create variable in parent scope and update test messages
1 parent 5633c07 commit e6bc375

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ var polyvalA = require( './polyval_a.js' );
4141
var polyvalB = require( './polyval_b.js' );
4242

4343

44+
// VARIABLES //
45+
46+
var PI2O6 = PI_SQUARED / 6.0;
47+
48+
4449
// MAIN //
4550

4651
/**
@@ -91,7 +96,7 @@ function spence( x ) {
9196
return 0.0;
9297
}
9398
if ( x === 0.0 ) {
94-
return ( PI_SQUARED / 6.0 );
99+
return PI2O6;
95100
}
96101
flg = 0;
97102
if ( x > 2.0 ) {
@@ -109,7 +114,7 @@ function spence( x ) {
109114
}
110115
y = -w * polyvalA( w ) / polyvalB( w );
111116
if ( flg & 1 ) {
112-
y = ( PI_SQUARED/6.0 ) - ( ln( x ) * ln( 1.0-x ) ) - y;
117+
y = PI2O6 - ( ln( x ) * ln( 1.0-x ) ) - y;
113118
}
114119
if ( flg & 2 ) {
115120
z = ln( x );

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "stdlib/constants/float64/pi_squared.h"
3737
#include <stdint.h>
3838

39+
// π^2 / 6
40+
static const double PI2O6 = STDLIB_CONSTANT_FLOAT64_PI_SQUARED / 6.0;
41+
3942
/* Begin auto-generated functions. The following functions are auto-generated. Do not edit directly. */
4043

4144
// BEGIN: polyval_a
@@ -117,7 +120,7 @@ double stdlib_base_spence( const double x ) {
117120
return 0.0;
118121
}
119122
if ( x == 0.0 ) {
120-
return ( STDLIB_CONSTANT_FLOAT64_PI_SQUARED / 6.0 );
123+
return PI2O6;
121124
}
122125
flg = 0;
123126
xc = x;
@@ -136,7 +139,7 @@ double stdlib_base_spence( const double x ) {
136139
}
137140
y = -w * polyval_a( w ) / polyval_b( w );
138141
if ( flg & 1 ) {
139-
y = ( STDLIB_CONSTANT_FLOAT64_PI_SQUARED / 6.0 ) - ( stdlib_base_ln( xc ) * stdlib_base_ln( 1.0 - xc ) ) - y;
142+
y = PI2O6 - ( stdlib_base_ln( xc ) * stdlib_base_ln( 1.0 - xc ) ) - y;
140143
}
141144
if ( flg & 2 ) {
142145
z = stdlib_base_ln( xc );

lib/node_modules/@stdlib/math/base/special/spence/test/test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ tape( 'the function accurately computes the dilogarithm for small positive numbe
5858
v = spence( x[ i ] );
5959
delta = abs( v - expected[ i ] );
6060
tol = 2.0 * EPS * abs( expected[ i ] );
61-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
61+
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
6262
}
6363
t.end();
6464
});
@@ -78,7 +78,7 @@ tape( 'the function accurately computes the dilogarithm for medium positive numb
7878
v = spence( x[ i ] );
7979
delta = abs( v - expected[ i ] );
8080
tol = 2.0 * EPS * abs( expected[ i ] );
81-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
81+
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
8282
}
8383
t.end();
8484
});
@@ -98,7 +98,7 @@ tape( 'the function accurately computes the dilogarithm for large positive numbe
9898
v = spence( x[ i ] );
9999
delta = abs( v - expected[ i ] );
100100
tol = EPS * abs( expected[ i ] );
101-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
101+
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
102102
}
103103
t.end();
104104
});

lib/node_modules/@stdlib/math/base/special/spence/test/test.native.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ tape( 'the function accurately computes the dilogarithm for medium positive numb
8686
for ( i = 0; i < x.length; i++ ) {
8787
v = spence( x[ i ] );
8888
delta = abs( v - expected[ i ] );
89+
90+
// NOTE: the tolerance here is larger than for the JavaScript implementation due to compiler optimizations which may be performed resulting in result divergence. For discussion, see https://github.com/stdlib-js/stdlib/pull/2298#discussion_r1624765205
8991
tol = 8.3 * EPS * abs( expected[ i ] );
90-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
92+
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
9193
}
9294
t.end();
9395
});
@@ -107,7 +109,7 @@ tape( 'the function accurately computes the dilogarithm for large positive numbe
107109
v = spence( x[ i ] );
108110
delta = abs( v - expected[ i ] );
109111
tol = 2.0 * EPS * abs( expected[ i ] );
110-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
112+
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. actual: ' + v + '. expected: ' + expected[ i ] + '. tol: ' + tol + '. Δ: ' + delta + '.' );
111113
}
112114
t.end();
113115
});

0 commit comments

Comments
 (0)