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
15 changes: 7 additions & 8 deletions lib/node_modules/@stdlib/math/base/special/bernoulli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,19 @@ for ( i = 0; i < 280; i++ ) {
Computes the nth [Bernoulli number][bernoulli-number].

```c
double out = stdlib_base_bernoulli( 0 );
double out = stdlib_base_bernoulli( 0.0 );
// returns 1.0

out = stdlib_base_bernoulli( 1 );
out = stdlib_base_bernoulli( 1.0 );
// returns 0.5
```

The function accepts the following arguments:

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

```c
double stdlib_base_bernoulli( const int32_t n );
double stdlib_base_bernoulli( const double n );
```

</section>
Expand All @@ -190,15 +190,14 @@ double stdlib_base_bernoulli( const int32_t n );
```c
#include "stdlib/math/base/special/bernoulli.h"
#include <stdio.h>
#include <stdint.h>

int main( void ) {
int32_t i;
double i;
double v;

for ( i = 0; i < 130; i++ ) {
for ( i = 0.0; i < 130.0; i++ ) {
v = stdlib_base_bernoulli( i );
printf( "bernoulli(%d) = %lf\n", i, v );
printf( "bernoulli(%lf) = %lf\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static double benchmark( void ) {

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
y = stdlib_base_bernoulli( (int)( x[ i % 100 ] ) );
y = stdlib_base_bernoulli( ( x[ i % 100 ] ) );
if ( y != y ) {
printf( "should not return NaN\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@

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

int main( void ) {
int32_t i;
double i;
double v;

for ( i = 0; i < 130; i++ ) {
for ( i = 0.0; i < 130.0; i++ ) {
v = stdlib_base_bernoulli( i );
printf( "bernoulli(%d) = %lf\n", i, v );
printf( "bernoulli(%lf) = %lf\n", i, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_BERNOULLI_H
#define STDLIB_MATH_BASE_SPECIAL_BERNOULLI_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" {
/**
* Computes the nth Bernoulli number.
*/
double stdlib_base_bernoulli( const int32_t n );
double stdlib_base_bernoulli( const double n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function bernoulli( n ) {
return 0.0;
}
if ( n > MAX_BERNOULLI ) {
return ( (n/2)&1 ) ? PINF : NINF;
return ( isOdd( n/2.0 ) ) ? PINF : NINF;
}
return BERNOULLI[ n/2 ];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"@stdlib/math/base/napi/unary",
"@stdlib/math/base/assert/is-odd",
"@stdlib/constants/float64/ninf",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf",
"@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
Expand All @@ -55,7 +56,8 @@
"dependencies": [
"@stdlib/math/base/assert/is-odd",
"@stdlib/constants/float64/ninf",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf",
"@stdlib/math/base/assert/is-nonnegative-integer"
]
},
{
Expand All @@ -71,7 +73,8 @@
"dependencies": [
"@stdlib/math/base/assert/is-odd",
"@stdlib/constants/float64/ninf",
"@stdlib/constants/float64/pinf"
"@stdlib/constants/float64/pinf",
"@stdlib/math/base/assert/is-nonnegative-integer"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/bernoulli.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_bernoulli )
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_bernoulli )
15 changes: 9 additions & 6 deletions lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
* limitations under the License.
*/

#include "stdlib/math/base/assert/is_nonnegative_integer.h"
#include "stdlib/math/base/assert/is_odd.h"
#include "stdlib/constants/float64/ninf.h"
#include "stdlib/constants/float64/pinf.h"
#include "stdlib/math/base/special/bernoulli.h"
#include <stdint.h>
#include <stdlib.h>

static const double bernoulli_value[ 130 ] = {
1.00000000000000000000000000000000000000000,
Expand Down Expand Up @@ -164,11 +167,11 @@ int32_t MAX_BERNOULLI = 258;
* @return output value
*
* @example
* double out = stdlib_base_bernoulli( 0 );
* // returns 1
* double out = stdlib_base_bernoulli( 0.0 );
* // returns 1.0
*/
double stdlib_base_bernoulli( const int32_t n ) {
if ( n < 0 ) {
double stdlib_base_bernoulli( const double n ) {
if ( !stdlib_base_is_nonnegative_integer( n ) ) {
return 0.0 / 0.0; // NaN
}
if ( n == 1 ) {
Expand All @@ -178,7 +181,7 @@ double stdlib_base_bernoulli( const int32_t n ) {
return 0.0;
}
if ( n > MAX_BERNOULLI ) {
return ( ( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF;
return ( stdlib_base_is_odd( n/2.0 ) ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF;
}
return bernoulli_value[ n / 2 ];
return bernoulli_value[ (size_t)( n / 2 ) ];
}