[racket] Coerce Number to uint32

From: Vincent K (vince.raiken at gmail.com)
Date: Sat Jun 9 08:52:16 EDT 2012

That worked, thank you so much! I'm curious though, why does that work? By all rights that seems to basically be a no-op, due to it ending up with the same value it had before. Am I missing something, or is this just how Racket works?

On Jun 9, 2012, at 4:13 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:

> At Sat, 9 Jun 2012 02:42:43 -0400, Vince Kuyatt wrote:
>> While working on the Rhipmunk FFI, I ran into a definition called
>> "NOT_GRABABLE_MASK", which as far as I can tell, is defined as:
>> #define GRABABLE_MASK (1<<31)
>> The problem with this, is that when I do the same operations:
>> (define GRABABLE_MASK (int->uint (arithmetic-shift 1 31)))
>> (define NOT_GRABABLE_MASK (bitwise-not GRABABLE_MASK))
>> I get an error thrown back at me when I use it in one of the Chipmunk
>> functions:
>> Scheme->C: expects argument of type <uint32>; given -2147483649
>> How can I coerce the definitions of those two masks so that they will be a
>> uint32 that I can pass to the Chipmunk API?
> I think you want
> (define (sint32->uint32 v)
>   (bitwise-and #xFFFFFFFF v))

Posted on the users mailing list.