Skip to content

Commit

Permalink
refactor: use int64_t, check last bit, cast to double
Browse files Browse the repository at this point in the history
  • Loading branch information
gunjjoshi committed Aug 3, 2024
1 parent 759e667 commit 3c8e991
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double n;
double k;
int64_t n;
int64_t k;
double y;
double t;
int i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) {
nc = n;
if ( nc < 0 ) {
nc = -nc + k - 1;
if ( stdlib_base_is_odd( (double)k ) ) {
if ( k & 1 ) {
sgn *= -1.0;
}
}
Expand All @@ -64,7 +64,7 @@ double stdlib_base_binomcoef( const int64_t n, const int64_t k ) {
return sgn;
}
if ( k == 1 || k == nc - 1 ) {
return sgn * nc;
return sgn * (double)nc;
}

// Minimize the number of computed terms by leveraging symmetry:
Expand Down

0 comments on commit 3c8e991

Please sign in to comment.