[Cs254f11] safe casting

Lee Spector lspector at hampshire.edu
Thu Dec 8 16:23:10 EST 2011


FWIW this is something that may be somewhat different between Clojure 1.2 and 1.3 -- at least there were changes in some related issues. The messiness here stems in part from the mismatch between the flexible, arbitrary-sized numeric representations that Lisps have generally had and the more traditional and limited numeric representations of Java.

 -Lee

On Dec 8, 2011, at 2:20 PM, Wm. Josiah Erikson wrote:

> Hey guys,
>    I was having trouble with my error routine occasionally throwing things like "IllegalArgumentException java.lang.IllegalArgumentException: Value out of range for long" because I was casting things to an int first (then I got lots of errors like this), then to a long (in an attempt to get rid of the problem), because I wanted to remove the decimals, but then I discovered unchecked-int, which casts to an int and just truncates it if it doesn't fit. Nice. And fine, since it's just the output of my error routine, and if that is too big to fit in an int, well then it's just really really bad, and we already knew that :)
> 
>    In case it's helpful for anyone else.
>    -Josiah
> 
> _______________________________________________
> Cs254f11 mailing list
> Cs254f11 at lists.hampshire.edu
> https://lists.hampshire.edu/mailman/listinfo/cs254f11

--
Lee Spector, Professor of Computer Science
Cognitive Science, Hampshire College
893 West Street, Amherst, MA 01002-3359
lspector at hampshire.edu, http://hampshire.edu/lspector/
Phone: 413-559-5352, Fax: 413-559-5438



More information about the Cs254f11 mailing list