@stdlib/math-base-special-bernoullif
v0.1.1
Published
Compute the nth Bernoulli number as a single-precision floating-point number.
Downloads
236
Readme
bernoullif
Compute the nth Bernoulli number as a single-precision floating-point number.
Installation
npm install @stdlib/math-base-special-bernoullifUsage
var bernoullif = require( '@stdlib/math-base-special-bernoullif' );bernoullif( n )
Computes the nth Bernoulli number as a single-precision floating-point number.
var v = bernoullif( 0 );
// returns 1.0
v = bernoullif( 1 );
// returns 0.5
v = bernoullif( 2 );
// returns ~0.167
v = bernoullif( 3 );
// returns 0.0
v = bernoullif( 4 );
// returns ~-0.033
v = bernoullif( 5 );
// returns 0.0
v = bernoullif( 20 );
// returns ~-529.124For even integers n >= 66, the function alternates between returning positive and negative infinity, as larger Bernoulli numbers cannot be safely represented in single-precision floating-point format.
var v = bernoullif( 66 );
// returns Infinity
v = bernoullif( 68 );
// returns -Infinity
v = bernoullif( 70 );
// returns InfinityIf not provided a nonnegative integer value, the function returns NaN.
var v = bernoullif( 3.14 );
// returns NaN
v = bernoullif( -1 );
// returns NaNIf provided NaN, the function returns NaN.
var v = bernoullif( NaN );
// returns NaNExamples
var logEachMap = require( '@stdlib/console-log-each-map' );
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var bernoullif = require( '@stdlib/math-base-special-bernoullif' );
var x = discreteUniform( 100, 0, 70, {
'dtype': 'int32'
});
logEachMap( 'bernoullif(%d) = %0.4f', x, bernoullif );C APIs
Usage
#include "stdlib/math/base/special/bernoullif.h"stdlib_base_bernoullif( n )
Computes the nth Bernoulli number as a single-precision floating-point number.
float out = stdlib_base_bernoullif( 0.0f );
// returns 1.0f
out = stdlib_base_bernoullif( 1.0f );
// returns 0.5fThe function accepts the following arguments:
- n:
[in] floatinput value.
float stdlib_base_bernoullif( const float n );Examples
#include "stdlib/math/base/special/bernoullif.h"
#include <stdio.h>
int main( void ) {
float i;
float v;
for ( i = 0.0f; i < 70.0f; i++ ) {
v = stdlib_base_bernoullif( i );
printf( "bernoullif(%f) = %f\n", i, v );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
