Last active
December 15, 2015 11:19
-
-
Save dherman/5251949 to your computer and use it in GitHub Desktop.
a NaN isn't a NaN isn't a NaN
This file contains 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
function bufferBytes(buffer) { | |
return [].map.call(new Uint8Array(buffer), function(x) {return x}) | |
} | |
function nanBytes(nan) { | |
var a = new Float64Array(1); | |
a[0] = nan; | |
return bufferBytes(a.buffer); | |
} | |
var buffer1 = (new Uint8Array([ 0, 0, 0, 0, 0, 0, 248, 127 ])).buffer; | |
var buffer2 = (new Uint8Array([ 0, 0, 0, 0, 0, 0, 248, 255 ])).buffer; | |
var nan1 = NaN; | |
var nan2 = Math.sqrt(-1); | |
var nan3 = (new Float64Array(buffer1))[0]; | |
var nan4 = (new Float64Array(buffer2))[0]; | |
console.log(nanBytes(nan1)); | |
console.log(nanBytes(nan2)); | |
console.log(nanBytes(nan3)); | |
console.log(nanBytes(nan4)); | |
// Firefox: | |
// [ 0, 0, 0, 0, 0, 0, 248, 127 ] | |
// [ 0, 0, 0, 0, 0, 0, 248, 255 ] | |
// [ 0, 0, 0, 0, 0, 0, 248, 127 ] | |
// [ 0, 0, 0, 0, 0, 0, 248, 127 ] | |
// Chrome: | |
// [ 0, 0, 0, 0, 0, 0, 248, 255 ] | |
// [ 0, 0, 0, 0, 0, 0, 248, 127 ] | |
// [ 0, 0, 0, 0, 0, 0, 248, 255 ] | |
// [ 0, 0, 0, 0, 0, 0, 248, 255 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Funny timing. nodejs/node-v0.x-archive@61935bc