File tree 1 file changed +10
-7
lines changed
lib/node_modules/@stdlib/math/base/special/spencef/lib
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ var polyvalB = require( './polyval_b.js' );
44
44
// VARIABLES //
45
45
46
46
var PI2O6 = f32 ( 1.64493406684822643647 ) ; // π^2 / 6
47
+ var ZERO = f32 ( 0.0 ) ;
48
+ var HALF = f32 ( 0.5 ) ;
49
+ var ONE = f32 ( 1.0 ) ;
47
50
48
51
49
52
// MAIN //
@@ -89,37 +92,37 @@ function spencef( x ) {
89
92
var y ;
90
93
var z ;
91
94
95
+ x = f32 ( x ) ;
92
96
if ( isnanf ( x ) || x < 0.0 ) {
93
97
return NaN ;
94
98
}
95
99
if ( x === 1.0 ) {
96
- return 0.0 ;
100
+ return ZERO ;
97
101
}
98
102
if ( x === 0.0 ) {
99
103
return PI2O6 ;
100
104
}
101
105
flg = 0 ;
102
106
if ( x > 2.0 ) {
103
- x = f32 ( 1.0 / f32 ( x ) ) ;
107
+ x = f32 ( ONE / x ) ;
104
108
flg |= 2 ;
105
109
}
106
110
if ( x > 1.5 ) {
107
- w = f32 ( 1.0 / f32 ( x ) ) - 1.0 ;
111
+ w = f32 ( f32 ( ONE / x ) - ONE ) ;
108
112
flg |= 2 ;
109
113
} else if ( x < 0.5 ) {
110
114
w = f32 ( - x ) ;
111
115
flg |= 1 ;
112
116
} else {
113
- w = f32 ( x ) - 1.0 ;
117
+ w = x - ONE ;
114
118
}
115
-
116
119
y = f32 ( - w * f32 ( f32 ( polyvalA ( w ) ) / f32 ( polyvalB ( w ) ) ) ) ;
117
120
if ( flg & 1 ) {
118
- y = f32 ( PI2O6 - f32 ( lnf ( x ) * lnf ( 1.0 - x ) ) - y ) ;
121
+ y = f32 ( PI2O6 - f32 ( lnf ( x ) * lnf ( ONE - x ) ) - y ) ;
119
122
}
120
123
if ( flg & 2 ) {
121
124
z = lnf ( x ) ;
122
- y = - f32 ( f32 ( 0.5 * z * z ) + y ) ;
125
+ y = - f32 ( f32 ( HALF * z * z ) + y ) ;
123
126
}
124
127
return y ;
125
128
}
You can’t perform that action at this time.
0 commit comments