Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Nov 14, 2024
1 parent cb2d1a8 commit c46db3a
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 41 deletions.
52 changes: 50 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

## Unreleased (2024-11-12)
## Unreleased (2024-11-14)

<section class="packages">

Expand Down Expand Up @@ -88,6 +88,40 @@ This release closes the following issue:

<!-- /.package -->

<section class="package" id="math-base-special-bernoulli-unreleased">

#### [@stdlib/math/base/special/bernoulli](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/bernoulli)

<details>

<section class="features">

##### 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)

</section>

<!-- /.features -->

<section class="breaking-changes">

##### 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`.

</section>

<!-- /.breaking-changes -->

</details>

</section>

<!-- /.package -->

<section class="package" id="math-base-special-cfloorf-unreleased">

#### [@stdlib/math/base/special/cfloorf](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cfloorf)
Expand Down Expand Up @@ -204,6 +238,18 @@ This release closes the following issue:

<!-- /.packages -->

<section class="breaking-changes">

### 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`.

</section>

<!-- /.breaking-changes -->

<section class="issues">

### Closed Issues
Expand All @@ -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
Expand All @@ -237,6 +284,7 @@ A total of 4 people contributed to this release. Thank you to the following cont

<details>

- [`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)_
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Prajwal Kulkarni <[email protected]>
Pranav Goswami <[email protected]>
Praneki <[email protected]>
Pratik <[email protected]>
Pratyush Kumar Chouhan <[email protected]>
Priyansh <[email protected]>
Pushpendra Chandravanshi <[email protected]>
RISHAV <[email protected]>
Expand All @@ -79,6 +80,7 @@ Ridam Garg <[email protected]>
Robert Gislason <[email protected]>
Roman Stetsyk <[email protected]>
Rutam <[email protected]>
Ruthwik Chikoti <[email protected]>
Ryan Seal <[email protected]>
Sai Srikar Dumpeti <[email protected]>
SarthakPaandey <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions base/special/bernoulli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions base/special/bernoulli/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand All @@ -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' );
}
Expand Down
8 changes: 4 additions & 4 deletions base/special/bernoulli/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' );
}
Expand Down
9 changes: 6 additions & 3 deletions base/special/bernoulli/benchmark/c/native/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/special/bernoulli/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion base/special/bernoulli/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @example
* var y = bernoulli( 1 );
* // returns 0.0
* // returns 0.5
*
* @example
* var y = bernoulli( 2 );
Expand Down
2 changes: 1 addition & 1 deletion base/special/bernoulli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* // returns 1.0
*
* y = bernoulli( 1 );
* // returns 0.0
* // returns 0.5
*
* y = bernoulli( 2 );
* // returns ~0.166
Expand Down
5 changes: 4 additions & 1 deletion base/special/bernoulli/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion base/special/bernoulli/lib/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 0 additions & 6 deletions base/special/bernoulli/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions base/special/bernoulli/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 13 additions & 7 deletions base/special/bernoulli/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
Expand Down
16 changes: 11 additions & 5 deletions base/special/bernoulli/test/test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();
Expand Down

0 comments on commit c46db3a

Please sign in to comment.