Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/factorial2f/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ logEachMap( 'factorial2f(%d) = %0.1f', x, factorial2f );
Evaluates the [double factorial][double-factorial] of `n` as a single-precision floating-point number.

```c
float out = stdlib_base_factorial2f( 3 );
float out = stdlib_base_factorial2f( 3.0f );
// returns 3.0f
```

The function accepts the following arguments:

- **n**: `[in] int32_t` input value.
- **n**: `[in] float` input value.

```c
float stdlib_base_factorial2f( const int32_t n );
float stdlib_base_factorial2f( const float n );
```

</section>
Expand All @@ -169,16 +169,15 @@ float stdlib_base_factorial2f( const int32_t n );
```c
#include "stdlib/math/base/special/factorial2f.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
const int32_t x[] = { 1, 10, 50, 56, 57 };
const float x[] = { 1.0f, 10.0f, 50.0f, 56.0f, 57.0f };

float b;
int i;
for ( i = 0; i < 5; i++ ) {
b = stdlib_base_factorial2f( x[ i ] );
printf ( "factorial2f(%d) = %f\n", x[ i ], b );
printf ( "factorial2f(%f) = %f\n", x[ i ], b );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ static float rand_float( void ) {
* @return elapsed time in seconds
*/
static double benchmark( void ) {
int32_t x[ 100 ];
float x[ 100 ];
double elapsed;
double t;
float y;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = (int32_t)( 56*rand_float() );
x[ i ] = roundf( 56.0f * rand_float() );
}

t = tic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

#include "stdlib/math/base/special/factorial2f.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
const int32_t x[] = { 1, 10, 50, 56, 57 };
const float x[] = { 1.0f, 10.0f, 50.0f, 56.0f, 57.0f };

float b;
int i;
for ( i = 0; i < 5; i++ ) {
b = stdlib_base_factorial2f( x[ i ] );
printf ( "factorial2f(%d) = %f\n", x[ i ], b );
printf ( "factorial2f(%lf) = %f\n", x[ i ], b );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_FACTORIAL2F_H
#define STDLIB_MATH_BASE_SPECIAL_FACTORIAL2F_H

#include <stdint.h>

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -31,7 +29,7 @@ extern "C" {
/**
* Evaluates the double factorial of `n` as a single-precision floating-point number.
*/
float stdlib_base_factorial2f( const int32_t n );
float stdlib_base_factorial2f( const float n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );
var isNonnegativeIntegerf = require( '@stdlib/math/base/assert/is-nonnegative-integerf' );
var isEvenf = require( '@stdlib/math/base/assert/is-evenf' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var PINF = require( '@stdlib/constants/float32/pinf' );
Expand Down Expand Up @@ -62,15 +62,12 @@ function factorial2f( n ) {
var v;
var i;

if ( isnanf( n ) ) {
if ( isnanf( n ) || !isNonnegativeIntegerf( n ) ) {
return NaN;
}
if ( n > FLOAT32_MAX_NTH_DOUBLE_FACTORIAL ) {
return PINF;
}
if ( n < 0 || isIntegerf( n ) === false ) {
return NaN;
}
v = n|0; // asm type annotation
if ( v === 0|0 || v === 1|0 ) {
return 1|0; // asm type annotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
"libpath": [],
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/int32-is-even",
"@stdlib/math/base/assert/is-evenf",
"@stdlib/constants/float32/pinf",
"@stdlib/constants/float32/max-nth-double-factorial"
"@stdlib/constants/float32/max-nth-double-factorial",
"@stdlib/math/base/assert/is-nonnegative-integerf"
]
},
{
Expand All @@ -53,9 +54,10 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/int32-is-even",
"@stdlib/math/base/assert/is-evenf",
"@stdlib/constants/float32/pinf",
"@stdlib/constants/float32/max-nth-double-factorial"
"@stdlib/constants/float32/max-nth-double-factorial",
"@stdlib/math/base/assert/is-nonnegative-integerf"
]
},
{
Expand All @@ -69,9 +71,10 @@
"libraries": [],
"libpath": [],
"dependencies": [
"@stdlib/math/base/assert/int32-is-even",
"@stdlib/math/base/assert/is-evenf",
"@stdlib/constants/float32/pinf",
"@stdlib/constants/float32/max-nth-double-factorial"
"@stdlib/constants/float32/max-nth-double-factorial",
"@stdlib/math/base/assert/is-nonnegative-integerf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/factorial2f.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_factorial2f )
STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_factorial2f )
30 changes: 15 additions & 15 deletions lib/node_modules/@stdlib/math/base/special/factorial2f/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,42 @@
*/

#include "stdlib/math/base/special/factorial2f.h"
#include "stdlib/math/base/assert/int32_is_even.h"
#include "stdlib/math/base/assert/is_evenf.h"
#include "stdlib/constants/float32/pinf.h"
#include "stdlib/constants/float32/max_nth_double_factorial.h"
#include <stdint.h>
#include "stdlib/math/base/assert/is_nonnegative_integerf.h"

/**
* Evaluates the double factorial of `n` as a single-precision floating-point number.
*
* @param x input value
* @param n input value
* @return double factorial
*
* @example
* float v = stdlib_base_factorial2f( 3 );
* float v = stdlib_base_factorial2f( 3.0f );
* // returns 3.0f
*/
float stdlib_base_factorial2f( const int32_t n ) {
int32_t last;
int32_t i;
float stdlib_base_factorial2f( const float n ) {
float last;
float out;
float i;

if ( !stdlib_base_is_nonnegative_integerf( n ) ) {
return 0.0f / 0.0f; // NaN
}
if ( n > STDLIB_CONSTANT_FLOAT32_MAX_NTH_DOUBLE_FACTORIAL ) {
return STDLIB_CONSTANT_FLOAT32_PINF;
}
if ( n < 0 ) {
return 0.0f / 0.0f; // NaN
}
if ( n == 0 || n == 1 ) {
if ( n == 0.0f || n == 1.0f ) {
return 1.0f;
}
if ( stdlib_base_int32_is_even( n ) ) {
last = 2;
if ( stdlib_base_is_evenf( n ) ) {
last = 2.0f;
} else {
last = 3;
last = 3.0f;
}
out = 1.0f;
for ( i = n; i >= last; i -= 2 ) {
for ( i = n; i >= last; i -= 2.0f ) {
out *= i;
}
return out;
Expand Down