Details
-
Type:
Defect
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: Release 1.6
-
Component/s: None
-
Labels:None
-
Patch:Code and Test
-
Approval:Ok
Description
The bigint and biginteger functions throw on double values outside of long range
This works fine:
user> (bigint (* 0.99 Long/MAX_VALUE))
9131138316486227968N
but passing any Float or Double values outside the range of a long throw an exception:
user> (bigint (* 1.01 Long/MAX_VALUE)) IllegalArgumentException Value out of range for long: 9.315605757223324E18 clojure.lang.RT.longCast (RT.java:1178)
Cause: bigint and biginteger cover a series of possible input cases but did not have an explicit case for Float or Double, so was falling back to default.
Solution: Add check for Float/Double case that coerces the input to double, then uses BigDecimal.valueOf(), then converts to a BigInteger and so on as with other types.
Patch: clj-1197-make-bigint-work-on-all-doubles-v1.txt
Cleaned up the description a bit.