I have a following sample of code:
(type (apply / [5.0 0]))
It throws an unexpected error - "Division By Zero" (expected behavior: return Inf)
Probably, it happens due to auto-boxing - can it be prevented?
I have a following sample of code:
(type (apply / [5.0 0]))
It throws an unexpected error - "Division By Zero" (expected behavior: return Inf)
Probably, it happens due to auto-boxing - can it be prevented?
Assuming you just want to use a two argument division on doubles, the following might work.
user=> (apply (fn d2div [n d] (double (/ (double n) (double d)))) [5.0 0.0])
##Inf
If you go down this path, check out clj-cmmons/primitive-math
.
How about
user=> (defmacro myapply [func args] `(~func ~@args))
#'user/myapply
user=> (myapply / [5.0 0])
##Inf
user=> (type (myapply / [5.0 0]))
java.lang.Double
I didn't know that apply
behaves in such a different manner in Clojure.