Skip to content

Commit

Permalink
Rounding mode parsing is now able to use evaluated results of the giv…
Browse files Browse the repository at this point in the history
…en S-exp
  • Loading branch information
siefca committed Jul 13, 2021
1 parent 73986c4 commit f28bac7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/io/randomseed/bankster/scale.clj
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,14 @@
java.math.RoundingMode/mode."
{:tag RoundingMode :added "1.0.0" :no-doc true}
[n]
(let [rn (if (simple-ident? n) (name n) n)
rn (if (and (string? rn) (str/starts-with? rn "ROUND_")) (subs rn 6) rn)]
(or (when (string? rn)
(try (when (some? (RoundingMode/valueOf ^String rn))
(symbol "java.math.RoundingMode" rn))
(catch IllegalArgumentException e nil)))
n)))
(if (instance? RoundingMode n) n
(let [rn (if (simple-ident? n) (name n) n)
rn (if (and (string? rn) (str/starts-with? rn "ROUND_")) (subs rn 6) rn)]
(or (when (string? rn)
(try (when (some? (RoundingMode/valueOf ^String rn))
(symbol "java.math.RoundingMode" rn))
(catch IllegalArgumentException e nil)))
n))))

(defmacro with-rounding
"Sets the rounding mode for operations on scaled values.
Expand All @@ -585,7 +586,7 @@
{:added "1.0.0"}
[rounding-mode & body]
(let [rms# (parse-rounding rounding-mode)]
`(binding [*rounding-mode* ~rms#]
`(binding [*rounding-mode* (parse-rounding ~rms#)]
~@body)))

(defmacro with-rescaling
Expand All @@ -608,7 +609,7 @@
([rounding-mode & body]
(let [rms# (parse-rounding rounding-mode)]
`(binding [*each* true
*rounding-mode* ~rms#]
*rounding-mode* (parse-rounding ~rms#)]
~@body))))

(defmacro each
Expand Down

0 comments on commit f28bac7

Please sign in to comment.