Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created May 5, 2016 16:50
Show Gist options
  • Save jugglinmike/50e562392ed1500350fcc500acca5bec to your computer and use it in GitHub Desktop.
Save jugglinmike/50e562392ed1500350fcc500acca5bec to your computer and use it in GitHub Desktop.
Testing Distinct NaN Representations in JavaScript
var a = new Float64Array(2);
var aBytes = new Uint8Array(a.buffer);
aBytes[6] = 248;
aBytes[7] = 255;
aBytes[14] = 248;
aBytes[15] = 127;
var nan1 = a[0];
var nan2 = a[1];
assert(isNaN(nan1), 'first NaN representation');
assert(isNaN(nan2), 'second NaN representation');
var b = new Float64Array(2);
var bBytes = new Uint8Array(b.buffer);
b[0] = nan2;
b[1] = nan1;
print('aBytes:', aBytes.join(' '));
print('bBytes:', bBytes.join(' '));
assert.sameValue(bBytes[6], 248);
assert.sameValue(bBytes[7], 127);
assert.sameValue(bBytes[14], 248);
assert.sameValue(bBytes[15], 255);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment