summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen C. Gilardi <squeegee@squeegee-mbp.scgilardi.selfip.net>2009-06-30 13:00:04 -0400
committerChouser <chouser@n01se.net>2009-07-09 23:21:37 -0400
commitab7947e68a5b435f243790e197cfdb781d47986f (patch)
tree62171ddf2c21bf5532e41cbfcd172d29d22ca599
parenta1397390d8b3b63f2039359520629d87b152d717 (diff)
Refs #137: make *math-context* settable, with test + tests of with-precision
Signed-off-by: Chouser <chouser@n01se.net>
-rw-r--r--src/clj/clojure/main.clj7
-rw-r--r--test/clojure/test_clojure/vars.clj21
2 files changed, 24 insertions, 4 deletions
diff --git a/src/clj/clojure/main.clj b/src/clj/clojure/main.clj
index 6bd798da..58fa0a3f 100644
--- a/src/clj/clojure/main.clj
+++ b/src/clj/clojure/main.clj
@@ -16,12 +16,13 @@
(defmacro with-bindings
"Executes body in the context of thread-local bindings for several vars
- that often need to be set!: *ns* *warn-on-reflection* *print-meta*
- *print-length* *print-level* *compile-path* *command-line-args* *1
- *2 *3 *e"
+ that often need to be set!: *ns* *warn-on-reflection* *math-context*
+ *print-meta* *print-length* *print-level* *compile-path*
+ *command-line-args* *1 *2 *3 *e"
[& body]
`(binding [*ns* *ns*
*warn-on-reflection* *warn-on-reflection*
+ *math-context* *math-context*
*print-meta* *print-meta*
*print-length* *print-length*
*print-level* *print-level*
diff --git a/test/clojure/test_clojure/vars.clj b/test/clojure/test_clojure/vars.clj
index 12e8a60c..540495f3 100644
--- a/test/clojure/test_clojure/vars.clj
+++ b/test/clojure/test_clojure/vars.clj
@@ -21,10 +21,29 @@
(def a)
(deftest test-binding
- (are (= _1 _2)
+ (are [_1 _2] (= _1 _2)
(eval `(binding [a 4] a)) 4 ; regression in Clojure SVN r1370
))
+(deftest test-with-precision
+ (are [x y] (= x y)
+ (with-precision 4 (+ 3.5555555M 1)) 4.556M
+ (with-precision 6 (+ 3.5555555M 1)) 4.55556M
+ (with-precision 6 :rounding CEILING (+ 3.5555555M 1)) 4.55556M
+ (with-precision 6 :rounding FLOOR (+ 3.5555555M 1)) 4.55555M
+ (with-precision 6 :rounding HALF_UP (+ 3.5555555M 1)) 4.55556M
+ (with-precision 6 :rounding HALF_DOWN (+ 3.5555555M 1)) 4.55556M
+ (with-precision 6 :rounding HALF_EVEN (+ 3.5555555M 1)) 4.55556M
+ (with-precision 6 :rounding UP (+ 3.5555555M 1)) 4.55556M
+ (with-precision 6 :rounding DOWN (+ 3.5555555M 1)) 4.55555M
+ (with-precision 6 :rounding UNNECESSARY (+ 3.5555M 1)) 4.5555M))
+
+(deftest test-settable-math-context
+ (is (=
+ (clojure.main/with-bindings
+ (set! *math-context* (java.math.MathContext. 8))
+ (+ 3.55555555555555M 1))
+ 4.5555556M)))
; with-local-vars var-get var-set alter-var-root [var? (predicates.clj)]
; with-in-str with-out-str