Created
May 5, 2016 16:50
-
-
Save jugglinmike/50e562392ed1500350fcc500acca5bec to your computer and use it in GitHub Desktop.
Testing Distinct NaN Representations in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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