I never said automatic overflowing is a good thing per se.

The problem is that the expectations set by hexadecimal notation are
violated. When I write 0xFF, I don't mean the abstract mathematical
number 255; I mean the number whose bit representation (e.g. one's
complement for signed integers) has the 8 least significant bits set
to 1 and any higher bits set to 0. Unfortunately this isn't a single
definite number but depends on the type. For signed bytes it is -1 but
for shorts, ints and longs it is 255. In a statically typed language
like Java, the compiler can treat a hexadecimal literal like 0xFF
initially as uninterpreted bits and then interpret it appropriately at
different types. In a low-level sense, this works out to simple bit
truncation ("automatic overflow").

-Per

On Wed, Mar 24, 2010 at 1:19 PM, ataggart <alex.tagg...@gmail.com> wrote:
> It was added here: 
> http://github.com/richhickey/clojure/commit/d0e1eef26abd215668ed27357839b2bba4ba095c
>
> Not automatically overflowing numbers is a Good Thing.  For example:
> http://seclists.org/fulldisclosure/2010/Mar/447
>
> Though the behavior now deviates from the java casting behavior where
> the more significant bits are just truncated.  I can't think of many
> cases where a downcast is used *and* the original value is expected to
> ever be larger than the target type.  If you really need that, then
> bit-masking prior to casting seems appropriate.
>
>
>
> On Mar 23, 7:41 am, Per Vognsen <per.vogn...@gmail.com> wrote:
>> Interesting. It's Clojure 1.2.0-master-SNAPSHOT as of last week:
>>
>> Clojure 1.2.0-master-SNAPSHOT
>> user=> 0xff
>> 255
>> user=> (byte 0xff)
>> java.lang.IllegalArgumentException: Value out of range for byte: 255
>> (NO_SOURCE_FILE:0)
>>
>> So, this looks like a new issue. Rich?
>>
>> -Per
>>
>> On Tue, Mar 23, 2010 at 8:39 PM, Mark J. Reed <markjr...@gmail.com> wrote:
>>
>>
>>
>> > On Tue, Mar 23, 2010 at 8:40 AM, Per Vognsen <per.vogn...@gmail.com> wrote:
>> >> Sorry, I didn't put that right. 0xFF would only be -1 as a signed
>> >> byte. What I'm saying is that the interaction between the type system
>> >> of integers and the reader's hexadecimal notation is pretty surprising
>> >> to me. In particular, (byte 0xFF) throws an error.
>>
>> > What version?  It works here:
>>
>> > Clojure 1.1.0
>> > user=> (byte 0xff)
>> > -1
>>
>> > In fact, it seems that (byte) doesn't check the range at all:
>>
>> > user=> (byte -129)
>> > 127
>>
>> > --
>> > Mark J. Reed <markjr...@gmail.com>
>>
>> > --
>> > 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
>>
>> > To unsubscribe from this group, send email to 
>> > clojure+unsubscribegooglegroups.com or reply to this email with the words 
>> > "REMOVE ME" as the subject.
>
> --
> 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
>
> To unsubscribe from this group, send email to 
> clojure+unsubscribegooglegroups.com or reply to this email with the words 
> "REMOVE ME" as the subject.
>

-- 
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

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to