From c46db3a92d0c4c81563bfcec365d9d6f21f3bf7a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 14 Nov 2024 10:02:18 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 52 ++++++++++++++++++- CONTRIBUTORS | 2 + base/special/bernoulli/README.md | 4 +- base/special/bernoulli/benchmark/benchmark.js | 8 +-- .../bernoulli/benchmark/benchmark.native.js | 8 +-- .../bernoulli/benchmark/c/native/benchmark.c | 9 ++-- base/special/bernoulli/docs/repl.txt | 2 +- base/special/bernoulli/docs/types/index.d.ts | 2 +- base/special/bernoulli/lib/index.js | 2 +- base/special/bernoulli/lib/main.js | 5 +- base/special/bernoulli/lib/native.js | 2 +- base/special/bernoulli/manifest.json | 6 --- base/special/bernoulli/src/main.c | 7 +-- base/special/bernoulli/test/test.js | 20 ++++--- base/special/bernoulli/test/test.native.js | 16 ++++-- 15 files changed, 104 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 645ff669a..3e5a45184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@
-## Unreleased (2024-11-12) +## Unreleased (2024-11-14)
@@ -88,6 +88,40 @@ This release closes the following issue: +
+ +#### [@stdlib/math/base/special/bernoulli](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/bernoulli) + +
+ +
+ +##### Features + +- [`47cfa90`](https://github.com/stdlib-js/stdlib/commit/47cfa907d643a00ac5b3fce9967e655401e110f8) - update the return value for `n=1` in `math/base/special/bernoulli` [(#3108)](https://github.com/stdlib-js/stdlib/pull/3108) + +
+ + + +
+ +##### BREAKING CHANGES + +- [`47cfa90`](https://github.com/stdlib-js/stdlib/commit/47cfa907d643a00ac5b3fce9967e655401e110f8): update return value for `n=1` + + - In order to migrate and preserve prior behavior, users should special case `n=1` and return `0`. The change in this commit aligns return values with SymPy and R; although, other libraries and envs choose to return `-0.5`. + +
+ + + +
+ +
+ + +
#### [@stdlib/math/base/special/cfloorf](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cfloorf) @@ -204,6 +238,18 @@ This release closes the following issue: +
+ +### BREAKING CHANGES + +- [`47cfa90`](https://github.com/stdlib-js/stdlib/commit/47cfa907d643a00ac5b3fce9967e655401e110f8): update return value for `n=1` + + - In order to migrate and preserve prior behavior, users should special case `n=1` and return `0`. The change in this commit aligns return values with SymPy and R; although, other libraries and envs choose to return `-0.5`. + +
+ + +
### Closed Issues @@ -220,9 +266,10 @@ A total of 3 issues were closed in this release: ### Contributors -A total of 4 people contributed to this release. Thank you to the following contributors: +A total of 5 people contributed to this release. Thank you to the following contributors: - Aayush Khanna +- Athan Reines - Gunj Joshi - Gururaj Gurram - Philipp Burckhardt @@ -237,6 +284,7 @@ A total of 4 people contributed to this release. Thank you to the following cont
+- [`47cfa90`](https://github.com/stdlib-js/stdlib/commit/47cfa907d643a00ac5b3fce9967e655401e110f8) - **feat:** update the return value for `n=1` in `math/base/special/bernoulli` [(#3108)](https://github.com/stdlib-js/stdlib/pull/3108) _(by Gunj Joshi, Athan Reines)_ - [`d88cd86`](https://github.com/stdlib-js/stdlib/commit/d88cd86622b7a4ebffcb4b57aa60d5b7292fee73) - **refactor:** use constants, `FI_F` for addon and style fixes in `math/base/special/ldexpf` [(#2868)](https://github.com/stdlib-js/stdlib/pull/2868) _(by Gunj Joshi)_ - [`d9a93be`](https://github.com/stdlib-js/stdlib/commit/d9a93be954f04720bb5b03512be42c9ce6201088) - **feat:** add `math/base/special/croundf` [(#3061)](https://github.com/stdlib-js/stdlib/pull/3061) _(by Gururaj Gurram, Philipp Burckhardt)_ - [`f8bcfd8`](https://github.com/stdlib-js/stdlib/commit/f8bcfd832483d46068c710b6854d5f97bcb778fd) - **feat:** add `math/base/special/gcdf` [(#2997)](https://github.com/stdlib-js/stdlib/pull/2997) _(by Aayush Khanna, Philipp Burckhardt)_ diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c9f811ce0..2024aac10 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -69,6 +69,7 @@ Prajwal Kulkarni Pranav Goswami Praneki <97080887+PraneGIT@users.noreply.github.com> Pratik <97464067+Pratik772846@users.noreply.github.com> +Pratyush Kumar Chouhan Priyansh <88396544+itsspriyansh@users.noreply.github.com> Pushpendra Chandravanshi RISHAV <115060907+rishav2404@users.noreply.github.com> @@ -79,6 +80,7 @@ Ridam Garg <67867319+RidamGarg@users.noreply.github.com> Robert Gislason Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com> Rutam <138517416+performant23@users.noreply.github.com> +Ruthwik Chikoti <145591715+ruthwikchikoti@users.noreply.github.com> Ryan Seal Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com> SarthakPaandey <145528240+SarthakPaandey@users.noreply.github.com> diff --git a/base/special/bernoulli/README.md b/base/special/bernoulli/README.md index d1d53aff7..d5d27336a 100644 --- a/base/special/bernoulli/README.md +++ b/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/base/special/bernoulli/benchmark/benchmark.js b/base/special/bernoulli/benchmark/benchmark.js index 01dbc6922..31aed0070 100644 --- a/base/special/bernoulli/benchmark/benchmark.js +++ b/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( './../../../../base/special/floor' ); +var randu = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( './../../../../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/base/special/bernoulli/benchmark/benchmark.native.js b/base/special/bernoulli/benchmark/benchmark.native.js index 36803379d..67f910d79 100644 --- a/base/special/bernoulli/benchmark/benchmark.native.js +++ b/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( './../../../../base/special/floor' ); +var randu = require( '@stdlib/random/array/discrete-uniform' ); var isnan = require( './../../../../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/base/special/bernoulli/benchmark/c/native/benchmark.c b/base/special/bernoulli/benchmark/c/native/benchmark.c index 785dc8066..7e84c8576 100644 --- a/base/special/bernoulli/benchmark/c/native/benchmark.c +++ b/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/base/special/bernoulli/docs/repl.txt b/base/special/bernoulli/docs/repl.txt index 601f23ece..f4b1f1319 100644 --- a/base/special/bernoulli/docs/repl.txt +++ b/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/base/special/bernoulli/docs/types/index.d.ts b/base/special/bernoulli/docs/types/index.d.ts index 07411b6d2..d1858c500 100644 --- a/base/special/bernoulli/docs/types/index.d.ts +++ b/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/base/special/bernoulli/lib/index.js b/base/special/bernoulli/lib/index.js index bf6d51586..b267efd5b 100644 --- a/base/special/bernoulli/lib/index.js +++ b/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/base/special/bernoulli/lib/main.js b/base/special/bernoulli/lib/main.js index 1728f174e..190c514a9 100644 --- a/base/special/bernoulli/lib/main.js +++ b/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/base/special/bernoulli/lib/native.js b/base/special/bernoulli/lib/native.js index 08d220eb7..42efa0d23 100644 --- a/base/special/bernoulli/lib/native.js +++ b/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/base/special/bernoulli/manifest.json b/base/special/bernoulli/manifest.json index 0c12d1f3c..b63457894 100644 --- a/base/special/bernoulli/manifest.json +++ b/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/base/special/bernoulli/src/main.c b/base/special/bernoulli/src/main.c index 576e74d7b..20ba5b756 100644 --- a/base/special/bernoulli/src/main.c +++ b/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/base/special/bernoulli/test/test.js b/base/special/bernoulli/test/test.js index 13d16477d..0226d11a2 100644 --- a/base/special/bernoulli/test/test.js +++ b/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/base/special/bernoulli/test/test.native.js b/base/special/bernoulli/test/test.native.js index e39e1c518..ce82bf8fa 100644 --- a/base/special/bernoulli/test/test.native.js +++ b/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();