This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-14
Channels
- # architecture (5)
- # beginners (36)
- # boot (3)
- # cider (89)
- # clara (35)
- # cljsrn (6)
- # clojure (123)
- # clojure-dev (15)
- # clojure-italy (9)
- # clojure-nl (14)
- # clojure-spec (11)
- # clojure-uk (192)
- # clojurescript (27)
- # cursive (22)
- # data-science (1)
- # datascript (1)
- # datomic (31)
- # defnpodcast (1)
- # duct (1)
- # emacs (9)
- # fulcro (2)
- # graphql (16)
- # jobs-discuss (10)
- # juxt (1)
- # keechma (7)
- # mount (4)
- # off-topic (83)
- # onyx (8)
- # pedestal (5)
- # portkey (1)
- # re-frame (44)
- # reagent (29)
- # reitit (4)
- # remote-jobs (1)
- # ring-swagger (1)
- # rum (24)
- # shadow-cljs (1)
- # spacemacs (30)
- # tools-deps (6)
- # vim (23)
@bravilogy please post the error here. it might still be helpful for those of us who have seen it before.
@levitanong figured it out in the end - I just needed to do a quick lein clean
đ
Just checking, but I am assuming that things like
(int (Math/round ...))
don't work in ClojureScript, 'cos the underlying Maths functions are JS not Java..?it works
bearing in mind that there are no integers in JS
itâs all floats down here
nah, only 64-bit floats
It âpretendsâ theyâre ints, but all youâre really getting are floats with zeros to the right of the decimal point.
sensible choices
đ đ
=> (def js-two (js/parseInt "2"))
#'cljs.user/js-two
=> js-two
2
=> (def js-three (js/parseInt "3"))
#'cljs.user/js-three
=> js-three
3
=> (/ js-three js-two)
1.5
=>
CLJS ^^
Compare to Clojure (jvm-based) â
(def clj-2 (int (Integer. "2")))
=> #'user/clj-2
clj-2
=> 2
(def clj-3 (int (Integer. "3")))
=> #'user/clj-3
clj-3
=> 3
(/ clj-3 clj-2)
=> 3/2
So I guess the JavaScript bit-wise logical operators like and, or, xor, shift, etc. coerce 64-bit floats to integers?
Or actually, I don't even know if JavaScript has such operators, but ClojureScript has functions for them like Clojure does, and they appear as if they work on the 2's complement integer representations.
And for example BuckleScript uses that trick to compile to Integers https://reasonml.github.io/en/try.html?rrjsx=true&reason=C4TwDgpgBMBOHQLxQDIQIYDMoB8oDkB7AEwgAoBLAO2ABoZ4J64EBKAbgChOAbCYKPADGUAM4BXALZRklYBEmsZAPigBvTlDEB3CsCEALKHIVKNWvGiwqoABk24CJcgDd0PcUyh9MdQRQBzA2AlRFU3D2gAajEpMh8QqBiJSTJYQOCOBwBfTmyuXn4oSRAAFUYZByJSMgctAEZaOqcagCZ6avIAFnorTF6MTFYO5zIANgGsSaHh5s6yAGYRmoBWaenhlvIAdnXUQdZWByzOFLIS8rZcVQApUQA6HkIA9iA
Does JavaScript have arbitrary precision integers built in, or added on via the Google Closure library?
Google Closure provides Int and Long classes, but these are not performant for sure https://google.github.io/closure-library/api/goog.math.Integer.html https://google.github.io/closure-library/api/goog.math.Long.html
V8 and Chrome recently added support for BigInt btw, you can try it now in Chrome dev/beta/canary typeof 1n // "bigint"