[racket] Optimization; converting 'Float' to 'Fixnum' in Typed Racket

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Sat Feb 18 23:22:46 EST 2012

At Sat, 18 Feb 2012 21:47:52 -0600,
Robby Findler wrote:
> On Sat, Feb 18, 2012 at 9:39 PM, SF <sf.rom17 at gmail.com> wrote:
> > On Sat, Feb 18, 2012 at 9:18 PM, Robby Findler wrote:
> >> I'm not sure of the precise answer, but I don't think that all floats
> >> (even the integers) have a corresponding fixnum.
> >
> > My C brain wonders why I can't just cast it to get the lower bits, I
> > don't care about overflow.
> I'm not sure if this will fit in with how Typed Racket works, but I
> guess you could write an ffi-based function that actually fiddles with
> the low-level representation to just get at the bits you want.
> But, actually, I think that maybe that won't work because Racket's
> floats are usually boxed, unless the compiler can "see" everywhere
> they go and can manage to pass around unboxed versions (something that
> TR facilitates, I believe). So, if you were to pass them off to an
> unknown (from the compiler & TR's perspective) function, then they'd
> fall back to boxing and you'd lose all the efficiency gains.
> I guess there would have to be some new primitive added to make this work.
> Of course, I could be missing out on one of the existing prims. Maybe
> one of the TR/runtime system experts'll fill us in.

`fl->fx' does what he wants, but only if the input float actually
represents an integer.


Posted on the users mailing list.