This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-26
Channels
- # aleph (3)
- # announcements (6)
- # babashka (14)
- # beginners (8)
- # biff (16)
- # calva (4)
- # cider (7)
- # clj-kondo (8)
- # cljs-dev (26)
- # clojure (65)
- # clojure-austin (2)
- # clojure-brasil (1)
- # clojure-europe (35)
- # clojure-nl (4)
- # clojure-norway (45)
- # clojure-portugal (1)
- # clojure-uk (9)
- # clr (5)
- # community-development (6)
- # conjure (1)
- # cursive (3)
- # events (8)
- # fulcro (1)
- # honeysql (19)
- # hyperfiddle (31)
- # introduce-yourself (1)
- # lsp (7)
- # matcher-combinators (10)
- # off-topic (17)
- # practicalli (1)
- # ring (30)
- # shadow-cljs (6)
- # testing (2)
Experimenting w/ BigInt support - https://github.com/clojure/clojurescript/pull/214
fairly low impact, as there's no direct reference to BigInt anywhere and you have to configure Closure to handle it
but if you set it up - it's pretty cool, 1N
or Long constant values bigger than JS max safe integer values - are emitted as BigInt
I pondered the Clojure numeric tower a bit - but after writing pages and pages of notes - I'm not so convinced about creating confusion about numerical interop
in the end JavaScript only really has Number (Double) and BigInt - trying to pretend otherwise just seems more like more trouble at the moment
re: numeric tower, my primary thought is that Ratio really exists because of Java loss of precision when dividing primitive integral types - however JS choice to use Double was more or less a simplification to avoid that particular footgun from the start
hmm i dont understand the latter bit, doesnt JS also have loss of precision in that case?
The way I understand Clojure’s Ratio is that it defaults to BigInt to simplify the types involved with rationals. e.g. in Common Lisp, the numerator and denominator of a rational is the integer
type, which includes everything from bits to bignums, so forms like (+ 1/2 1/2)
will evaluate to a value of type bit
. I assume the choice of BigInt in Clojure is to have this sort of flexibility (though there is no way to statically determine if a part in a Clojure ratio may be represented with a fixnum, i.e. the most we can assume out of (+ 1/2 1/2)
in clojure is that we have a BigInt
)
hmm i dont understand the latter bit, doesnt JS also have loss of precision in that case?
The way I understand Clojure’s Ratio is that it defaults to BigInt to simplify the types involved with rationals. e.g. in Common Lisp, the numerator and denominator of a rational is the integer
type, which includes everything from bits to bignums, so forms like (+ 1/2 1/2)
will evaluate to a value of type bit
. I assume the choice of BigInt in Clojure is to have this sort of flexibility (though there is no way to statically determine if a part in a Clojure ratio may be represented with a fixnum, i.e. the most we can assume out of (+ 1/2 1/2)
in clojure is that we have a BigInt
)
this is true, but defaulting to Double in JS prevents basic nasty stuff like 1/2
and then doing some say iteration bounding on that result
the big problem for numeric tower is that in JS you cannot generically combine BigInt
and Number
Clojure's numeric tower could be summarized Long
-> BigInt
-> Ratio
-> Double
-> BigDecimal
I think.
the other thing which is practical is that the numeric tower in Clojure involves a lot of code and everything references everything
re: bigint: ah right, numbers are technically all doubles, and integers go up to whatever the length of a double’s mantissa is… so we cant just promote Number to BigInt when mixing them like in Java, or else we could be taking in a number with a fractional part and lose it
in that case i think youre right that cljs should just stick with the js limitations and not try to brush it over