YW.
Though, you might want to refine it a bit to support BigDecimal and avoid
reflection.
(defn abs [x]
(cond
(instance? BigDecimal x)
(let [^BigDecimal x x]
(.abs x))
(instance? Double x)
(let [^Double x x]
(Math/abs x))
(instance? Float x)
(let [^Float x x]
aww cool! thanks Cedric :)
On 28/05/13 18:02, Cedric Greevey wrote:
(defn acmp [a1 a2 tolerance]
(every? #(< % tolerance)
(map #(Math/abs (- %1 %2)) (seq a1) (seq a2
user=> (acmp (double-array [0.01 0.7 2.2])
(double-array [0.011 0.695 2.199])
0.01)
true
use
(defn acmp [a1 a2 tolerance]
(every? #(< % tolerance)
(map #(Math/abs (- %1 %2)) (seq a1) (seq a2
user=> (acmp (double-array [0.01 0.7 2.2])
(double-array [0.011 0.695 2.199])
0.01)
true
user=> (acmp (double-array [0.01 0.7 2.2])
(double-array [0.01
ooo thanks Chris! I was suspecting the exact same thing because I tried
this:
(is (= (seq (aget ready 0))
(seq (aget ready 1
and got this:
expected: (= (seq (aget ready 0)) (seq (aget ready 1)))
actual: (not (= (-0.5345224838248488 0.2672612419124244
0.801783725737273*1*)
It doesn't seem to be in the published javadoc, but this is an array
comparison with an epsilon tolerance, which was likely added after the
published javadoc was generated. 0.01 here is the maximum permitted
absolute difference between each compared number.
https://github.com/junit-team/junit/blo
Hi everyone,
sometimes I feel really stupid!
I am currently looking at a well-known java library's tests and found this:
Assert.assertArrayEquals(arrayOutput[0], arrayOutput[1], 0.01);
//arrayOutput is a 2d double-array btw
since I've basically wrapped this lib, I'd like to port the java tes