-1

This page says the following:

ClojureScript currently only supports integer and floating point literals that map to JavaScript primitives

Can someone tell me what that actually means for integer? Are they 64-bits (probably not, since it would take two JS numbers for that)? Or 32-bits? Or 53-bits (that being the maximum integer bits in a double AFAIK, see here)?

[EDIT] The reason I want to know this, is that I want to write a "simulation", using a "cross-platform" language, such that the simulation gives the same results in the client (Browser(JS), Android, Web-Start, ...) and the Server (JVM). Floating points are know to cause "de-synchronisation" for simulations, because different hardware can give different results for the same calculation, with the same input. Therefore I want to use "integers" only, but if the size of integers differs between Clojure and ClojureScript, I'm still going to get "de-synchronisation" eventually (for example, when reaching integer overflow, which is used in random number generators, which are heavily used in simulations).

Community
  • 1
  • 1
Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85

2 Answers2

2

"Maps to JavaScript primitives." Seems to me that that means that a ClojureScript integer is exactly the same as a JavaScript integer: it maps to the same primitive type. Which according to this answer, is 2^53-1

Community
  • 1
  • 1
  • According to this page, http://www.w3schools.com/js/js_datatypes.asp , "JavaScript has only one type of numbers.", that being 64-bit floating point, aka double. So JS doesn't actually have "integers" as a type of "primitive", which is why it's not obvious to me I should assume "32-bits" from the statement about ClojureScript. – Sebastien Diot Dec 30 '15 at 19:21
  • 1
    Point. I don't deal with large values often enough for 32 bits to be a problem (I think its come up once in ten years). Given that JS only has the one type, at 64 bits, then I would assume that ClojureScript also only has the one effective type as well, with the same properties and limitations, which is 2^53, http://stackoverflow.com/questions/307179/what-is-javascripts-highest-integer-value-that-a-number-can-go-to-without-losin – Draco18s no longer trusts SE Dec 30 '15 at 19:29
  • (Why the heck won't LaTeX formatting work for me now?) Updated answer. – Draco18s no longer trusts SE Dec 30 '15 at 19:33
2

I tried to somehow verify the answer of @Draco18s, and eventually came to this code, in a ClojureScript REPL:

cljs.user=> (- (+ 9007199254740990 1) 1)
9007199254740990
cljs.user=> (- (+ 9007199254740991 1) 1)
9007199254740991
cljs.user=> (- (+ 9007199254740992 1) 1)
9007199254740991

It looks like "9007199254740992" is still a valid integer, but I thinks that's just because of rounding or something. So, it's really 9007199254740991 (or 2^53-1).

Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85