Skip to content

Commit 2dcd971

Browse files
committed
refactor: update return value for n=1
1 parent aca6ec3 commit 2dcd971

File tree

10 files changed

+35
-25
lines changed

10 files changed

+35
-25
lines changed

lib/node_modules/@stdlib/math/base/special/bernoullif/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var v = bernoullif( 0 );
4343
// returns 1.0
4444

4545
v = bernoullif( 1 );
46-
// returns 0.0
46+
// returns 0.5
4747

4848
v = bernoullif( 2 );
4949
// returns ~0.167
@@ -158,7 +158,7 @@ float out = stdlib_base_bernoullif( 0 );
158158
// returns 1.0
159159

160160
out = stdlib_base_bernoullif( 1 );
161-
// returns 0.0
161+
// returns 0.5
162162
```
163163

164164
The function accepts the following arguments:

lib/node_modules/@stdlib/math/base/special/bernoullif/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
> var y = {{alias}}( 0 )
2323
1.0
2424
> y = {{alias}}( 1 )
25-
0.0
25+
0.5
2626
> y = {{alias}}( 2 )
2727
~0.167
2828
> y = {{alias}}( 3 )

lib/node_modules/@stdlib/math/base/special/bernoullif/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* @example
3232
* var y = bernoullif( 1 );
33-
* // returns 0.0
33+
* // returns 0.5
3434
*
3535
* @example
3636
* var y = bernoullif( 2 );

lib/node_modules/@stdlib/math/base/special/bernoullif/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* // returns 1.0
3131
*
3232
* y = bernoullif( 1 );
33-
* // returns 0.0
33+
* // returns 0.5
3434
*
3535
* y = bernoullif( 2 );
3636
* // returns ~0.166

lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var MAX_BERNOULLI = 62|0; // asm type annotation
4848
*
4949
* @example
5050
* var y = bernoullif( 1 );
51-
* // returns 0.0
51+
* // returns 0.5
5252
*
5353
* @example
5454
* var y = bernoullif( 2 );
@@ -86,6 +86,9 @@ function bernoullif( n ) {
8686
if ( isnanf( n ) || !isNonNegativeInteger( n ) ) {
8787
return NaN;
8888
}
89+
if ( n == 1 ) {
90+
return 0.5;
91+
}
8992
if ( isOdd( n ) ) {
9093
return 0.0;
9194
}

lib/node_modules/@stdlib/math/base/special/bernoullif/lib/native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var addon = require( './../src/addon.node' );
3737
*
3838
* @example
3939
* var y = bernoullif( 1 );
40-
* // returns 0.0
40+
* // returns 0.5
4141
*
4242
* @example
4343
* var y = bernoullif( 2 );

lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/math/base/napi/unary",
40-
"@stdlib/math/base/assert/is-nonnegative-integer",
41-
"@stdlib/math/base/assert/is-nan",
4240
"@stdlib/math/base/assert/is-odd",
4341
"@stdlib/constants/float32/ninf",
4442
"@stdlib/constants/float32/pinf"
@@ -55,8 +53,6 @@
5553
"libraries": [],
5654
"libpath": [],
5755
"dependencies": [
58-
"@stdlib/math/base/assert/is-nonnegative-integer",
59-
"@stdlib/math/base/assert/is-nan",
6056
"@stdlib/math/base/assert/is-odd",
6157
"@stdlib/constants/float32/ninf",
6258
"@stdlib/constants/float32/pinf"
@@ -73,8 +69,6 @@
7369
"libraries": [],
7470
"libpath": [],
7571
"dependencies": [
76-
"@stdlib/math/base/assert/is-nonnegative-integer",
77-
"@stdlib/math/base/assert/is-nan",
7872
"@stdlib/math/base/assert/is-odd",
7973
"@stdlib/constants/float32/ninf",
8074
"@stdlib/constants/float32/pinf"

lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/bernoullif.h"
20-
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
21-
#include "stdlib/math/base/assert/is_nan.h"
2220
#include "stdlib/math/base/assert/is_odd.h"
2321
#include "stdlib/constants/float32/ninf.h"
2422
#include "stdlib/constants/float32/pinf.h"
@@ -72,9 +70,12 @@ static const int32_t MAX_BERNOULLI = 62;
7270
* // returns 1
7371
*/
7472
float stdlib_base_bernoullif( const int32_t n ) {
75-
if ( stdlib_base_is_nan( n ) || !stdlib_base_is_nonnegative_integer( n ) ) {
73+
if ( n < 0 ) {
7674
return 0.0 / 0.0; // NaN
7775
}
76+
if ( n == 1 ) {
77+
return 0.5;
78+
}
7879
if ( stdlib_base_is_odd( n ) ) {
7980
return 0.0;
8081
}

lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,33 @@ tape( 'if provided a negative number, the function returns `NaN`', function test
4949

5050
for ( i = -1; i > -50; i-- ) {
5151
v = bernoullif( i );
52-
t.strictEqual( isnan( v ), true, 'returns NaN when provided ' + i );
52+
t.strictEqual( isnan( v ), true, 'returns expected value when provided ' + i );
5353
}
5454
t.end();
5555
});
5656

57+
tape( 'if provided `1`, the function returns `0.5`', function test( t ) {
58+
var v = bernoullif( 1 );
59+
t.strictEqual( v, 0.5, 'returns expected value' );
60+
t.end();
61+
});
62+
5763
tape( 'if provided `NaN`, the function returns `NaN`', function test( t ) {
5864
var v = bernoullif( NaN );
59-
t.strictEqual( isnan( v ), true, 'returns NaN when provided a NaN' );
65+
t.strictEqual( isnan( v ), true, 'returns expected value' );
6066
t.end();
6167
});
6268

6369
tape( 'if provided a non-integer, the function returns `NaN`', function test( t ) {
6470
var v = bernoullif( 3.14 );
65-
t.strictEqual( isnan( v ), true, 'returns NaN' );
71+
t.strictEqual( isnan( v ), true, 'returns expected value' );
6672
t.end();
6773
});
6874

6975
tape( 'the function returns the nth Bernoulli number for odd numbers', function test( t ) {
7076
var v;
7177
var i;
72-
for ( i = 1; i < 500; i += 2 ) {
78+
for ( i = 3; i < 500; i += 2 ) {
7379
v = bernoullif( i );
7480

7581
// Odd Bernoulli numbers are equal to zero:
@@ -94,9 +100,9 @@ tape( 'the function returns +/- infinity for large integers', function test( t )
94100
for ( i = 64; i < 500; i += 2 ) {
95101
v = bernoullif( i );
96102
if ( i % 4 === 0 ) {
97-
t.strictEqual( v, NINF, 'returns negative infinity' );
103+
t.strictEqual( v, NINF, 'returns expected value' );
98104
} else {
99-
t.strictEqual( v, PINF, 'returns positive infinity' );
105+
t.strictEqual( v, PINF, 'returns expected value' );
100106
}
101107
}
102108
t.end();

lib/node_modules/@stdlib/math/base/special/bernoullif/test/test.native.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ tape( 'if provided a negative number, the function returns `NaN`', opts, functio
6363
t.end();
6464
});
6565

66+
tape( 'if provided `1`, the function returns `0.5`', opts, function test( t ) {
67+
var v = bernoullif( 1 );
68+
t.strictEqual( v, 0.5, 'returns expected value' );
69+
t.end();
70+
});
71+
6672
tape( 'the function returns the nth Bernoulli number for odd numbers', opts, function test( t ) {
6773
var v;
6874
var i;
69-
for ( i = 1; i < 500; i += 2 ) {
75+
for ( i = 3; i < 500; i += 2 ) {
7076
v = bernoullif( i );
7177

7278
// Odd Bernoulli numbers are equal to zero:
@@ -91,9 +97,9 @@ tape( 'the function returns +/- infinity for large integers', opts, function tes
9197
for ( i = 64; i < 500; i += 2 ) {
9298
v = bernoullif( i );
9399
if ( i % 4 === 0 ) {
94-
t.strictEqual( v, NINF, 'returns negative infinity' );
100+
t.strictEqual( v, NINF, 'returns expected value' );
95101
} else {
96-
t.strictEqual( v, PINF, 'returns positive infinity' );
102+
t.strictEqual( v, PINF, 'returns expected value' );
97103
}
98104
}
99105
t.end();

0 commit comments

Comments
 (0)