Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test: Accept either kind of NaN

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...
commit 61935bc167cc2de57c6417bd12493775dc9c1b81 1 parent ae86fa8
@isaacs isaacs authored
Showing with 15 additions and 5 deletions.
  1. +6 −2 test/simple/test-writedouble.js
  2. +9 −3 test/simple/test-writefloat.js
View
8 test/simple/test-writedouble.js
@@ -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]);
@@ -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)));
}
View
12 test/simple/test-writefloat.js
@@ -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]);
@@ -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)));
}

5 comments on commit 61935bc

@kapouer

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
Owner

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

@kapouer

Do you have a reference to that bug in clang ?

@bnoordhuis

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
Owner

@bnoordhuis yea, was ia32 only.

Please sign in to comment.
Something went wrong with that request. Please try again.