README.md (2414B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Bernoulli 22 23 > Compute the nth [Bernoulli number][bernoulli-number]. 24 25 <section class="intro"> 26 27 <!-- /.intro --> 28 29 <section class="usage"> 30 31 ## Usage 32 33 ```javascript 34 var bernoulli = require( '@stdlib/math/base/special/bernoulli' ); 35 ``` 36 37 #### bernoulli( n ) 38 39 Computes the nth [Bernoulli number][bernoulli-number]. 40 41 ```javascript 42 var v = bernoulli( 0 ); 43 // returns 1.0 44 45 v = bernoulli( 1 ); 46 // returns 0.0 47 48 v = bernoulli( 2 ); 49 // returns ~0.167 50 51 v = bernoulli( 3 ); 52 // returns 0.0 53 54 v = bernoulli( 4 ); 55 // returns ~-0.033 56 57 v = bernoulli( 5 ); 58 // returns 0.0 59 60 v = bernoulli( 20 ); 61 // returns ~-529.124 62 ``` 63 64 For even integers `n >= 260`, the function alternates between returning positive and negative infinity, as larger [Bernoulli numbers][bernoulli-number] cannot be safely represented in [double-precision floating-point format][ieee754]. 65 66 ```javascript 67 var v = bernoulli( 260 ); 68 // returns -Infinity 69 70 v = bernoulli( 262 ); 71 // returns Infinity 72 73 v = bernoulli( 264 ); 74 // returns -Infinity 75 ``` 76 77 If not provided a nonnegative integer value, the function returns `NaN`. 78 79 ```javascript 80 var v = bernoulli( 3.14 ); 81 // returns NaN 82 83 v = bernoulli( -1 ); 84 // returns NaN 85 ``` 86 87 If provided `NaN`, the function returns `NaN`. 88 89 ```javascript 90 var v = bernoulli( NaN ); 91 // returns NaN 92 ``` 93 94 </section> 95 96 <!-- /.usage --> 97 98 <section class="notes"> 99 100 </section> 101 102 <!-- /.notes --> 103 104 <section class="examples"> 105 106 ## Examples 107 108 <!-- eslint no-undef: "error" --> 109 110 ```javascript 111 var bernoulli = require( '@stdlib/math/base/special/bernoulli' ); 112 113 var v; 114 var i; 115 116 for ( i = 0; i < 280; i++ ) { 117 v = bernoulli( i ); 118 console.log( v ); 119 } 120 ``` 121 122 </section> 123 124 <!-- /.examples --> 125 126 <section class="links"> 127 128 [bernoulli-number]: https://en.wikipedia.org/wiki/Bernoulli_number 129 130 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985 131 132 </section> 133 134 <!-- /.links -->