I think I found a bug with pr-ing a negative zero number in CLJS:
JVM Clojure:
user=> (prn -0.0)
-0.0
CLJS:
cljs.user=> (prn -0.0)
0
This causes a real bug for me. Issue+patch welcome @dnolen?@quoll btw, are you a contact point for minor improvements to clojure.math?
It's part of ClojureScript proper now, which has always required David's approval, but sure.
Did I miss something?
FWIW, CLJS's clojure.math mirrors Clojure JVM's clojure.math so I think that should be the first point of contact
as in #clojure-dev
I wouldn’t say that you missed anything, but there are a couple of “nice to haves” that I would like to drop in if it isn’t objectionable to the team. 🙂
I remember hitting this one when working on math.
The simplest approach is updating the cond in pr-writer-impl with:
(number? obj)
(-write writer
(cond
(js/isNaN obj) "##NaN"
(identical? obj js/Number.POSITIVE_INFINITY) "##Inf"
(identical? obj js/Number.NEGATIVE_INFINITY) "##-Inf"
(js/Object.is obj -0.0) "-0"
:else (str_ obj)))
But I didn't know how well it could go over at the time. (updating core, and potentially breaking user code)It's possible to use (and (zero? obj) (neg? (math/copy-sign 1 obj))) but that's utterly irrational 🙂
I've already applied a patch and indeed landed on the same approach.
What's also possible is: (neg? (/ obj)) - I came across this elsewhere. http://Object.is is only available since ES6 which is now the base target for CLJS since the last few releases, we couldn't use that before.
You can also use (identical? ##-Inf (/ 1 obj))
I think http://Object.is is the most clearest :)
yes
https://clojure.atlassian.net/browse/CLJS-3471 Also discovered tools.reader doesn't read negative zero correctly in CLJS. I'll make a separate ticket for that and fix that tomorrow
There's also this one I mentioned, less important: https://clojurians.slack.com/archives/C07UQ678E/p1769252416934779