Skip to content

Commit c9cacbf

Browse files
test: add tests for IEEE 754-2019 compliance
PR-URL: #6571 Ref: #365 Reviewed-by: Athan Reines <[email protected]> Signed-off-by: stdlib-bot <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent 8987c39 commit c9cacbf

File tree

12 files changed

+114
-14
lines changed

12 files changed

+114
-14
lines changed

lib/node_modules/@stdlib/math/base/special/ln/test/test.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' );
2626
var NINF = require( '@stdlib/constants/float64/ninf' );
2727
var EPS = require( '@stdlib/constants/float64/eps' );
2828
var abs = require( '@stdlib/math/base/special/abs' );
29+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
2930
var ln = require( './../lib' );
3031

3132

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

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

@@ -224,3 +226,9 @@ tape( 'the function returns `NaN` if provided a negative number', function test(
224226
t.strictEqual( isnan( v ), true, 'returns NaN' );
225227
t.end();
226228
});
229+
230+
tape( 'the function returns positive zero if provided `1.0`', function test( t ) {
231+
var v = ln( 1.0 );
232+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
233+
t.end();
234+
});

lib/node_modules/@stdlib/math/base/special/ln/test/test.native.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var PINF = require( '@stdlib/constants/float64/pinf' );
2727
var NINF = require( '@stdlib/constants/float64/ninf' );
2828
var EPS = require( '@stdlib/constants/float64/eps' );
2929
var abs = require( '@stdlib/math/base/special/abs' );
30+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3031
var tryRequire = require( '@stdlib/utils/try-require' );
3132

3233

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

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

@@ -233,3 +235,9 @@ tape( 'the function returns `NaN` if provided a negative number', opts, function
233235
t.strictEqual( isnan( v ), true, 'returns NaN' );
234236
t.end();
235237
});
238+
239+
tape( 'the function returns positive zero if provided `1.0`', opts, function test( t ) {
240+
var v = ln( 1.0 );
241+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
242+
t.end();
243+
});

lib/node_modules/@stdlib/math/base/special/lnf/test/test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var NINF = require( '@stdlib/constants/float32/ninf' );
2727
var EPS = require( '@stdlib/constants/float32/eps' );
2828
var abs = require( '@stdlib/math/base/special/abs' );
2929
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
30+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3031
var lnf = require( './../lib' );
3132

3233

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

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

@@ -239,3 +241,9 @@ tape( 'the function returns `NaN` if provided a negative number', function test(
239241
t.strictEqual( isnanf( v ), true, 'returns expected value' );
240242
t.end();
241243
});
244+
245+
tape( 'the function returns positive zero if provided `1.0`', function test( t ) {
246+
var v = lnf( 1.0 );
247+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
248+
t.end();
249+
});

lib/node_modules/@stdlib/math/base/special/lnf/test/test.native.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var NINF = require( '@stdlib/constants/float32/ninf' );
2828
var EPS = require( '@stdlib/constants/float32/eps' );
2929
var abs = require( '@stdlib/math/base/special/abs' );
3030
var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' );
31+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3132
var tryRequire = require( '@stdlib/utils/try-require' );
3233

3334

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

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

@@ -248,3 +250,9 @@ tape( 'the function returns `NaN` if provided a negative number', opts, function
248250
t.strictEqual( isnanf( v ), true, 'returns expected value' );
249251
t.end();
250252
});
253+
254+
tape( 'the function returns positive zero if provided `1.0`', opts, function test( t ) {
255+
var v = lnf( 1.0 );
256+
t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
257+
t.end();
258+
});

lib/node_modules/@stdlib/math/base/special/log/test/test.js

+32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var randu = require( '@stdlib/random/base/randu' );
2626
var round = require( '@stdlib/math/base/special/round' );
2727
var ln = require( '@stdlib/math/base/special/ln' );
2828
var EPS = require( '@stdlib/constants/float64/eps' );
29+
var PINF = require( '@stdlib/constants/float64/pinf' );
30+
var NINF = require( '@stdlib/constants/float64/ninf' );
31+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
2932
var log = require( './../lib' );
3033

3134

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

74+
tape( 'the function returns `+infinity` if provided `x = +infinity` and a valid `b`', function test( t ) {
75+
t.equal( log( PINF, 1.0 ), PINF, 'returns expected value' );
76+
t.equal( log( PINF, 2.0 ), PINF, 'returns expected value' );
77+
t.equal( log( PINF, 10.0 ), PINF, 'returns expected value' );
78+
t.end();
79+
});
80+
81+
tape( 'the function returns `-infinity` if provided `x = +-0` and a valid `b`', function test( t ) {
82+
t.equal( log( 0.0, 1.0 ), NINF, 'returns expected value' );
83+
t.equal( log( 0.0, 2.0 ), NINF, 'returns expected value' );
84+
t.equal( log( 0.0, 10.0 ), NINF, 'returns expected value' );
85+
t.equal( log( -0.0, 1.0 ), NINF, 'returns expected value' );
86+
t.equal( log( -0.0, 2.0 ), NINF, 'returns expected value' );
87+
t.equal( log( -0.0, 10.0 ), NINF, 'returns expected value' );
88+
t.end();
89+
});
90+
91+
tape( 'the function returns positive zero if provided `x = 1.0` and a valid `b`', function test( t ) {
92+
var v;
93+
94+
v = log( 1.0, 2.0 );
95+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
96+
97+
v = log( 1.0, 10.0 );
98+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
99+
100+
t.end();
101+
});
102+
71103
tape( 'the function returns `ln(x) / ln(b)`', function test( t ) {
72104
var b;
73105
var x;

lib/node_modules/@stdlib/math/base/special/log/test/test.native.js

+32
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var randu = require( '@stdlib/random/base/randu' );
2727
var round = require( '@stdlib/math/base/special/round' );
2828
var ln = require( '@stdlib/math/base/special/ln' );
2929
var EPS = require( '@stdlib/constants/float64/eps' );
30+
var PINF = require( '@stdlib/constants/float64/pinf' );
31+
var NINF = require( '@stdlib/constants/float64/ninf' );
32+
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
3033
var tryRequire = require( '@stdlib/utils/try-require' );
3134

3235

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

83+
tape( 'the function returns `+infinity` if provided `x = +infinity` and a valid `b`', opts, function test( t ) {
84+
t.equal( log( PINF, 1.0 ), PINF, 'returns expected value' );
85+
t.equal( log( PINF, 2.0 ), PINF, 'returns expected value' );
86+
t.equal( log( PINF, 10.0 ), PINF, 'returns expected value' );
87+
t.end();
88+
});
89+
90+
tape( 'the function returns `-infinity` if provided `x = +-0` and a valid `b`', opts, function test( t ) {
91+
t.equal( log( 0.0, 1.0 ), NINF, 'returns expected value' );
92+
t.equal( log( 0.0, 2.0 ), NINF, 'returns expected value' );
93+
t.equal( log( 0.0, 10.0 ), NINF, 'returns expected value' );
94+
t.equal( log( -0.0, 1.0 ), NINF, 'returns expected value' );
95+
t.equal( log( -0.0, 2.0 ), NINF, 'returns expected value' );
96+
t.equal( log( -0.0, 10.0 ), NINF, 'returns expected value' );
97+
t.end();
98+
});
99+
100+
tape( 'the function returns positive zero if provided `x = 1.0` and a valid `b`', opts, function test( t ) {
101+
var v;
102+
103+
v = log( 1.0, 2.0 );
104+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
105+
106+
v = log( 1.0, 10.0 );
107+
t.equal( isPositiveZero( v ), true, 'returns expected value' );
108+
109+
t.end();
110+
});
111+
80112
tape( 'the function returns `ln(x) / ln(b)`', opts, function test( t ) {
81113
var b;
82114
var x;

lib/node_modules/@stdlib/math/base/special/log10/lib/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function log10( x ) {
119119
return NaN;
120120
}
121121
toWords.assign( x, WORDS, 1, 0 );
122-
hx = WORDS[ 0 ];
122+
hx = WORDS[ 0 ] | 0; // asm type annotation
123123
lx = WORDS[ 1 ];
124124
k = 0|0; // asm type annotation
125125

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

133133
// Subnormal number, scale up x:
134134
x *= TWO54;
135-
hx = getHighWord( x );
135+
hx = getHighWord( x ) | 0; // asm type annotation
136136
}
137137
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
138138
return x + x;

lib/node_modules/@stdlib/math/base/special/log10/test/test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ tape( 'the function evaluates the common logarithm of `x` (subnormal values)', f
210210
t.end();
211211
});
212212

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

lib/node_modules/@stdlib/math/base/special/log10/test/test.native.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ tape( 'the function evaluates the common logarithm of `x` (subnormal values)', o
219219
t.end();
220220
});
221221

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

lib/node_modules/@stdlib/math/base/special/log2/lib/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function log2( x ) {
116116
return NaN;
117117
}
118118
toWords.assign( x, WORDS, 1, 0 );
119-
hx = WORDS[ 0 ];
119+
hx = WORDS[ 0 ] | 0; // asm type annotation
120120
lx = WORDS[ 1 ];
121121
k = 0|0; // asm type annotation
122122
if ( hx < HIGH_MIN_NORMAL_EXP ) {
@@ -128,7 +128,7 @@ function log2( x ) {
128128

129129
// Subnormal number, scale up x:
130130
x *= TWO54;
131-
hx = getHighWord( x );
131+
hx = getHighWord( x ) | 0; // asm type annotation
132132
}
133133
if ( hx >= HIGH_MAX_NORMAL_EXP ) {
134134
return x + x;

lib/node_modules/@stdlib/math/base/special/log2/test/test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ tape( 'the function evaluates the binary logarithm of `x` (subnormal values)', f
210210
t.end();
211211
});
212212

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

lib/node_modules/@stdlib/math/base/special/log2/test/test.native.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,9 @@ tape( 'the function evaluates the binary logarithm of `x` (subnormal values)', o
219219
t.end();
220220
});
221221

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

0 commit comments

Comments
 (0)