Skip to content

Commit 1e76bce

Browse files
committed
refactor: fix 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - 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: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 83ca3ae commit 1e76bce

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

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ var polyvalB = require( './polyval_b.js' );
4444
// VARIABLES //
4545

4646
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 );
4750

4851

4952
// MAIN //
@@ -89,37 +92,37 @@ function spencef( x ) {
8992
var y;
9093
var z;
9194

95+
x = f32( x );
9296
if ( isnanf( x ) || x < 0.0 ) {
9397
return NaN;
9498
}
9599
if ( x === 1.0 ) {
96-
return 0.0;
100+
return ZERO;
97101
}
98102
if ( x === 0.0 ) {
99103
return PI2O6;
100104
}
101105
flg = 0;
102106
if ( x > 2.0 ) {
103-
x = f32( 1.0 / f32( x ) );
107+
x = f32( ONE / x );
104108
flg |= 2;
105109
}
106110
if ( x > 1.5 ) {
107-
w = f32( 1.0 / f32( x ) ) - 1.0;
111+
w = f32( f32( ONE / x ) - ONE );
108112
flg |= 2;
109113
} else if ( x < 0.5 ) {
110114
w = f32( -x );
111115
flg |= 1;
112116
} else {
113-
w = f32( x ) - 1.0;
117+
w = x - ONE;
114118
}
115-
116119
y = f32( -w * f32( f32( polyvalA(w) ) / f32( polyvalB(w) ) ) );
117120
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 );
119122
}
120123
if ( flg & 2 ) {
121124
z = lnf( x );
122-
y = -f32( f32( 0.5*z*z ) + y );
125+
y = -f32( f32( HALF*z*z ) + y );
123126
}
124127
return y;
125128
}

0 commit comments

Comments
 (0)