On Feb 12, 2011, at 6:53 AM, Aaron Cohen wrote:
On Sat, Feb 12, 2011 at 8:28 AM, timc <timgcl...@gmail.com> wrote:
Further investigation reveals that
(def b (byte i))
is doing something equivalent to this internally:
byte b = Byte.parseByte(String.format("%d",i));
which does indeed throw a NumberFormatException if the decimal
integer
representation given to it produces an out-of-range value (as it
should).
So - what I'm pleading for, is that (byte b) and (int i), (short s),
etc. should simply perform a masking operation (on the appropriate
number of least significant bits) in the way that java clearly does.
For the record, unchecked coercions are in progress:
http://dev.clojure.org/jira/browse/CLJ-441
And until those are available, I have sometimes worked around it by
making a tiny function that takes an int in the range 0..255 and
returns a byte:
(defn ubyte [val]
(if (>= val 128)
(byte (- val 256))
(byte val)))
Andy
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en