From b7b38447fd59acab1dffcb1a1e27b593afa724a0 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sun, 24 Aug 2025 00:16:36 +0530 Subject: [PATCH 1/3] refactor: modify C implementation to accept double --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- .../@stdlib/math/base/special/bernoulli/README.md | 15 +++++++-------- .../bernoulli/benchmark/c/native/benchmark.c | 2 +- .../base/special/bernoulli/examples/c/example.c | 7 +++---- .../include/stdlib/math/base/special/bernoulli.h | 4 +--- .../math/base/special/bernoulli/manifest.json | 9 ++++++--- .../math/base/special/bernoulli/src/addon.c | 2 +- .../math/base/special/bernoulli/src/main.c | 15 +++++++++------ 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md b/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md index d5d27336a71d..de040abc59f8 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/README.md @@ -154,19 +154,19 @@ for ( i = 0; i < 280; i++ ) { Computes the nth [Bernoulli number][bernoulli-number]. ```c -double out = stdlib_base_bernoulli( 0 ); +double out = stdlib_base_bernoulli( 0.0 ); // returns 1.0 -out = stdlib_base_bernoulli( 1 ); +out = stdlib_base_bernoulli( 1.0 ); // returns 0.5 ``` The function accepts the following arguments: -- **n**: `[in] int32_t` input value. +- **n**: `[in] double` input value. ```c -double stdlib_base_bernoulli( const int32_t n ); +double stdlib_base_bernoulli( const double n ); ``` @@ -190,15 +190,14 @@ double stdlib_base_bernoulli( const int32_t n ); ```c #include "stdlib/math/base/special/bernoulli.h" #include -#include int main( void ) { - int32_t i; + double i; double v; - for ( i = 0; i < 130; i++ ) { + for ( i = 0.0; i < 130.0; i++ ) { v = stdlib_base_bernoulli( i ); - printf( "bernoulli(%d) = %lf\n", i, v ); + printf( "bernoulli(%lf) = %lf\n", i, v ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c index 075794f585dc..0795faea4d39 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/benchmark/c/native/benchmark.c @@ -102,7 +102,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_bernoulli( (int)( x[ i % 100 ] ) ); + y = stdlib_base_bernoulli( ( x[ i % 100 ] ) ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/examples/c/example.c index b821857724aa..14ce8acdb19d 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/examples/c/example.c @@ -18,14 +18,13 @@ #include "stdlib/math/base/special/bernoulli.h" #include -#include int main( void ) { - int32_t i; + double i; double v; - for ( i = 0; i < 130; i++ ) { + for ( i = 0.0; i < 130.0; i++ ) { v = stdlib_base_bernoulli( i ); - printf( "bernoulli(%d) = %lf\n", i, v ); + printf( "bernoulli(%lf) = %lf\n", i, v ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/include/stdlib/math/base/special/bernoulli.h b/lib/node_modules/@stdlib/math/base/special/bernoulli/include/stdlib/math/base/special/bernoulli.h index 09f82e2d76c8..28c1bd908267 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/include/stdlib/math/base/special/bernoulli.h +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/include/stdlib/math/base/special/bernoulli.h @@ -19,8 +19,6 @@ #ifndef STDLIB_MATH_BASE_SPECIAL_BERNOULLI_H #define STDLIB_MATH_BASE_SPECIAL_BERNOULLI_H -#include - /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. */ @@ -31,7 +29,7 @@ extern "C" { /** * Computes the nth Bernoulli number. */ -double stdlib_base_bernoulli( const int32_t n ); +double stdlib_base_bernoulli( const double n ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json b/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json index b63457894ac8..e8352697c730 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/manifest.json @@ -39,7 +39,8 @@ "@stdlib/math/base/napi/unary", "@stdlib/math/base/assert/is-odd", "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pinf" + "@stdlib/constants/float64/pinf", + "@stdlib/math/base/assert/is-nonnegative-integer" ] }, { @@ -55,7 +56,8 @@ "dependencies": [ "@stdlib/math/base/assert/is-odd", "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pinf" + "@stdlib/constants/float64/pinf", + "@stdlib/math/base/assert/is-nonnegative-integer" ] }, { @@ -71,7 +73,8 @@ "dependencies": [ "@stdlib/math/base/assert/is-odd", "@stdlib/constants/float64/ninf", - "@stdlib/constants/float64/pinf" + "@stdlib/constants/float64/pinf", + "@stdlib/math/base/assert/is-nonnegative-integer" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/addon.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/addon.c index adb2808de128..2ee9d8e56b8f 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/addon.c @@ -19,4 +19,4 @@ #include "stdlib/math/base/special/bernoulli.h" #include "stdlib/math/base/napi/unary.h" -STDLIB_MATH_BASE_NAPI_MODULE_I_D( stdlib_base_bernoulli ) +STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_bernoulli ) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c index 20ba5b75601f..2b0b4690ec31 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c @@ -16,10 +16,13 @@ * limitations under the License. */ +#include "stdlib/math/base/assert/is_nonnegative_integer.h" #include "stdlib/math/base/assert/is_odd.h" #include "stdlib/constants/float64/ninf.h" #include "stdlib/constants/float64/pinf.h" #include "stdlib/math/base/special/bernoulli.h" +#include +#include static const double bernoulli_value[ 130 ] = { 1.00000000000000000000000000000000000000000, @@ -164,11 +167,11 @@ int32_t MAX_BERNOULLI = 258; * @return output value * * @example -* double out = stdlib_base_bernoulli( 0 ); -* // returns 1 +* double out = stdlib_base_bernoulli( 0.0 ); +* // returns 1.0 */ -double stdlib_base_bernoulli( const int32_t n ) { - if ( n < 0 ) { +double stdlib_base_bernoulli( const double n ) { + if ( !stdlib_base_is_nonnegative_integer( n ) ) { return 0.0 / 0.0; // NaN } if ( n == 1 ) { @@ -178,7 +181,7 @@ double stdlib_base_bernoulli( const int32_t n ) { return 0.0; } if ( n > MAX_BERNOULLI ) { - return ( ( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; + return ( (size_t)( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; } - return bernoulli_value[ n / 2 ]; + return bernoulli_value[ (size_t)( n / 2 ) ]; } From 15fe7c0d00f8a5a27e9e4fef3d4dc9a5467efb51 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sun, 24 Aug 2025 12:46:10 +0530 Subject: [PATCH 2/3] refactor: use is-odd instead of bitwise --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - 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 --- --- .../@stdlib/math/base/special/bernoulli/lib/main.js | 2 +- lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js index cbcacc455004..0b4b75025e75 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/lib/main.js @@ -92,7 +92,7 @@ function bernoulli( n ) { return 0.0; } if ( n > MAX_BERNOULLI ) { - return ( (n/2)&1 ) ? PINF : NINF; + return ( isOdd( n/2.0 ) ) ? PINF : NINF; } return BERNOULLI[ n/2 ]; } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c index 2b0b4690ec31..0138c01d8fc8 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c @@ -181,7 +181,7 @@ double stdlib_base_bernoulli( const double n ) { return 0.0; } if ( n > MAX_BERNOULLI ) { - return ( (size_t)( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; + return ( stdlib_base_is_odd( n/2.0 ) ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; } return bernoulli_value[ (size_t)( n / 2 ) ]; } From 8bcda365e74fa32fce555aec24c6cd85590640b4 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 24 Aug 2025 00:18:13 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/math/base/special/bernoulli/src/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c index 0138c01d8fc8..b1eb3203f5bd 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoulli/src/main.c @@ -174,7 +174,7 @@ double stdlib_base_bernoulli( const double n ) { if ( !stdlib_base_is_nonnegative_integer( n ) ) { return 0.0 / 0.0; // NaN } - if ( n == 1 ) { + if ( n == 1.0 ) { return 0.5; } if ( stdlib_base_is_odd( n ) ) { @@ -183,5 +183,5 @@ double stdlib_base_bernoulli( const double n ) { if ( n > MAX_BERNOULLI ) { return ( stdlib_base_is_odd( n/2.0 ) ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF; } - return bernoulli_value[ (size_t)( n / 2 ) ]; + return bernoulli_value[ (size_t)( n / 2.0 ) ]; }