Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/bernoullif/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ logEachMap( 'bernoullif(%d) = %0.4f', x, bernoullif );
Computes the nth [Bernoulli number][bernoulli-number] as a single-precision floating-point number.

```c
float out = stdlib_base_bernoullif( 0 );
float out = stdlib_base_bernoullif( 0.0f );
// returns 1.0f

out = stdlib_base_bernoullif( 1 );
out = stdlib_base_bernoullif( 1.0f );
// returns 0.5f
```

The function accepts the following arguments:

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

```c
float stdlib_base_bernoullif( const int32_t n );
float stdlib_base_bernoullif( const float n );
```
</section>
Expand All @@ -192,15 +192,14 @@ float stdlib_base_bernoullif( const int32_t n );
```c
#include "stdlib/math/base/special/bernoullif.h"
#include <stdio.h>
#include <stdint.h>
int main( void ) {
int32_t i;
float i;
float v;
for ( i = 0; i < 70; i++ ) {
for ( i = 0.0f; i < 70.0f; i++ ) {
v = stdlib_base_bernoullif( i );
printf( "bernoullif(%d) = %f\n", i, v );
printf( "bernoullif(%f) = %f\n", i, v );
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "stdlib/math/base/special/bernoullif.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
Expand Down Expand Up @@ -103,7 +102,7 @@ static double benchmark( void ) {

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
y = stdlib_base_bernoullif( (int32_t)( x[ i%100 ] ) );
y = stdlib_base_bernoullif( ( 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/bernoullif.h"
#include <stdio.h>
#include <stdint.h>

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

for ( i = 0; i < 70; i++ ) {
for ( i = 0.0f; i < 70.0f; i++ ) {
v = stdlib_base_bernoullif( i );
printf( "bernoullif(%d) = %f\n", i, v );
printf( "bernoullif(%f) = %f\n", i, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#ifndef STDLIB_MATH_BASE_SPECIAL_BERNOULLIF_H
#define STDLIB_MATH_BASE_SPECIAL_BERNOULLIF_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 as a single-precision floating-point number.
*/
float stdlib_base_bernoullif( const int32_t n );
float stdlib_base_bernoullif( const float n );

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
var isNonNegativeIntegerf = require( '@stdlib/math/base/assert/is-nonnegative-integerf' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var isOdd = require( '@stdlib/math/base/assert/is-odd' );
var isOddf = require( '@stdlib/math/base/assert/is-oddf' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var PINF = require( '@stdlib/constants/float32/pinf' );
var BERNOULLIF = require( './bernoullif.json' );
Expand Down Expand Up @@ -89,11 +89,11 @@ function bernoullif( n ) {
if ( n === 1 ) {
return 0.5;
}
if ( isOdd( n ) ) {
if ( isOddf( n ) ) {
return 0.0;
}
if ( n > MAX_BERNOULLI ) {
return ( (n/2)&1 ) ? PINF : NINF;
return ( isOddf( n/2.0 ) ) ? PINF : NINF;
}
return float64ToFloat32( BERNOULLIF[ n/2 ] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"dependencies": [
"@stdlib/math/base/napi/unary",
"@stdlib/constants/float32/ninf",
"@stdlib/constants/float32/pinf"
"@stdlib/constants/float32/pinf",
"@stdlib/math/base/assert/is-nonnegative-integerf",
"@stdlib/math/base/assert/is-oddf"
]
},
{
Expand All @@ -53,7 +55,9 @@
"libpath": [],
"dependencies": [
"@stdlib/constants/float32/ninf",
"@stdlib/constants/float32/pinf"
"@stdlib/constants/float32/pinf",
"@stdlib/math/base/assert/is-nonnegative-integerf",
"@stdlib/math/base/assert/is-oddf"
]
},
{
Expand All @@ -68,7 +72,9 @@
"libpath": [],
"dependencies": [
"@stdlib/constants/float32/ninf",
"@stdlib/constants/float32/pinf"
"@stdlib/constants/float32/pinf",
"@stdlib/math/base/assert/is-nonnegative-integerf",
"@stdlib/math/base/assert/is-oddf"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#include "stdlib/math/base/special/bernoullif.h"
#include "stdlib/math/base/napi/unary.h"

STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_bernoullif )
STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_bernoullif )
17 changes: 10 additions & 7 deletions lib/node_modules/@stdlib/math/base/special/bernoullif/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_integerf.h"
#include "stdlib/math/base/assert/is_oddf.h"
#include "stdlib/math/base/special/bernoullif.h"
#include "stdlib/constants/float32/ninf.h"
#include "stdlib/constants/float32/pinf.h"
#include <stdint.h>
#include <stdlib.h>

static const float bernoulli_value[ 33 ] = {
1.0f,
Expand Down Expand Up @@ -66,21 +69,21 @@ static const int32_t MAX_BERNOULLI = 64;
* @return output value
*
* @example
* float out = stdlib_base_bernoullif( 0 );
* float out = stdlib_base_bernoullif( 0.0f );
* // returns 1.0f
*/
float stdlib_base_bernoullif( const int32_t n ) {
if ( n < 0 ) {
float stdlib_base_bernoullif( const float n ) {
if ( !stdlib_base_is_nonnegative_integerf( n ) ) {
return 0.0f / 0.0f; // NaN
}
if ( n == 1 ) {
if ( n == 1.0f ) {
return 0.5f;
}
if ( n & 1 ) {
if ( stdlib_base_is_oddf( n ) ) {
return 0.0f;
}
if ( n > MAX_BERNOULLI ) {
return ( ( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF;
return ( stdlib_base_is_oddf( n/2.0f ) ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF;
}
return bernoulli_value[ n / 2 ];
return bernoulli_value[ (size_t)( n / 2.0f ) ];
}