I just found this interesting article about numbers in JavaScript. Apparently JavaScript doesn't actually have integers, just floating point numbers, and so it actually just approximates integers the same way decimal numbers get approximated. So you end up with problems like (I copied these results from my JS console):
>>> 10000000000000000 === 10000000000000001 true >>> 10000000000000000+1 10000000000000000
Here's the article: http://blog.greweb.fr/2013/01/be-careful-with-js-numbers/
I just found this interesting article about numbers in JavaScript. Apparently JavaScript doesn't actually have integers, just floating point numbers, and so it actually just approximates integers the same way decimal numbers get approximated. So you end up with problems like (I copied these results from my JS console):
>>> 10000000000000000 === 10000000000000001 true >>> 10000000000000000+1 10000000000000000
Here's the article: http://blog.greweb.fr/2013/01/be-careful-with-js-numbers/
You must browse reddit . I saw that this morning. Pretty interesting. I wasn't aware that javascript handled numbers that way.
You must browse reddit . I saw that this morning. Pretty interesting. I wasn't aware that javascript handled numbers that way.
Interesting! I have to say, I wasn't aware of that either...
I guess on the one hand it "reduces complexity" in that it saves on multiple types for JS to store and manipulate/carry out any operations on numbers. If they're ALL in floating point, it saves casting and conversion - perhaps at the expense of memory and speed though.
However, it looks like they wrap it up to the Nth degree to hide that fact. JS must waste a lot of time just determining types? For any given variable JS must have to inspect the variable contents first - which seems a bit backwards and more intensive than just having typed variable in the first place, negating any benefit of a single numeric type?
Meh, maybe I am over analysing it CPU Architecture exam in two days time, I'll blame that!
Jim,
Interesting! I have to say, I wasn't aware of that either...
I guess on the one hand it "reduces complexity" in that it saves on multiple types for JS to store and manipulate/carry out any operations on numbers. If they're ALL in floating point, it saves casting and conversion - perhaps at the expense of memory and speed though.
However, it looks like they wrap it up to the Nth degree to hide that fact. JS must waste a lot of time just determining types? For any given variable JS must have to inspect the variable contents first - which seems a bit backwards and more intensive than just having typed variable in the first place, negating any benefit of a single numeric type?
Meh, maybe I am over analysing it CPU Architecture exam in two days time, I'll blame that!
Jim,