This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-27
Channels
- # announcements (7)
- # aws (1)
- # beginners (42)
- # calva (65)
- # clj-kondo (5)
- # cljs-dev (11)
- # clojure (69)
- # clojure-australia (7)
- # clojure-dev (4)
- # clojure-europe (9)
- # clojure-gamedev (2)
- # clojurescript (2)
- # conjure (4)
- # cursive (1)
- # data-science (1)
- # datomic (8)
- # events (1)
- # fulcro (35)
- # graalvm-mobile (40)
- # introduce-yourself (1)
- # lsp (26)
- # malli (14)
- # mathematics (2)
- # missionary (5)
- # nextjournal (4)
- # off-topic (4)
- # polylith (10)
- # shadow-cljs (5)
- # test-doc-blocks (1)
- # tools-build (24)
- # tools-deps (1)
- # xtdb (12)
(reposted since I sent this to the wrong channel) Working on the cljs.math thing, I’m encountering a couple of cases where `-0.0` is significant. The IEEE-754 standard represents `0.0` as `0x0000000000000000`, and `-0.0` as `0x8000000000000000`. In Clojure, I can use these easily:
user=> -0.0
-0.0
user=> (str -0.0)
"-0.0"
It works similarly in node, though conversion to a string does not:
> -0.0
-0
> "" + -0.0
'0'
> let z = -0.0
undefined
> z
-0
ClojureScript seems to lose this info entirely:
cljs.user=> -0.0
0
cljs.user=> (str -0.0)
"0"
Fortunately, the info is there:
cljs.user=> (def z -0.0)
#'cljs.user/z
cljs.user=> (let [buffer (js/ArrayBuffer. 8)
d (js/Float64Array. buffer)
b (js/Uint8Array. buffer)]
(aset d 0 z)
(str b))
"0,0,0,0,0,0,0,128"
(Obviously, I’m running on a little-endian machine 🙂)
So the value of `z` does remember that the sign bit was set. It just doesn’t get printed. Is this something that there is interest in fixing? I’m happy to look at it, but not if no one cares 🙂it looks like showing the sign of zero in the JS REPL is a semi-recent update, since this article claims the same happens in Node.js: https://2ality.com/2012/03/signedzero.html
> hm. it seems to be due to `.toString`
I agree, since the node repl (or my version of node anyway, which is v12.18.3) displays -0
for the value, but not when it’s converted to a string. I appreciate finding the difference for .toLocaleString
! I wouldn’t have thought to look for that.