Skip to content
Snippets Groups Projects
Commit 0120e0be authored by Simon Belak's avatar Simon Belak
Browse files

Fix growth when current period is 0

parent c98e9404
No related branches found
No related tags found
No related merge requests found
......@@ -49,13 +49,12 @@
(defn growth
"Relative difference between `x1` an `x2`."
[x2 x1]
(when (and x1 x2)
(when (and x1 x2 (not (zero? x1)))
(let [x2 (double x2)
x1 (double x1)]
(cond
(every? neg? [x1 x2]) (growth (- x1) (- x2))
(and (neg? x1) (pos? x2)) (- (growth x1 x2))
(nil? x1) nil
:else (/ (* (if (neg? x1) -1 1) (- x2 x1)) x1)))))
(defn- merge-juxt
......
......@@ -20,12 +20,20 @@
1.0
-0.5
-5.0
5.0]
5.0
2.0
nil
nil
nil]
[(growth 123 100)
(growth -0.1 -0.2)
(growth -0.4 -0.2)
(growth -0.4 0.1)
(growth 0.1 -0.4)])
(growth 0.1 -0.4)
(growth Long/MAX_VALUE Long/MIN_VALUE)
(growth 0.1 nil)
(growth nil 0.5)
(growth 0.5 0.0)])
(expect
[{:foo 2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment