Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dc36e99

Browse filesBrowse files
committed
refactor: remove redundant f32 conversions
--- 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 26cd960 commit dc36e99
Copy full SHA for dc36e99

File tree

Expand file treeCollapse file tree

1 file changed

+16
-16
lines changed
Filter options
  • lib/node_modules/@stdlib/math/base/special/binomcoeff/lib
Expand file treeCollapse file tree

1 file changed

+16
-16
lines changed

‎lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/main.js

Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/math/base/special/binomcoeff/lib/main.js
+16-16Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
var MAX_SAFE_INTEGER = require( '@stdlib/constants/float32/max-safe-integer' );
2424
var PINF = require( '@stdlib/constants/float32/pinf' );
25-
var isIntegerf = require( '@stdlib/math/base/assert/is-integer' );
26-
var isnanf = require( '@stdlib/math/base/assert/is-nan' );
27-
var isOddf = require( '@stdlib/math/base/assert/is-odd' );
25+
var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var isOddf = require( '@stdlib/math/base/assert/is-oddf' );
2828
var floorf = require( '@stdlib/math/base/special/floorf' );
2929
var gcdf = require( '@stdlib/math/base/special/gcdf' );
3030
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
@@ -78,23 +78,23 @@ function binomcoeff( n, k ) {
7878
return NaN;
7979
}
8080
if ( k < 0 ) {
81-
return float64ToFloat32( 0.0 );
81+
return 0.0;
8282
}
8383
sgn = float64ToFloat32( 1.0 );
8484
if ( n < 0 ) {
8585
n = -n + k - 1;
8686
if ( isOddf( k ) ) {
87-
sgn *= float64ToFloat32( -1.0 );
87+
sgn = float64ToFloat32( sgn * -1.0 );
8888
}
8989
}
9090
if ( k > n ) {
91-
return float64ToFloat32( 0.0 );
91+
return 0.0;
9292
}
9393
if ( k === 0 || k === n ) {
94-
return float64ToFloat32( sgn );
94+
return sgn;
9595
}
9696
if ( k === 1 || k === n - 1 ) {
97-
return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(n) );
97+
return float64ToFloat32( sgn * n );
9898
}
9999
// Minimize the number of computed terms by leveraging symmetry:
100100
if ( n - k < k ) {
@@ -109,13 +109,13 @@ function binomcoeff( n, k ) {
109109
if ( res > s ) {
110110
break;
111111
}
112-
res *= float64ToFloat32( n );
113-
res /= float64ToFloat32( d );
112+
res = float64ToFloat32( res * n );
113+
res = float64ToFloat32( res / d );
114114
n -= 1;
115115
}
116116
// If we did not early exit from the previous loop, the answer is exact, and we can simply return...
117117
if ( d > k ) {
118-
return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(res) );
118+
return float64ToFloat32( sgn * res );
119119
}
120120
/*
121121
* Let `N` equal the provided `n`.
@@ -135,7 +135,7 @@ function binomcoeff( n, k ) {
135135
*/
136136
b = binomcoeff( n, k-d+1 );
137137
if ( b === PINF ) {
138-
return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(b) );
138+
return float64ToFloat32( sgn * float64ToFloat32( b ) );
139139
}
140140
c = binomcoeff( k, k-d+1 );
141141

@@ -145,10 +145,10 @@ function binomcoeff( n, k ) {
145145
* To help guard against overflow and precision loss, we calculate the greatest common divisor (gcdf). In this case, we pick `b`, as `b` should be less than `res` in most (if not all) cases.
146146
*/
147147
g = gcdf( b, c );
148-
b /= g;
149-
c /= g;
150-
res /= c;
151-
return float64ToFloat32( float64ToFloat32(sgn) * float64ToFloat32(res) * float64ToFloat32(b) );
148+
b = float64ToFloat32( b / g );
149+
c = float64ToFloat32( c / g );
150+
res = float64ToFloat32( res / c );
151+
return float64ToFloat32( sgn * res * b );
152152
}
153153

154154

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.