feat: add math/base/special/bernoullif#3037
Conversation
| @@ -0,0 +1,34 @@ | |||
| [ | |||
| 1.00000000000000000000000000000000000000000, | |||
There was a problem hiding this comment.
These values all have very high precision. Is there a reason for that?
There was a problem hiding this comment.
No, I have used similar values as of math/base/special/bernoulli. Should I make it less precise?
There was a problem hiding this comment.
No, I have used similar values as of math/base/special/bernoulli. Should I make it less precise?
Yes, @gururaj1512.
You'll have to keep these values in appropriate precision. You can use https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/number/float64/base/to-float32 for the conversion.
Co-authored-by: Athan <kgryte@gmail.com> Signed-off-by: Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com>
|
@gunjjoshi This is not a problem exclusively with this PR, since it also applies to |
|
@Planeshifter Thanks for catching this. After digging for some time, I found that there is a mix of opinions on whether Overall, I think, it would be better if we too, use |
|
But yes, NIST prescribes the convention to use |
|
Let's go ahead and use 1/2. This will match SymPy and is also used as a convention in R. As commented elsewhere, how much the choice actually matters in practice is subject to some debate. In this case, I'm more inclined to go with Knuth. |
|
Similar to the changes proposed in #3108, we'll want to make similar changes here. |
…lli` BREAKING CHANGE: 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`. PR-URL: #3108 Ref: #3037 (comment) Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Gunj Joshi <gunjjoshi8372@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
|
Refactored it as suggested. |
|
/stdlib merge |
|
|
||
| // MODULES // | ||
|
|
||
| var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); |
There was a problem hiding this comment.
| var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); | |
| var isNonNegativeIntegerf = require( '@stdlib/math/base/assert/is-nonnegative-integerf' ); |
| return 0.0; | ||
| } | ||
| if ( n > MAX_BERNOULLI ) { | ||
| return ( ( n / 2 ) & 1 ) ? PINF : NINF; |
There was a problem hiding this comment.
| return ( ( n / 2 ) & 1 ) ? PINF : NINF; | |
| return ( (n/2)&1 ) ? PINF : NINF; |
|
|
||
| var bernoullif = require( './../lib' ); | ||
|
|
||
| var v; | ||
| var i; | ||
|
|
||
| for ( i = 0; i < 70; i++ ) { | ||
| v = bernoullif( i ); | ||
| console.log( v ); | ||
| } |
There was a problem hiding this comment.
| var bernoullif = require( './../lib' ); | |
| var v; | |
| var i; | |
| for ( i = 0; i < 70; i++ ) { | |
| v = bernoullif( i ); | |
| console.log( v ); | |
| } | |
| var logEachMap = require( '@stdlib/console/log-each-map' ); | |
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | |
| var bernoullif = require( './../lib' ); | |
| var x = discreteUniform( 100, 0, 70, { | |
| 'dtype': 'int32' | |
| }); | |
| logEachMap( 'bernoullif(%d) = %0.4f', x, bernoullif ); |
|
|
||
| for ( i = 0; i < 70; i++ ) { | ||
| v = stdlib_base_bernoullif( i ); | ||
| printf( "bernoulli(%d) = %f\n", i, v ); |
There was a problem hiding this comment.
| printf( "bernoulli(%d) = %f\n", i, v ); | |
| printf( "bernoullif(%d) = %f\n", i, v ); |
|
|
||
| for ( i = -1; i > -50; i-- ) { | ||
| v = bernoullif( i ); | ||
| t.strictEqual( isnanf( v ), true, 'returns expected value when provided ' + i ); |
There was a problem hiding this comment.
| t.strictEqual( isnanf( v ), true, 'returns expected value when provided ' + i ); | |
| t.strictEqual( isnanf( v ), true, 'returns expected value' ); |
Applies here and below...
| tape( 'the function returns the nth Bernoulli number for odd numbers', function test( t ) { | ||
| var v; | ||
| var i; | ||
| for ( i = 3; i < 500; i += 2 ) { |
There was a problem hiding this comment.
| for ( i = 3; i < 500; i += 2 ) { | |
| for ( i = 3; i < 100; i += 2 ) { |
A smaller range is ok for bernoullif
| tape( 'the function returns +/- infinity for large integers', function test( t ) { | ||
| var v; | ||
| var i; | ||
| for ( i = 66; i < 500; i += 2 ) { |
There was a problem hiding this comment.
| for ( i = 66; i < 500; i += 2 ) { | |
| for ( i = 66; i < 150; i += 2 ) { |
Same comment.
| // MODULES // | ||
|
|
||
| var bench = require( '@stdlib/bench' ); | ||
| var randu = require( '@stdlib/random/array/discrete-uniform' ); |
There was a problem hiding this comment.
| var randu = require( '@stdlib/random/array/discrete-uniform' ); | |
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
For being consistent across other packages.
| var y; | ||
| var i; | ||
|
|
||
| x = randu( 100, 0, 500 ); |
There was a problem hiding this comment.
| x = randu( 100, 0, 500 ); | |
| x = discreteUniform( 100, 0, 100 ); |
100 is fine here for the max value.
| int i; | ||
|
|
||
| for ( i = 0; i < 100; i++ ) { | ||
| x[ i ] = ( 500.0 * rand_float() ); |
There was a problem hiding this comment.
| x[ i ] = ( 500.0 * rand_float() ); | |
| x[ i ] = ( 500.0f * rand_float() ); |
|
|
||
| t = tic(); | ||
| for ( i = 0; i < ITERATIONS; i++ ) { | ||
| y = stdlib_base_bernoullif( (int)( x[ i % 100 ] ) ); |
There was a problem hiding this comment.
| y = stdlib_base_bernoullif( (int)( x[ i % 100 ] ) ); | |
| y = stdlib_base_bernoullif( (int32_t)( x[ i%100 ] ) ); |
| "libraries": [], | ||
| "libpath": [], | ||
| "dependencies": [ | ||
| "@stdlib/math/base/assert/is-odd", |
There was a problem hiding this comment.
@stdlib/math/base/assert/is-odd is not needed here now.
| "stdmath", | ||
| "mathematics", | ||
| "math", | ||
| "special functions", |
There was a problem hiding this comment.
| "special functions", |
Keywords with more than one word are not used.
| var bernoullif = require( '@stdlib/math/base/special/bernoullif' ); | ||
|
|
||
| var v; | ||
| var i; | ||
|
|
||
| for ( i = 0; i < 70; i++ ) { | ||
| v = bernoullif( i ); | ||
| console.log( v ); | ||
| } |
There was a problem hiding this comment.
| var bernoullif = require( '@stdlib/math/base/special/bernoullif' ); | |
| var v; | |
| var i; | |
| for ( i = 0; i < 70; i++ ) { | |
| v = bernoullif( i ); | |
| console.log( v ); | |
| } | |
| var logEachMap = require( '@stdlib/console/log-each-map' ); | |
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | |
| var bernoullif = require( './../lib' ); | |
| var x = discreteUniform( 100, 0, 70, { | |
| 'dtype': 'int32' | |
| }); | |
| logEachMap( 'bernoullif(%d) = %0.4f', x, bernoullif ); |
|
|
||
| ```c | ||
| float out = stdlib_base_bernoullif( 0 ); | ||
| // returns 1.0 |
There was a problem hiding this comment.
| // returns 1.0 | |
| // returns 1.0f |
| // returns 1.0 | ||
|
|
||
| out = stdlib_base_bernoullif( 1 ); | ||
| // returns 0.5 |
There was a problem hiding this comment.
| // returns 0.5 | |
| // returns 0.5f |
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: passed
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: passed
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: passed
- task: lint_c_examples
status: passed
- task: lint_c_benchmarks
status: passed
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
Progresses #649
Description
math/base/special/bernoullif, which would be the single-precision equivalent for math/base/special/bernoullif.Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers