data-science

Data science, data analysis, and machine learning in Clojure https://scicloj.github.io/pages/chat_streams/ for additional discussions
Santiago 2019-12-31T10:49:35.004600Z

I tried to round a number yesterday and it was very frustrating, ended up using a string and then reconverting. How do you do it?

zane 2020-01-02T00:05:22.010600Z

Forgive me if you're already aware, but depending on your needs you might not need to reach for a library like fastmath. Math/round is from Java's standard library works for many use cases.

$ clj
Clojure 1.10.1
user=> (Math/round 0.7)
1

genmeblog 2019-12-31T11:51:53.005500Z

I use Apache Commons Math for that, but you can adapt the code from their strategies.

chrisn 2019-12-31T14:38:12.007500Z

Well, @slack.jcpsantiago or you can use the fastmath clojure library where @tsulej has already carefully gone through a bunch of libraries and curated the fastest paths out of them for various forms of arithmetic: https://github.com/generateme/fastmath

genmeblog 2019-12-31T15:31:52.009600Z

haha, yes, fastmath exposes what I've mentioned above as round, rint, and approx

Santiago 2019-12-31T16:16:25.010100Z

Nice thank you both, I'll check it out