Fork me on GitHub
#clojure
<
2024-03-03
>
evocatus08:03:53

I was discussing Clojure with someone on Reddit and they told me there are no unsigned 64-bit integers in Java and consequently in Clojure. Ho do you solve it? Or just using signed 64-bit numbers? Looks like Clojure silently fallbacks to BigInt:

user=> (def x 2)
#'user/x
user=> (type x)
java.lang.Long
user=> (def y 18446744073709551615)
#'user/y
user=> (type y)
clojure.lang.BigInt

Bailey Kocin18:03:25

1. Use the signed numbers to emulate the bigger unsigned numbers see here https://stackoverflow.com/questions/397867/port-of-random-generator-from-c-to-java/397997#397997 2. Use a language with 64 bit unsigned support like Rust or Go or C++ But I guess what do you mean by “how do you solve it”?

Adam Mertzenich19:03:22

The Long class has some operations that may help with treating them as unsigned, though it may be a bit clunky and Bailey is right in raising the issue of using the right tool (language) for the job https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Long.html (ctr+f unsigned)