Skip to content

Commit

Permalink
Fix false-negative test for (long Float/MAX_VALUE) and (long Double/M…
Browse files Browse the repository at this point in the history
…AX_VALUE). Fix unintentionally unchecked conversion of decimal objects to long.

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
Alexander Taggart authored and stuarthalloway committed May 6, 2011
1 parent 6fb09f4 commit bf22d2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/jvm/clojure/lang/RT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,12 @@ else if (x instanceof BigInteger)
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){
Expand Down
2 changes: 1 addition & 1 deletion test/clojure/test_clojure/numbers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down

0 comments on commit bf22d2a

Please sign in to comment.