[racket] Coerce Number to uint32

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jun 9 04:13:13 EDT 2012

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.