Skip to content

Instantly share code, notes, and snippets.

@jussi-kalliokoski
Created March 27, 2013 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jussi-kalliokoski/5252226 to your computer and use it in GitHub Desktop.
Save jussi-kalliokoski/5252226 to your computer and use it in GitHub Desktop.
Some NaN stuff
/*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