summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Taggart <alex.taggart@expojure.com>2011-04-25 13:52:22 -0700
committerStuart Halloway <stu@thinkrelevance.com>2011-05-06 09:44:37 -0400
commitbf22d2a456909f40faa03f87e9509ff28b96abe0 (patch)
tree7fe382ca050ed05462373c9280bdfdcad1a48c61
parent6fb09f402c5448070a2efc64ebd64285480b263f (diff)
Fix false-negative test for (long Float/MAX_VALUE) and (long Double/MAX_VALUE). Fix unintentionally unchecked conversion of decimal objects to long.
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--src/jvm/clojure/lang/RT.java7
-rw-r--r--test/clojure/test_clojure/numbers.clj2
2 files changed, 7 insertions, 2 deletions
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index c467d31e..d19319e0 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -1000,7 +1000,12 @@ static public long longCast(Object x){
else
throw new IllegalArgumentException("Value out of range for long: " + x);
}
- return ((Number) x).longValue();
+ else if (x instanceof Byte || x instanceof Short)
+ return ((Number) x).longValue();
+ else if (x instanceof Ratio)
+ return longCast(((Ratio)x).bigIntegerValue());
+ else
+ return longCast(((Number)x).doubleValue());
}
static public long longCast(int x){
diff --git a/test/clojure/test_clojure/numbers.clj b/test/clojure/test_clojure/numbers.clj
index 301f6e4a..08cf60c2 100644
--- a/test/clojure/test_clojure/numbers.clj
+++ b/test/clojure/test_clojure/numbers.clj
@@ -106,7 +106,7 @@
[unchecked-short [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE -1 -1 -1 -1]]
[int [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE :error :error :error]]
[unchecked-int [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE -1 Integer/MAX_VALUE Integer/MAX_VALUE]]
- [long [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE Long/MAX_VALUE Long/MAX_VALUE Long/MAX_VALUE]]
+ [long [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE Long/MAX_VALUE :error :error]]
[unchecked-long [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE Long/MAX_VALUE Long/MAX_VALUE Long/MAX_VALUE]]
;; 2.14748365E9 if when float/double conversion is avoided...
[float [-1.0 0.0 1.0 127.0 32767.0 2.147483648E9 9.223372036854776E18 Float/MAX_VALUE :error]]