Skip to content

Commit 5cd396f

Browse files
authored
refactor: use bitwise operation and make casting behavior explicit
PR-URL: #2733 Ref: 06b8011#r144990986 Ref: 06b8011#r144991031 Ref: 06b8011#r144991056 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 8a97c7d commit 5cd396f

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

lib/node_modules/@stdlib/math/base/special/binomcoef/benchmark/c/native/benchmark.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ static double rand_double( void ) {
9191
*/
9292
static double benchmark( void ) {
9393
double elapsed;
94-
double n;
95-
double k;
94+
int64_t n;
95+
int64_t k;
9696
double y;
9797
double t;
9898
int i;

lib/node_modules/@stdlib/math/base/special/binomcoef/manifest.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
"@stdlib/math/base/napi/binary",
4242
"@stdlib/math/base/special/floor",
4343
"@stdlib/math/base/special/gcd",
44-
"@stdlib/math/base/assert/is-odd",
4544
"@stdlib/constants/float64/pinf",
4645
"@stdlib//constants/float64/max-safe-integer"
4746
]
@@ -61,7 +60,6 @@
6160
"dependencies": [
6261
"@stdlib/math/base/special/floor",
6362
"@stdlib/math/base/special/gcd",
64-
"@stdlib/math/base/assert/is-odd",
6563
"@stdlib/constants/float64/pinf",
6664
"@stdlib//constants/float64/max-safe-integer"
6765
]
@@ -81,7 +79,6 @@
8179
"dependencies": [
8280
"@stdlib/math/base/special/floor",
8381
"@stdlib/math/base/special/gcd",
84-
"@stdlib/math/base/assert/is-odd",
8582
"@stdlib/constants/float64/pinf",
8683
"@stdlib//constants/float64/max-safe-integer"
8784
]

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "stdlib/math/base/special/binomcoef.h"
2020
#include "stdlib/math/base/special/floor.h"
2121
#include "stdlib/math/base/special/gcd.h"
22-
#include "stdlib/math/base/assert/is_odd.h"
2322
#include "stdlib/constants/float64/pinf.h"
2423
#include "stdlib//constants/float64/max_safe_integer.h"
2524
#include <stdint.h>
@@ -53,7 +52,7 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) {
5352
nc = n;
5453
if ( nc < 0 ) {
5554
nc = -nc + k - 1;
56-
if ( stdlib_base_is_odd( (double)k ) ) {
55+
if ( k & 1 ) {
5756
sgn *= -1.0;
5857
}
5958
}
@@ -64,7 +63,7 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) {
6463
return sgn;
6564
}
6665
if ( k == 1 || k == nc - 1 ) {
67-
return sgn * nc;
66+
return sgn * (double)nc;
6867
}
6968

7069
// Minimize the number of computed terms by leveraging symmetry:

0 commit comments

Comments
 (0)