diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-04-09 12:10:31 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-04-09 12:10:31 +0000 |
commit | 3c6ffedd187e69c824c5bfb7251a8a9de0cb3cca (patch) | |
tree | 511c1775a4299ac1aa89b5032eaf68d058d6cfbc | |
parent | 182e2a0458c8c13704b6de0d235792cbd5e7ae63 (diff) |
Moved MathContext creation to runtime in with-precision
-rw-r--r-- | src/boot.clj | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/boot.clj b/src/boot.clj index 15323ab9..e52d07e7 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -2286,18 +2286,17 @@ not-every? (comp not every?)) `(sync nil ~@exprs)) (defmacro with-precision - "Sets the precision and rounding mode to be used for BigDecimal operations. - Usage: (with-precision 10 (/ 1M 3)) + "Sets the precision and rounding mode to be used for BigDecimal operations. + + Usage: (with-precision 10 (/ 1M 3)) or: (with-precision 10 :rounding HALF_DOWN (/ 1M 3)) - The rounding mode is one of CEILING, FLOOR, HALF_UP, HALF_DOWN, HALF_EVEN, - UP, DOWN and UNNECESSARY; it defaults to HALF_UP." + + The rounding mode is one of CEILING, FLOOR, HALF_UP, HALF_DOWN, + HALF_EVEN, UP, DOWN and UNNECESSARY; it defaults to HALF_UP." [precision & exprs] - (let [[body mc] - (if (= (first exprs) :rounding) - [(rest (rest exprs)) - (java.math.MathContext. precision - (. clojure.lang.Reflector getStaticField java.math.RoundingMode (name (second exprs))))] - [exprs - (java.math.MathContext. precision)])] - `(binding [*math-context* ~mc] - ~@body)))
\ No newline at end of file + (let [[body rm] (if (= (first exprs) :rounding) + [(rest (rest exprs)) + `((. java.math.RoundingMode ~(second exprs)))] + [exprs nil])] + `(binding [*math-context* (java.math.MathContext. ~precision ~@rm)] + ~@body)))
\ No newline at end of file |