Created
March 27, 2013 06:39
-
-
Save jussi-kalliokoski/5252226 to your computer and use it in GitHub Desktop.
Some NaN stuff
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
/*jshint asi:true */ | |
var print = typeof console === 'undefined' ? print : console.log.bind(console) | |
var whatnan = function (narray) { | |
return [].map.call(new Uint8Array(narray.buffer), function (n) { | |
return (n < 16 ? '0' : '') + n.toString(16) | |
}).join('') | |
} | |
var printnan = function (nan) { | |
print(whatnan(new Float64Array([nan]))) | |
} | |
print(whatnan(new Float64Array([0/0]))) // 000000000000f87f | |
print(whatnan(new Float64Array([Math.sqrt(-1)]))) // 000000000000f8ff | |
printnan(0/0) | |
// 000000000000f8ff (node) | |
// 000000000000f87f (js) | |
printnan(Math.sqrt(-1)) // 000000000000f8ff | |
var a = 0/0 | |
var b = Math.sqrt(-1) | |
printnan(a) | |
// 000000000000f8ff (node) | |
// 000000000000f87f (js) | |
printnan(b) // 000000000000f8ff | |
var shouldBeImmutable = Object.freeze(Object.create(null, { | |
foo: { | |
value: a | |
} | |
})) | |
printnan(shouldBeImmutable.foo) | |
// 000000000000f8ff (node) | |
// 000000000000f87f (js) | |
Object.defineProperty(shouldBeImmutable, 'foo', { | |
value: b | |
}) | |
printnan(shouldBeImmutable.foo) | |
// 000000000000f8ff (node) | |
// 000000000000f87f (js) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment