From b76c750935c37dbe61c5414054ca8084459227e7 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sun, 24 Aug 2025 00:29:29 +0530 Subject: [PATCH 1/5] refactor: modify C implementation to accept float --- 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 --- --- .../math/base/special/bernoullif/README.md | 15 +++++++-------- .../bernoullif/benchmark/c/native/benchmark.c | 3 +-- .../base/special/bernoullif/examples/c/example.c | 7 +++---- .../include/stdlib/math/base/special/bernoullif.h | 4 +--- .../math/base/special/bernoullif/manifest.json | 12 +++++++++--- .../math/base/special/bernoullif/src/addon.c | 2 +- .../math/base/special/bernoullif/src/main.c | 15 +++++++++------ 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md b/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md index 4791711ef06f..6528deb8470d 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/README.md @@ -156,19 +156,19 @@ logEachMap( 'bernoullif(%d) = %0.4f', x, bernoullif ); Computes the nth [Bernoulli number][bernoulli-number] as a single-precision floating-point number. ```c -float out = stdlib_base_bernoullif( 0 ); +float out = stdlib_base_bernoullif( 0.0f ); // returns 1.0f -out = stdlib_base_bernoullif( 1 ); +out = stdlib_base_bernoullif( 1.0f ); // returns 0.5f ``` The function accepts the following arguments: -- **n**: `[in] int32_t` input value. +- **n**: `[in] float` input value. ```c -float stdlib_base_bernoullif( const int32_t n ); +float stdlib_base_bernoullif( const float n ); ``` @@ -192,15 +192,14 @@ float stdlib_base_bernoullif( const int32_t n ); ```c #include "stdlib/math/base/special/bernoullif.h" #include -#include int main( void ) { - int32_t i; + float i; float v; - for ( i = 0; i < 70; i++ ) { + for ( i = 0.0f; i < 70.0f; i++ ) { v = stdlib_base_bernoullif( i ); - printf( "bernoullif(%d) = %f\n", i, v ); + printf( "bernoullif(%f) = %f\n", i, v ); } } ``` diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/benchmark.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/benchmark.c index ccc644bc354d..d7ae6982d331 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/benchmark/c/native/benchmark.c @@ -18,7 +18,6 @@ #include "stdlib/math/base/special/bernoullif.h" #include -#include #include #include #include @@ -103,7 +102,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_bernoullif( (int32_t)( x[ i%100 ] ) ); + y = stdlib_base_bernoullif( ( x[ i%100 ] ) ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/example.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/example.c index dd088db88bce..2f7c1e9c7e08 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/example.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/examples/c/example.c @@ -18,14 +18,13 @@ #include "stdlib/math/base/special/bernoullif.h" #include -#include int main( void ) { - int32_t i; + float i; float v; - for ( i = 0; i < 70; i++ ) { + for ( i = 0.0f; i < 70.0f; i++ ) { v = stdlib_base_bernoullif( i ); - printf( "bernoullif(%d) = %f\n", i, v ); + printf( "bernoullif(%f) = %f\n", i, v ); } } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/include/stdlib/math/base/special/bernoullif.h b/lib/node_modules/@stdlib/math/base/special/bernoullif/include/stdlib/math/base/special/bernoullif.h index d91a06908c7e..87b87c910942 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/include/stdlib/math/base/special/bernoullif.h +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/include/stdlib/math/base/special/bernoullif.h @@ -19,8 +19,6 @@ #ifndef STDLIB_MATH_BASE_SPECIAL_BERNOULLIF_H #define STDLIB_MATH_BASE_SPECIAL_BERNOULLIF_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 as a single-precision floating-point number. */ -float stdlib_base_bernoullif( const int32_t n ); +float stdlib_base_bernoullif( const float n ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json b/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json index dfd6c1402483..728bd21fab18 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/manifest.json @@ -38,7 +38,9 @@ "dependencies": [ "@stdlib/math/base/napi/unary", "@stdlib/constants/float32/ninf", - "@stdlib/constants/float32/pinf" + "@stdlib/constants/float32/pinf", + "@stdlib/math/base/assert/is-nonnegative-integerf", + "@stdlib/math/base/assert/is-oddf" ] }, { @@ -53,7 +55,9 @@ "libpath": [], "dependencies": [ "@stdlib/constants/float32/ninf", - "@stdlib/constants/float32/pinf" + "@stdlib/constants/float32/pinf", + "@stdlib/math/base/assert/is-nonnegative-integerf", + "@stdlib/math/base/assert/is-oddf" ] }, { @@ -68,7 +72,9 @@ "libpath": [], "dependencies": [ "@stdlib/constants/float32/ninf", - "@stdlib/constants/float32/pinf" + "@stdlib/constants/float32/pinf", + "@stdlib/math/base/assert/is-nonnegative-integerf", + "@stdlib/math/base/assert/is-oddf" ] } ] diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/addon.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/addon.c index b3fbf2264ddd..340d04fbd5e5 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/addon.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/addon.c @@ -19,4 +19,4 @@ #include "stdlib/math/base/special/bernoullif.h" #include "stdlib/math/base/napi/unary.h" -STDLIB_MATH_BASE_NAPI_MODULE_I_F( stdlib_base_bernoullif ) +STDLIB_MATH_BASE_NAPI_MODULE_F_F( stdlib_base_bernoullif ) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c index 37807ea16ad9..00a4e14a5d45 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c @@ -16,10 +16,13 @@ * limitations under the License. */ +#include "stdlib/math/base/assert/is_nonnegative_integerf.h" +#include "stdlib/math/base/assert/is_oddf.h" #include "stdlib/math/base/special/bernoullif.h" #include "stdlib/constants/float32/ninf.h" #include "stdlib/constants/float32/pinf.h" #include +#include static const float bernoulli_value[ 33 ] = { 1.0f, @@ -66,21 +69,21 @@ static const int32_t MAX_BERNOULLI = 64; * @return output value * * @example -* float out = stdlib_base_bernoullif( 0 ); +* float out = stdlib_base_bernoullif( 0.0f ); * // returns 1.0f */ -float stdlib_base_bernoullif( const int32_t n ) { - if ( n < 0 ) { +float stdlib_base_bernoullif( const float n ) { + if ( !stdlib_base_is_nonnegative_integerf( n ) ) { return 0.0f / 0.0f; // NaN } if ( n == 1 ) { return 0.5f; } - if ( n & 1 ) { + if ( stdlib_base_is_oddf( n ) ) { return 0.0f; } if ( n > MAX_BERNOULLI ) { - return ( ( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; + return ( (size_t)( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; } - return bernoulli_value[ n / 2 ]; + return bernoulli_value[ (size_t)( n / 2 ) ]; } From 4ca929e2afef6dbefa45c2381f8bc025a9d25773 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 24 Aug 2025 00:20:38 -0700 Subject: [PATCH 2/5] style: add decimal Signed-off-by: Athan --- .../@stdlib/math/base/special/bernoullif/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c index 00a4e14a5d45..f0a1598fe6db 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c @@ -76,7 +76,7 @@ float stdlib_base_bernoullif( const float n ) { if ( !stdlib_base_is_nonnegative_integerf( n ) ) { return 0.0f / 0.0f; // NaN } - if ( n == 1 ) { + if ( n == 1.0 ) { return 0.5f; } if ( stdlib_base_is_oddf( n ) ) { From 22ac2d29e36b020f48700bdee8dd8dc0940dacf0 Mon Sep 17 00:00:00 2001 From: GUNJ JOSHI Date: Sun, 24 Aug 2025 12:50:47 +0530 Subject: [PATCH 3/5] refactor: use is-oddf 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/bernoullif/lib/main.js | 6 +++--- .../@stdlib/math/base/special/bernoullif/src/main.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js index aa3d8dad5ee4..136adc68c2cd 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/lib/main.js @@ -23,7 +23,7 @@ var isNonNegativeIntegerf = require( '@stdlib/math/base/assert/is-nonnegative-integerf' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); -var isOdd = require( '@stdlib/math/base/assert/is-odd' ); +var isOddf = require( '@stdlib/math/base/assert/is-oddf' ); var NINF = require( '@stdlib/constants/float32/ninf' ); var PINF = require( '@stdlib/constants/float32/pinf' ); var BERNOULLIF = require( './bernoullif.json' ); @@ -89,11 +89,11 @@ function bernoullif( n ) { if ( n === 1 ) { return 0.5; } - if ( isOdd( n ) ) { + if ( isOddf( n ) ) { return 0.0; } if ( n > MAX_BERNOULLI ) { - return ( (n/2)&1 ) ? PINF : NINF; + return ( isOddf( n/2.0 ) ) ? PINF : NINF; } return float64ToFloat32( BERNOULLIF[ n/2 ] ); } diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c index 00a4e14a5d45..6a8c9f468875 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c @@ -76,14 +76,14 @@ float stdlib_base_bernoullif( const float n ) { if ( !stdlib_base_is_nonnegative_integerf( n ) ) { return 0.0f / 0.0f; // NaN } - if ( n == 1 ) { + if ( n == 1.0f ) { return 0.5f; } if ( stdlib_base_is_oddf( n ) ) { return 0.0f; } if ( n > MAX_BERNOULLI ) { - return ( (size_t)( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; + return ( stdlib_base_is_oddf( n/2.0f ) ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; } - return bernoulli_value[ (size_t)( n / 2 ) ]; + return bernoulli_value[ (size_t)( n / 2.0f ) ]; } From a9c26e87223d943c82d5bad6187aa84e28ce1d92 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 24 Aug 2025 00:21:01 -0700 Subject: [PATCH 4/5] style: add decimal Signed-off-by: Athan --- .../@stdlib/math/base/special/bernoullif/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c index f0a1598fe6db..f0095c80c742 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c @@ -85,5 +85,5 @@ float stdlib_base_bernoullif( const float n ) { if ( n > MAX_BERNOULLI ) { return ( (size_t)( n / 2 ) & 1 ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; } - return bernoulli_value[ (size_t)( n / 2 ) ]; + return bernoulli_value[ (size_t)( n / 2.0 ) ]; } From 1cedace6b75ad9e92fa7854ac954ad0f8e0cf2e5 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 24 Aug 2025 00:25:35 -0700 Subject: [PATCH 5/5] style: remove whitespace Signed-off-by: Athan --- .../@stdlib/math/base/special/bernoullif/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c index 6a8c9f468875..616a5c5785ed 100644 --- a/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/bernoullif/src/main.c @@ -83,7 +83,7 @@ float stdlib_base_bernoullif( const float n ) { return 0.0f; } if ( n > MAX_BERNOULLI ) { - return ( stdlib_base_is_oddf( n/2.0f ) ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; + return ( stdlib_base_is_oddf( n/2.0f ) ) ? STDLIB_CONSTANT_FLOAT32_PINF : STDLIB_CONSTANT_FLOAT32_NINF; } return bernoulli_value[ (size_t)( n / 2.0f ) ]; }