Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
test: Accept either kind of NaN
Browse files Browse the repository at this point in the history
A llvm/clang bug on Darwin ia32 makes these tests fail 100% of
the time.  Since no one really seems to mind overly much, and we
can't reasonably fix this in node anyway, just accept both types
of NaN for now.
  • Loading branch information
isaacs committed Mar 27, 2013
1 parent ae86fa8 commit 61935bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions test/simple/test-writedouble.js
Expand Up @@ -168,7 +168,9 @@ function test(clazz) {

buffer.writeDoubleBE(NaN, 0);
buffer.writeDoubleLE(NaN, 8);
ASSERT.equal(0x7F, buffer[0]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]);
ASSERT.equal(0xF8, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
Expand All @@ -183,7 +185,9 @@ function test(clazz) {
ASSERT.equal(0x00, buffer[12]);
ASSERT.equal(0x00, buffer[13]);
ASSERT.equal(0xF8, buffer[14]);
ASSERT.equal(0x7F, buffer[15]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[15] || 0xFF === buffer[15]);
ASSERT.ok(isNaN(buffer.readDoubleBE(0)));
ASSERT.ok(isNaN(buffer.readDoubleLE(8)));
}
Expand Down
12 changes: 9 additions & 3 deletions test/simple/test-writefloat.js
Expand Up @@ -99,7 +99,9 @@ function test(clazz) {

buffer.writeFloatBE(-Infinity, 0);
buffer.writeFloatLE(-Infinity, 4);
ASSERT.equal(0xFF, buffer[0]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0xFF === buffer[0] || 0x7F === buffer[0]);
ASSERT.equal(0x80, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
Expand All @@ -112,14 +114,18 @@ function test(clazz) {

buffer.writeFloatBE(NaN, 0);
buffer.writeFloatLE(NaN, 4);
ASSERT.equal(0x7F, buffer[0]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[0] || 0xFF === buffer[0]);
ASSERT.equal(0xc0, buffer[1]);
ASSERT.equal(0x00, buffer[2]);
ASSERT.equal(0x00, buffer[3]);
ASSERT.equal(0x00, buffer[4]);
ASSERT.equal(0x00, buffer[5]);
ASSERT.equal(0xc0, buffer[6]);
ASSERT.equal(0x7F, buffer[7]);
// Darwin ia32 does the other kind of NaN.
// Compiler bug. No one really cares.
ASSERT(0x7F === buffer[7] || 0xFF === buffer[7]);
ASSERT.ok(isNaN(buffer.readFloatBE(0)));
ASSERT.ok(isNaN(buffer.readFloatLE(4)));
}
Expand Down

5 comments on commit 61935bc

@kapouer
Copy link

Choose a reason for hiding this comment

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

I just had a similar bug on mips (little endian), with nodejs 0.10.15 (debian),
both in qemu and real hardware:

buffer.writeDoubleBE(NaN, 0);
buffer.writeDoubleLE(NaN, 8);
<Buffer 7f f7 ff ff ff ff ff ff ff ff ff ff ff ff f7 7f>

and

buffer.writeFloatBE(NaN, 0);
buffer.writeFloatLE(NaN, 4);
<Buffer 7f bf ff ff ff ff bf 7f>

@trevnorris
Copy link

Choose a reason for hiding this comment

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

Just a mention, the bug in clang was fixed in 3.3.

@kapouer
Copy link

Choose a reason for hiding this comment

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

Do you have a reference to that bug in clang ?

@bnoordhuis
Copy link
Member

Choose a reason for hiding this comment

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

http://llvm.org/bugs/show_bug.cgi?id=15054 - might be worth it to try the attached case.

@trevnorris The fix was for ia32 only IIRC?

@trevnorris
Copy link

Choose a reason for hiding this comment

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

@bnoordhuis yea, was ia32 only.

Please sign in to comment.