Skip to content

Commit

Permalink
test: fix buffer writes on mips
Browse files Browse the repository at this point in the history
Mips has a different way of handling NaN. This makes sure the tests
pass on MIPS as well.

PR-URL: #20377
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed May 9, 2018
1 parent 98ccaea commit 601f138
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
17 changes: 13 additions & 4 deletions test/parallel/test-buffer-writedouble.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ assert.strictEqual(buffer.readDoubleLE(8), -Infinity);
buffer.writeDoubleBE(NaN, 0);
buffer.writeDoubleLE(NaN, 8);

assert.ok(buffer.equals(new Uint8Array([
0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x7F
])));
// JS only knows a single NaN but there exist two platform specific
// implementations. Therefore, allow both quiet and signalling NaNs.
if (buffer[1] === 0xF7) {
assert.ok(buffer.equals(new Uint8Array([
0x7F, 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF7, 0x7F
])));
} else {
assert.ok(buffer.equals(new Uint8Array([
0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x7F
])));
}

assert.ok(Number.isNaN(buffer.readDoubleBE(0)));
assert.ok(Number.isNaN(buffer.readDoubleLE(8)));
Expand Down
14 changes: 12 additions & 2 deletions test/parallel/test-buffer-writefloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ assert.strictEqual(buffer.readFloatLE(4), -Infinity);

buffer.writeFloatBE(NaN, 0);
buffer.writeFloatLE(NaN, 4);
assert.ok(buffer.equals(
new Uint8Array([ 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F ])));

// JS only knows a single NaN but there exist two platform specific
// implementations. Therefore, allow both quiet and signalling NaNs.
if (buffer[1] === 0xBF) {
assert.ok(
buffer.equals(new Uint8Array(
[ 0x7F, 0xBF, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0x7F ])));
} else {
assert.ok(
buffer.equals(new Uint8Array(
[ 0x7F, 0xC0, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F ])));
}

assert.ok(Number.isNaN(buffer.readFloatBE(0)));
assert.ok(Number.isNaN(buffer.readFloatLE(4)));
Expand Down

0 comments on commit 601f138

Please sign in to comment.