Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for IEEE 754-2019 compliance #6571

Merged
merged 19 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/ln/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var ln = require( './../lib' );


Expand Down Expand Up @@ -209,8 +210,9 @@ tape( 'the function evaluates the natural logarithm of `x` (subnormal values)',
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', function test( t ) {
t.strictEqual( ln( 0.0 ), NINF, 'equals -infinity' );
tape( 'the function returns `-infinity` if provided `+-0`', function test( t ) {
t.strictEqual( ln( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( ln( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand All @@ -224,3 +226,9 @@ tape( 'the function returns `NaN` if provided a negative number', function test(
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.end();
});

tape( 'the function returns positive zero if provided `1.0`', function test( t ) {
var v = ln( 1.0 );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
t.end();
});
12 changes: 10 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/ln/test/test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -218,8 +219,9 @@ tape( 'the function evaluates the natural logarithm of `x` (subnormal values)',
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', opts, function test( t ) {
t.strictEqual( ln( 0.0 ), NINF, 'equals -infinity' );
tape( 'the function returns `-infinity` if provided `+-0`', opts, function test( t ) {
t.strictEqual( ln( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( ln( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand All @@ -233,3 +235,9 @@ tape( 'the function returns `NaN` if provided a negative number', opts, function
t.strictEqual( isnan( v ), true, 'returns NaN' );
t.end();
});

tape( 'the function returns positive zero if provided `1.0`', opts, function test( t ) {
var v = ln( 1.0 );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
t.end();
});
10 changes: 9 additions & 1 deletion lib/node_modules/@stdlib/math/base/special/lnf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var NINF = require( '@stdlib/constants/float32/ninf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var lnf = require( './../lib' );


Expand Down Expand Up @@ -224,8 +225,9 @@ tape( 'the function evaluates the natural logarithm of `x` (subnormal values)',
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', function test( t ) {
tape( 'the function returns `-infinity` if provided `+-0`', function test( t ) {
t.strictEqual( lnf( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( lnf( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand All @@ -239,3 +241,9 @@ tape( 'the function returns `NaN` if provided a negative number', function test(
t.strictEqual( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns positive zero if provided `1.0`', function test( t ) {
var v = lnf( 1.0 );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var NINF = require( '@stdlib/constants/float32/ninf' );
var EPS = require( '@stdlib/constants/float32/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -233,8 +234,9 @@ tape( 'the function evaluates the natural logarithm of `x` (subnormal values)',
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', opts, function test( t ) {
tape( 'the function returns `-infinity` if provided `+-0`', opts, function test( t ) {
t.strictEqual( lnf( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( lnf( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand All @@ -248,3 +250,9 @@ tape( 'the function returns `NaN` if provided a negative number', opts, function
t.strictEqual( isnanf( v ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns positive zero if provided `1.0`', opts, function test( t ) {
var v = lnf( 1.0 );
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
t.end();
});
32 changes: 32 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/log/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var ln = require( '@stdlib/math/base/special/ln' );
var EPS = require( '@stdlib/constants/float64/eps' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var log = require( './../lib' );


Expand Down Expand Up @@ -68,6 +71,35 @@ tape( 'the function returns `1.0` if provided `x` and `b` such that `x = b` (exc
t.end();
});

tape( 'the function returns `+infinity` if provided `x = +infinity` and a valid `b`', function test( t ) {
t.equal( log( PINF, 1.0 ), PINF, 'returns expected value' );
t.equal( log( PINF, 2.0 ), PINF, 'returns expected value' );
t.equal( log( PINF, 10.0 ), PINF, 'returns expected value' );
t.end();
});

tape( 'the function returns `-infinity` if provided `x = +-0` and a valid `b`', function test( t ) {
t.equal( log( 0.0, 1.0 ), NINF, 'returns expected value' );
t.equal( log( 0.0, 2.0 ), NINF, 'returns expected value' );
t.equal( log( 0.0, 10.0 ), NINF, 'returns expected value' );
t.equal( log( -0.0, 1.0 ), NINF, 'returns expected value' );
t.equal( log( -0.0, 2.0 ), NINF, 'returns expected value' );
t.equal( log( -0.0, 10.0 ), NINF, 'returns expected value' );
t.end();
});

tape( 'the function returns positive zero if provided `x = 1.0` and a valid `b`', function test( t ) {
var v;

v = log( 1.0, 2.0 );
t.equal( isPositiveZero( v ), true, 'returns expected value' );

v = log( 1.0, 10.0 );
t.equal( isPositiveZero( v ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns `ln(x) / ln(b)`', function test( t ) {
var b;
var x;
Expand Down
32 changes: 32 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/log/test/test.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var ln = require( '@stdlib/math/base/special/ln' );
var EPS = require( '@stdlib/constants/float64/eps' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var tryRequire = require( '@stdlib/utils/try-require' );


Expand Down Expand Up @@ -77,6 +80,35 @@ tape( 'the function returns `1.0` if provided `x` and `b` such that `x = b` (exc
t.end();
});

tape( 'the function returns `+infinity` if provided `x = +infinity` and a valid `b`', opts, function test( t ) {
t.equal( log( PINF, 1.0 ), PINF, 'returns expected value' );
t.equal( log( PINF, 2.0 ), PINF, 'returns expected value' );
t.equal( log( PINF, 10.0 ), PINF, 'returns expected value' );
t.end();
});

tape( 'the function returns `-infinity` if provided `x = +-0` and a valid `b`', opts, function test( t ) {
t.equal( log( 0.0, 1.0 ), NINF, 'returns expected value' );
t.equal( log( 0.0, 2.0 ), NINF, 'returns expected value' );
t.equal( log( 0.0, 10.0 ), NINF, 'returns expected value' );
t.equal( log( -0.0, 1.0 ), NINF, 'returns expected value' );
t.equal( log( -0.0, 2.0 ), NINF, 'returns expected value' );
t.equal( log( -0.0, 10.0 ), NINF, 'returns expected value' );
t.end();
});

tape( 'the function returns positive zero if provided `x = 1.0` and a valid `b`', opts, function test( t ) {
var v;

v = log( 1.0, 2.0 );
t.equal( isPositiveZero( v ), true, 'returns expected value' );

v = log( 1.0, 10.0 );
t.equal( isPositiveZero( v ), true, 'returns expected value' );

t.end();
});

tape( 'the function returns `ln(x) / ln(b)`', opts, function test( t ) {
var b;
var x;
Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/log10/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function log10( x ) {
return NaN;
}
toWords.assign( x, WORDS, 1, 0 );
hx = WORDS[ 0 ];
hx = WORDS[ 0 ] | 0; // asm type annotation
lx = WORDS[ 1 ];
k = 0|0; // asm type annotation

Expand All @@ -132,7 +132,7 @@ function log10( x ) {

// Subnormal number, scale up x:
x *= TWO54;
hx = getHighWord( x );
hx = getHighWord( x ) | 0; // asm type annotation
Copy link
Contributor Author

@anandkaranubc anandkaranubc Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also updated this line accordingly to be consistent with upstream (and C) implementation.

Reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our C implementation:

xc *= TWO54;
stdlib_base_float64_get_high_word( xc, &hx );
ihx = (int32_t)hx;

}
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
return x + x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ tape( 'the function evaluates the common logarithm of `x` (subnormal values)', f
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', function test( t ) {
tape( 'the function returns `-infinity` if provided `+-0`', function test( t ) {
t.strictEqual( log10( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( log10( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ tape( 'the function evaluates the common logarithm of `x` (subnormal values)', o
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', opts, function test( t ) {
tape( 'the function returns `-infinity` if provided `+-0`', opts, function test( t ) {
t.strictEqual( log10( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( log10( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/math/base/special/log2/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function log2( x ) {
return NaN;
}
toWords.assign( x, WORDS, 1, 0 );
hx = WORDS[ 0 ];
hx = WORDS[ 0 ] | 0; // asm type annotation
lx = WORDS[ 1 ];
k = 0|0; // asm type annotation
if ( hx < HIGH_MIN_NORMAL_EXP ) {
Expand All @@ -128,7 +128,7 @@ function log2( x ) {

// Subnormal number, scale up x:
x *= TWO54;
hx = getHighWord( x );
hx = getHighWord( x ) | 0; // asm type annotation
}
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
return x + x;
Expand Down
3 changes: 2 additions & 1 deletion lib/node_modules/@stdlib/math/base/special/log2/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ tape( 'the function evaluates the binary logarithm of `x` (subnormal values)', f
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', function test( t ) {
tape( 'the function returns `-infinity` if provided `+-0`', function test( t ) {
t.strictEqual( log2( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( log2( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ tape( 'the function evaluates the binary logarithm of `x` (subnormal values)', o
t.end();
});

tape( 'the function returns `-infinity` if provided `0`', opts, function test( t ) {
tape( 'the function returns `-infinity` if provided `+-0`', opts, function test( t ) {
t.strictEqual( log2( 0.0 ), NINF, 'returns expected value' );
t.strictEqual( log2( -0.0 ), NINF, 'returns expected value' );
t.end();
});

Expand Down