diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md b/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md index d1d53aff738..d5d27336a71 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md @@ -43,7 +43,7 @@ var v = bernoulli( 0 ); // returns 1.0 v = bernoulli( 1 ); -// returns 0.0 +// returns 0.5 v = bernoulli( 2 ); // returns ~0.167 @@ -158,7 +158,7 @@ double out = stdlib_base_bernoulli( 0 ); // returns 1.0 out = stdlib_base_bernoulli( 1 ); -// returns 0.0 +// returns 0.5 ``` The function accepts the following arguments: diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.js index 15602454656..8f609f4d53f 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.js @@ -21,8 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var randu = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; var bernoulli = require( './../lib' ); @@ -35,10 +34,11 @@ bench( pkg, function benchmark( b ) { var y; var i; + x = randu( 100, 0, 500 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu()*500.0 ); - y = bernoulli( x ); + y = bernoulli( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.native.js index c66f8ed4360..0f6b8df52be 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/benchmark.native.js @@ -22,8 +22,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var randu = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -44,10 +43,11 @@ bench( pkg+'::native', opts, function benchmark( b ) { var y; var i; + x = randu( 100, 0, 500 ); + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - x = floor( randu() * 500.0 ); - y = bernoulli( x ); + y = bernoulli( x[ i % x.length ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c index 785dc8066d8..7e84c857608 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c @@ -91,15 +91,18 @@ static double rand_double( void ) { */ static double benchmark( void ) { double elapsed; - double x; + double x[ 100 ]; double y; double t; int i; + for ( i = 0; i < 100; i++ ) { + x[ i ] = ( 500.0 * rand_double() ); + } + t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - x = ( 500.0 * rand_double() ); - y = stdlib_base_bernoulli( x ); + y = stdlib_base_bernoulli( (int)( x[ i % 100 ] ) ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/repl.txt b/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/repl.txt index 601f23ecec1..f4b1f1319a4 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/repl.txt +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/repl.txt @@ -21,7 +21,7 @@ > var y = {{alias}}( 0 ) 1.0 > y = {{alias}}( 1 ) - 0.0 + 0.5 > y = {{alias}}( 2 ) ~0.167 > y = {{alias}}( 3 ) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/types/index.d.ts b/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/types/index.d.ts index 07411b6d2e5..d1858c50004 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/docs/types/index.d.ts @@ -30,7 +30,7 @@ * * @example * var y = bernoulli( 1 ); -* // returns 0.0 +* // returns 0.5 * * @example * var y = bernoulli( 2 ); diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/index.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/index.js index bf6d51586b1..b267efd5b7f 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/index.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/index.js @@ -30,7 +30,7 @@ * // returns 1.0 * * y = bernoulli( 1 ); -* // returns 0.0 +* // returns 0.5 * * y = bernoulli( 2 ); * // returns ~0.166 diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js index 46b03b66b4b..cbcacc45500 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js @@ -47,7 +47,7 @@ var MAX_BERNOULLI = 258|0; // asm type annotation * * @example * var y = bernoulli( 1 ); -* // returns 0.0 +* // returns 0.5 * * @example * var y = bernoulli( 2 ); @@ -85,6 +85,9 @@ function bernoulli( n ) { if ( isnan( n ) || !isNonNegativeInteger( n ) ) { return NaN; } + if ( n === 1 ) { + return 0.5; + } if ( isOdd( n ) ) { return 0.0; } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/native.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/native.js index 08d220eb750..42efa0d231e 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/native.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/native.js @@ -37,7 +37,7 @@ var addon = require( './../src/addon.node' ); * * @example * var y = bernoulli( 1 ); -* // returns 0.0 +* // returns 0.5 * * @example * var y = bernoulli( 2 ); diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json b/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json index 0c12d1f3c76..b63457894ac 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json @@ -37,8 +37,6 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/napi/unary", - "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-odd", "@stdlib/constants/float64/ninf", "@stdlib/constants/float64/pinf" @@ -55,8 +53,6 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-odd", "@stdlib/constants/float64/ninf", "@stdlib/constants/float64/pinf" @@ -73,8 +69,6 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/math/base/assert/is-nonnegative-integer", - "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/assert/is-odd", "@stdlib/constants/float64/ninf", "@stdlib/constants/float64/pinf" diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c index 576e74d7b1b..20ba5b75601 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c @@ -16,8 +16,6 @@ * limitations under the License. */ -#include "stdlib/math/base/assert/is_nonnegative_integer.h" -#include "stdlib/math/base/assert/is_nan.h" #include "stdlib/math/base/assert/is_odd.h" #include "stdlib/constants/float64/ninf.h" #include "stdlib/constants/float64/pinf.h" @@ -170,9 +168,12 @@ int32_t MAX_BERNOULLI = 258; * // returns 1 */ double stdlib_base_bernoulli( const int32_t n ) { - if ( stdlib_base_is_nan( n ) || !stdlib_base_is_nonnegative_integer( n ) ) { + if ( n < 0 ) { return 0.0 / 0.0; // NaN } + if ( n == 1 ) { + return 0.5; + } if ( stdlib_base_is_odd( n ) ) { return 0.0; } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.js index c2c678e1537..a5100c1614b 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.js @@ -44,31 +44,37 @@ tape( 'if provided a negative number, the function returns `NaN`', function test var v; var i; - t.strictEqual( isnan( bernoulli( -3.14 ) ), true, 'returns NaN' ); + t.strictEqual( isnan( bernoulli( -3.14 ) ), true, 'returns expected value' ); for ( i = -1; i > -100; i-- ) { v = bernoulli( i ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i ); } t.end(); }); +tape( 'if provided `1`, the function returns `0.5`', function test( t ) { + var v = bernoulli( 1 ); + t.strictEqual( v, 0.5, 'returns expected value' ); + t.end(); +}); + tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) { var v = bernoulli( NaN ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided a NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) { var v = bernoulli( 3.14 ); - t.strictEqual( isnan( v ), true, 'returns NaN' ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); t.end(); }); tape( 'the function returns the nth Bernoulli number for odd numbers', function test( t ) { var v; var i; - for ( i = 1; i < 500; i += 2 ) { + for ( i = 3; i < 500; i += 2 ) { v = bernoulli( i ); // Odd Bernoulli numbers are equal to zero: @@ -93,9 +99,9 @@ tape( 'the function returns +/- infinity for large integers', function test( t ) for ( i = 260; i < 1000; i += 2 ) { v = bernoulli( i ); if ( i % 4 === 0 ) { - t.strictEqual( v, NINF, 'returns negative infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); } else { - t.strictEqual( v, PINF, 'returns positive infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.native.js index 8962a1bacb7..3b8377ca613 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/test/test.native.js @@ -53,19 +53,25 @@ tape( 'if provided a negative number, the function returns `NaN`', opts, functio var v; var i; - t.strictEqual( isnan( bernoulli( -3.14 ) ), true, 'returns NaN' ); + t.strictEqual( isnan( bernoulli( -3.14 ) ), true, 'returns expected value' ); for ( i = -1; i > -100; i-- ) { v = bernoulli( i ); - t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i ); + t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i ); } t.end(); }); +tape( 'if provided `1`, the function returns `0.5`', opts, function test( t ) { + var v = bernoulli( 1 ); + t.strictEqual( v, 0.5, 'returns expected value' ); + t.end(); +}); + tape( 'the function returns the nth Bernoulli number for odd numbers', opts, function test( t ) { var v; var i; - for ( i = 1; i < 500; i += 2 ) { + for ( i = 3; i < 500; i += 2 ) { v = bernoulli( i ); // Odd Bernoulli numbers are equal to zero: @@ -90,9 +96,9 @@ tape( 'the function returns +/- infinity for large integers', opts, function tes for ( i = 260; i < 1000; i += 2 ) { v = bernoulli( i ); if ( i % 4 === 0 ) { - t.strictEqual( v, NINF, 'returns negative infinity' ); + t.strictEqual( v, NINF, 'returns expected value' ); } else { - t.strictEqual( v, PINF, 'returns positive infinity' ); + t.strictEqual( v, PINF, 'returns expected value' ); } } t.end();