Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav <[email protected]>
  • Loading branch information
Pranavchiku authored Mar 15, 2024
1 parent 88ee382 commit 39f133d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ for ( i = 0; i < values.length; i++ ) {
#include "stdlib/math/base/special/factorial2.h"
```

#### stdlib_base_factorial2( x )
#### stdlib_base_factorial2( n )

Evaluates the [double factorial][double-factorial] of `n`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bench( pkg+'::native', opts, function benchmark( b ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = factorial2(i % 301);
y = factorial2( i % 301 );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ double rand_double() {
*/
double benchmark() {
double elapsed;
double x;
int32_t x;
double y;
double t;
int i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

int main( void ) {
const int32_t x[] = { 1, 10, 1, 301, 302 };

double b;
int i;

for ( i = 0; i < 5; i++ ){
b = stdlib_base_factorial2( x[ i ] );
printf ( "factorial2(%d) = %lf\n", x[ i ], b );
Expand Down
42 changes: 21 additions & 21 deletions lib/node_modules/@stdlib/math/base/special/factorial2/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@
* // returns ~3
*/
double stdlib_base_factorial2(const int32_t n) {
int last;
double out;
int v;
int i;
if ( stdlib_base_is_nan( n ) ){
int32_t last;
double out;
int32_t v;
int32_t i;
if ( stdlib_base_is_nan( n ) ){
return 0.0/0.0; // NaN
}
if (n >= MAX_FACTORIAL2 ){
return STDLIB_CONSTANT_FLOAT64_PINF;
}
if ( n < 0 || !stdlib_base_is_integer( n )) {
return 0.0/0.0;
}
v = n;
if (v == 0 || v == 1) {
return 1;
}
if (stdlib_base_is_even( v )) {
last = 2;
} else {
last = 3;
}
out = 1;
for (i = v; i >= last; i -= 2) {
out *= i;
}
return out;
return 0.0/0.0;
}
v = n;
if (v == 0 || v == 1) {
return 1;
}
if (stdlib_base_is_even( v )) {
last = 2;
} else {
last = 3;
}
out = 1;
for (i = v; i >= last; i -= 2) {
out *= i;
}
return out;
}

0 comments on commit 39f133d

Please sign in to comment.