File tree Expand file tree Collapse file tree 8 files changed +30
-28
lines changed
lib/node_modules/@stdlib/math/base/special/bernoulli
include/stdlib/math/base/special Expand file tree Collapse file tree 8 files changed +30
-28
lines changed Original file line number Diff line number Diff line change @@ -154,19 +154,19 @@ for ( i = 0; i < 280; i++ ) {
154
154
Computes the nth [ Bernoulli number] [ bernoulli-number ] .
155
155
156
156
``` c
157
- double out = stdlib_base_bernoulli( 0 );
157
+ double out = stdlib_base_bernoulli( 0.0 );
158
158
// returns 1.0
159
159
160
- out = stdlib_base_bernoulli( 1 );
160
+ out = stdlib_base_bernoulli( 1.0 );
161
161
// returns 0.5
162
162
```
163
163
164
164
The function accepts the following arguments:
165
165
166
- - ** n** : ` [in] int32_t ` input value.
166
+ - ** n** : ` [in] double ` input value.
167
167
168
168
``` c
169
- double stdlib_base_bernoulli ( const int32_t n );
169
+ double stdlib_base_bernoulli ( const double n );
170
170
```
171
171
172
172
</section>
@@ -190,15 +190,14 @@ double stdlib_base_bernoulli( const int32_t n );
190
190
```c
191
191
#include "stdlib/math/base/special/bernoulli.h"
192
192
#include <stdio.h>
193
- #include <stdint.h>
194
193
195
194
int main( void ) {
196
- int32_t i;
195
+ double i;
197
196
double v;
198
197
199
- for ( i = 0; i < 130; i++ ) {
198
+ for ( i = 0.0 ; i < 130.0 ; i++ ) {
200
199
v = stdlib_base_bernoulli( i );
201
- printf( "bernoulli(%d ) = %lf\n", i, v );
200
+ printf( "bernoulli(%lf ) = %lf\n", i, v );
202
201
}
203
202
}
204
203
```
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ static double benchmark( void ) {
102
102
103
103
t = tic ();
104
104
for ( i = 0 ; i < ITERATIONS ; i ++ ) {
105
- y = stdlib_base_bernoulli ( (int )( x [ i % 100 ] ) );
105
+ y = stdlib_base_bernoulli ( ( x [ i % 100 ] ) );
106
106
if ( y != y ) {
107
107
printf ( "should not return NaN\n" );
108
108
break ;
Original file line number Diff line number Diff line change 18
18
19
19
#include "stdlib/math/base/special/bernoulli.h"
20
20
#include <stdio.h>
21
- #include <stdint.h>
22
21
23
22
int main ( void ) {
24
- int32_t i ;
23
+ double i ;
25
24
double v ;
26
25
27
- for ( i = 0 ; i < 130 ; i ++ ) {
26
+ for ( i = 0.0 ; i < 130.0 ; i ++ ) {
28
27
v = stdlib_base_bernoulli ( i );
29
- printf ( "bernoulli(%d ) = %lf\n" , i , v );
28
+ printf ( "bernoulli(%lf ) = %lf\n" , i , v );
30
29
}
31
30
}
Original file line number Diff line number Diff line change 19
19
#ifndef STDLIB_MATH_BASE_SPECIAL_BERNOULLI_H
20
20
#define STDLIB_MATH_BASE_SPECIAL_BERNOULLI_H
21
21
22
- #include <stdint.h>
23
-
24
22
/*
25
23
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
26
24
*/
@@ -31,7 +29,7 @@ extern "C" {
31
29
/**
32
30
* Computes the nth Bernoulli number.
33
31
*/
34
- double stdlib_base_bernoulli ( const int32_t n );
32
+ double stdlib_base_bernoulli ( const double n );
35
33
36
34
#ifdef __cplusplus
37
35
}
Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ function bernoulli( n ) {
92
92
return 0.0 ;
93
93
}
94
94
if ( n > MAX_BERNOULLI ) {
95
- return ( ( n / 2 ) & 1 ) ? PINF : NINF ;
95
+ return ( isOdd ( n / 2.0 ) ) ? PINF : NINF ;
96
96
}
97
97
return BERNOULLI [ n / 2 ] ;
98
98
}
Original file line number Diff line number Diff line change 39
39
" @stdlib/math/base/napi/unary" ,
40
40
" @stdlib/math/base/assert/is-odd" ,
41
41
" @stdlib/constants/float64/ninf" ,
42
- " @stdlib/constants/float64/pinf"
42
+ " @stdlib/constants/float64/pinf" ,
43
+ " @stdlib/math/base/assert/is-nonnegative-integer"
43
44
]
44
45
},
45
46
{
55
56
"dependencies" : [
56
57
" @stdlib/math/base/assert/is-odd" ,
57
58
" @stdlib/constants/float64/ninf" ,
58
- " @stdlib/constants/float64/pinf"
59
+ " @stdlib/constants/float64/pinf" ,
60
+ " @stdlib/math/base/assert/is-nonnegative-integer"
59
61
]
60
62
},
61
63
{
71
73
"dependencies" : [
72
74
" @stdlib/math/base/assert/is-odd" ,
73
75
" @stdlib/constants/float64/ninf" ,
74
- " @stdlib/constants/float64/pinf"
76
+ " @stdlib/constants/float64/pinf" ,
77
+ " @stdlib/math/base/assert/is-nonnegative-integer"
75
78
]
76
79
}
77
80
]
Original file line number Diff line number Diff line change 19
19
#include "stdlib/math/base/special/bernoulli.h"
20
20
#include "stdlib/math/base/napi/unary.h"
21
21
22
- STDLIB_MATH_BASE_NAPI_MODULE_I_D ( stdlib_base_bernoulli )
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D ( stdlib_base_bernoulli )
Original file line number Diff line number Diff line change 16
16
* limitations under the License.
17
17
*/
18
18
19
+ #include "stdlib/math/base/assert/is_nonnegative_integer.h"
19
20
#include "stdlib/math/base/assert/is_odd.h"
20
21
#include "stdlib/constants/float64/ninf.h"
21
22
#include "stdlib/constants/float64/pinf.h"
22
23
#include "stdlib/math/base/special/bernoulli.h"
24
+ #include <stdint.h>
25
+ #include <stdlib.h>
23
26
24
27
static const double bernoulli_value [ 130 ] = {
25
28
1.00000000000000000000000000000000000000000 ,
@@ -164,21 +167,21 @@ int32_t MAX_BERNOULLI = 258;
164
167
* @return output value
165
168
*
166
169
* @example
167
- * double out = stdlib_base_bernoulli( 0 );
168
- * // returns 1
170
+ * double out = stdlib_base_bernoulli( 0.0 );
171
+ * // returns 1.0
169
172
*/
170
- double stdlib_base_bernoulli ( const int32_t n ) {
171
- if ( n < 0 ) {
173
+ double stdlib_base_bernoulli ( const double n ) {
174
+ if ( ! stdlib_base_is_nonnegative_integer ( n ) ) {
172
175
return 0.0 / 0.0 ; // NaN
173
176
}
174
- if ( n == 1 ) {
177
+ if ( n == 1.0 ) {
175
178
return 0.5 ;
176
179
}
177
180
if ( stdlib_base_is_odd ( n ) ) {
178
181
return 0.0 ;
179
182
}
180
183
if ( n > MAX_BERNOULLI ) {
181
- return ( ( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF ;
184
+ return ( stdlib_base_is_odd ( n / 2.0 ) ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF ;
182
185
}
183
- return bernoulli_value [ n / 2 ];
186
+ return bernoulli_value [ ( size_t )( n / 2.0 ) ];
184
187
}
You can’t perform that action at this time.
0 commit comments