From eda8fecfd4526943b1a33cd19f87ae07f1c76bfb Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 30 Sep 2026 13:14:12 +0000 Subject: [PATCH] fix: preserve sign in `math/base/special/{ceil2,floor2}` Propagates fix from 85d7c62 ("fix: preserve sign") to sibling packages which return the absolute value of the input when provided the negative smallest subnormal. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TurpzeynpkmbhtrFiaufhM --- .../@stdlib/math/base/special/ceil2/lib/main.js | 2 +- lib/node_modules/@stdlib/math/base/special/ceil2/src/main.c | 2 +- .../@stdlib/math/base/special/ceil2/test/test.js | 6 ++++++ .../@stdlib/math/base/special/ceil2/test/test.native.js | 6 ++++++ .../@stdlib/math/base/special/floor2/lib/main.js | 2 +- .../@stdlib/math/base/special/floor2/src/main.c | 2 +- .../@stdlib/math/base/special/floor2/test/test.js | 6 ++++++ .../@stdlib/math/base/special/floor2/test/test.native.js | 6 ++++++ 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/ceil2/lib/main.js b/lib/node_modules/@stdlib/math/base/special/ceil2/lib/main.js index 94ce9239aff0..8e57cecf61f2 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil2/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/ceil2/lib/main.js @@ -72,7 +72,7 @@ function ceil2( x ) { // If provided the smallest subnormal, no rounding possible: if ( p === MIN_EXP_SUBNORMAL ) { - return x; + return sign * x; } // Determine a power of two which rounds the input value toward positive infinity: if ( sign === -1.0 ) { diff --git a/lib/node_modules/@stdlib/math/base/special/ceil2/src/main.c b/lib/node_modules/@stdlib/math/base/special/ceil2/src/main.c index cb36f40fdf26..a2769bea5cdc 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/ceil2/src/main.c @@ -58,7 +58,7 @@ double stdlib_base_ceil2( const double x ) { // If provided the smallest subnormal, no rounding possible: if ( p == STDLIB_CONSTANT_FLOAT64_MIN_BASE2_EXPONENT_SUBNORMAL ) { - return xc; + return x; } // Determine a power of two which rounds the input value toward positive infinity: diff --git a/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.js b/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.js index c1f04a4fdb3b..75096800e1fe 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.js @@ -82,6 +82,12 @@ tape( 'the function returns the minimum double-precision floating-point value if t.end(); }); +tape( 'the function returns the negative minimum double-precision floating-point value if provided the negative minimum double-precision floating-point value', function test( t ) { + var v = ceil2( -SMALLEST_SUBNORMAL ); + t.strictEqual( v, -SMALLEST_SUBNORMAL, 'returns negative smallest subnormal' ); + t.end(); +}); + tape( 'the function overflows if provided a sufficiently large positive value', function test( t ) { var x; var v; diff --git a/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.native.js index 9b75e6226ac4..eeaad0189a05 100644 --- a/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/ceil2/test/test.native.js @@ -91,6 +91,12 @@ tape( 'the function returns the minimum double-precision floating-point value if t.end(); }); +tape( 'the function returns the negative minimum double-precision floating-point value if provided the negative minimum double-precision floating-point value', opts, function test( t ) { + var v = ceil2( -SMALLEST_SUBNORMAL ); + t.strictEqual( v, -SMALLEST_SUBNORMAL, 'returns negative smallest subnormal' ); + t.end(); +}); + tape( 'the function overflows if provided a sufficiently large positive value', opts, function test( t ) { var x; var v; diff --git a/lib/node_modules/@stdlib/math/base/special/floor2/lib/main.js b/lib/node_modules/@stdlib/math/base/special/floor2/lib/main.js index a110109d2a17..7100804e26af 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor2/lib/main.js +++ b/lib/node_modules/@stdlib/math/base/special/floor2/lib/main.js @@ -72,7 +72,7 @@ function floor2( x ) { // If provided the smallest subnormal, no rounding possible: if ( p === MIN_EXP_SUBNORMAL ) { - return x; + return sign * x; } // Determine a power of two which rounds the input value toward negative infinity: if ( sign === 1.0 ) { diff --git a/lib/node_modules/@stdlib/math/base/special/floor2/src/main.c b/lib/node_modules/@stdlib/math/base/special/floor2/src/main.c index 3ebe6e557c71..76dcf15d54ab 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor2/src/main.c +++ b/lib/node_modules/@stdlib/math/base/special/floor2/src/main.c @@ -57,7 +57,7 @@ double stdlib_base_floor2( const double x ) { // If provided the smallest subnormal, no rounding possible: if ( p == STDLIB_CONSTANT_FLOAT64_MIN_BASE2_EXPONENT_SUBNORMAL ) { - return xc; + return x; } // Determine a power of two which rounds the input value toward negative infinity: if ( sign == 1.0 ) { diff --git a/lib/node_modules/@stdlib/math/base/special/floor2/test/test.js b/lib/node_modules/@stdlib/math/base/special/floor2/test/test.js index 99bcce5a3a7d..97a51bf2ed84 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor2/test/test.js +++ b/lib/node_modules/@stdlib/math/base/special/floor2/test/test.js @@ -82,6 +82,12 @@ tape( 'the function returns the minimum double-precision floating-point value if t.end(); }); +tape( 'the function returns the negative minimum double-precision floating-point value if provided the negative minimum double-precision floating-point value', function test( t ) { + var v = floor2( -SMALLEST_SUBNORMAL ); + t.strictEqual( v, -SMALLEST_SUBNORMAL, 'returns negative smallest subnormal' ); + t.end(); +}); + tape( 'the function overflows if provided a sufficiently large negative value', function test( t ) { var x; var v; diff --git a/lib/node_modules/@stdlib/math/base/special/floor2/test/test.native.js b/lib/node_modules/@stdlib/math/base/special/floor2/test/test.native.js index 730e2ebec8b4..67482df5803a 100644 --- a/lib/node_modules/@stdlib/math/base/special/floor2/test/test.native.js +++ b/lib/node_modules/@stdlib/math/base/special/floor2/test/test.native.js @@ -91,6 +91,12 @@ tape( 'the function returns the minimum double-precision floating-point value if t.end(); }); +tape( 'the function returns the negative minimum double-precision floating-point value if provided the negative minimum double-precision floating-point value', opts, function test( t ) { + var v = floor2( -SMALLEST_SUBNORMAL ); + t.strictEqual( v, -SMALLEST_SUBNORMAL, 'returns negative smallest subnormal' ); + t.end(); +}); + tape( 'the function overflows if provided a sufficiently large negative value', opts, function test( t ) { var x; var v;