You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a safe-divide function returning ##Inf when dividing by zero.
(defnsafe-divide [a b]
(if (zero? b)
(if (neg? a)
##-Inf##Inf)
(/ a b)))
I'd like to have a version working with broch, but boxed-arithmetic only accepts a few functions from clojure.core.
I understand the logic behind that, but unfortunately writing my own custom boxed-arithmetic turns out to be quite difficult as most of the used functions are private.
Would it be possible to expose those functions?
Alternatively, perhaps boxed-arithmetic could expose two sub-functions where the user could do the dispatch manually?
Something like boxed-mult-div and boxed-add-sub-min-max.
The text was updated successfully, but these errors were encountered:
Hmm, I think you can get a version of your safe-divide for broch quantities using b/with-num to get the right unit for the given division (with 1/1 so it's a safe division) and then set the number to either ##Inf or ##-Inf.
(defndiv-derive [a b]
(b// (b/with-num a 1) (b/with-num b 1)))
(defnsafe-divide-b [a b]
(if (zero? (b/num b))
(let [inf (if (neg? (b/num a)) ##-Inf##Inf)]
(b/with-num (div-derive a b) inf))
(b// a b)))
(comment
(safe-divide-b (b/meters1) (b/seconds0)) ; => #broch/quantity[##Inf "m/s"]
(safe-divide-b (b/meters-1) (b/seconds0)) ; => #broch/quantity[##-Inf "m/s"]
)
I have a
safe-divide
function returning##Inf
when dividing by zero.I'd like to have a version working with
broch
, butboxed-arithmetic
only accepts a few functions fromclojure.core
.I understand the logic behind that, but unfortunately writing my own custom
boxed-arithmetic
turns out to be quite difficult as most of the used functions are private.Would it be possible to expose those functions?
Alternatively, perhaps
boxed-arithmetic
could expose two sub-functions where the user could do the dispatch manually?Something like
boxed-mult-div
andboxed-add-sub-min-max
.The text was updated successfully, but these errors were encountered: