This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-17
Channels
- # announcements (6)
- # babashka-sci-dev (6)
- # beginners (30)
- # cider (2)
- # clerk (34)
- # clj-kondo (2)
- # clojure (40)
- # clojure-europe (50)
- # clojure-germany (2)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-uk (2)
- # clojurescript (7)
- # conjure (2)
- # cursive (7)
- # events (3)
- # guix (1)
- # hyperfiddle (22)
- # lsp (2)
- # malli (3)
- # music (1)
- # off-topic (9)
- # re-frame (5)
- # reitit (3)
- # sql (1)
- # vim (3)
- # xtdb (5)
morgen!
What is the obvious thing I'm missing here?
(defn decimal-points [n points]
(double (.setScale (java.math.BigDecimal. n) points java.math.RoundingMode/HALF_UP)))
(comment
(with-precision 2 (double (/ 22 7)))
3.142857142857143 ;; not what I want
(decimal-points (double (/ 22 7)) 2)
3.14 ;; what I want
)
In the examples I see on Clojuredocs, using BigDecimal gets you what you want… I think.
(with-precision 3 (/ 22M 7))
;;=> 3.14M
you can't necessarily get a precise decimal value out of a base-2 floating point (i.e. double
) value ... BigDecimal is the way to go
then what am I doing wrong here?
(with-precision 2 101323.2345M)
101323.2345M
(with-precision 2 (java.math.BigDecimal. 101323.2345))
101323.234500000005937181413173675537109375M
(decimal-points 101323.2345 2)
101323.23
dunno... this works on the java8 repl i currently have open:
(-> (java.math.BigDecimal. 1.234567)
(.round (java.math.MathContext. 3))))
@U0525KG62 it seems to me like what you’re doing wrong is expecting with-precision
to work as intended 😅 I agree that it looks off!
obviously I can do the interop, but it feels like there is something in clojure that I should be using instead
ohhhhh... i see - you have to do an arithmetic op with BigDecimal
s for with-precision
to work:
;; no op - does nothing
(with-precision 1 3.123456789M) ;=> 3.123456789M
;; not a BigDecimal op - does nothing
(with-precision 2 (double (/ 22 7))) ;=> 3.142857142857143
;; does an op on BigDecimals - uses precision
(with-precision 1 (/ 1M 3)) ;=> 0.3M
(with-precision 1 (+ 3.123456789M 0)) ;=> 3M
;; sadly - does nothing
(with-precision 1 (+ 3.123456789M)) ;=> 3.123456789M
so really with-precision
is there to rescue you from an ArithmeticException
caused by a non-terminating expansion during BigDecimal
operations
What am I moaning about?
I just got an email from Netflix telling me to not forget finishing to watch a show
This sort of corporate nagging infuriates me
I’m already annoyed when they ask me what I thought about something cos they have made us think that our thoughts should be given to them for nothing
On some vague promises of improvements which have definitely not arrrived and I see no prospect of them arriving any time soon
When I get sent shit like that, I go straight to email preferences and disable everything. If they don’t allow that, I send them a GDPR threat 😛
I know what you mean and I could do all of that but I feel like that's a me solution to a them problem if you know what I mean
Make a piracy jar. Every time someone sends you a marketing email you didn't ask for, you put it in the piracy jar. Every time you need to torrent something without a guilty conscience, you remove an email from the piracy jar. Problem solved.
Now we all have problems 🙂
I feel like a daily 🧵 on my whinges over here might at least let some of the pressure out. And sorry @U0525KG62 I can't be 🍑 'd with Mastadon.
@U04V5V0V4 I like to think you are doing that to help support older Mastodons that are out there.
I'm aware that it's a silly test, but it's an existing, flaky test that I want to fix up.
The existing test just assumes that time has passed, which it sometimes has, sometimes hasn't.
Optimally I'd be able to with-redef
some kind of central time-taking thing. I could redefine java.time.Instant/now
but that's pretty implementation-specific
You could use Clock for that. In the „prod part“ it just can run with the System time, while you can set it to fixed time for the test and manipulate it
You would then create Instant/now with the clock as a parameter. The downside is, that then you have to provide the clock from the outside, so you can switch it in the test
That is a nice style imo but if you don’t want to thread it through, make the clock a dynamic binding and rebind it in your tests
@mccraigmccraig I ❤️ helix. You’ll have fun 🙂
i've been working on an app with local-first (SQLite/IndexedDB based) persistence... using hooks with promises for db queries seemed to make a lot more sense than awkward event flows copying data over to a re-frame app-db
... and once you've drunk the hooks kool-aid then helix starts to look rather more elegant than reagent
the local-first storage stuff was for a rewrite of the yapster app in RN ... right now i'm looking at helix for a mini-webapp to support users who have forgotten their yapster login details, and after the less than stellar reagent+hooks experience i thought i would take helix for a spin