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

From: SF (sf.rom17 at gmail.com)
Date: Sat Feb 18 21:07:05 EST 2012

I'm trying to optimize some code that processes a bunch of data,
basically image pixels, which currently takes on the order of several
seconds and seems like it should be much faster (important because
it's an interactive application). Coming from C++ I have a good idea
in my mind of how I'd write it with low-level operations. I read up on
Racket optimization. It is still somewhat unclear to me how Racket
deals with fixnums, flonums, unsafe operations, Typed Racket types,
and how it all fits together. I chose to optimize my program (partly
to learn how) incrementally, trying all the options, timing at every
step with debugging info turned off. This worked until I wanted to
convert Integers to Fixnums in Typed Racket (which has been giving me
much faster results than anything in untyped Racket).

The problem is that I can't find a way to convert a Float to a Fixnum,
only to an Integer. None of fl->fx, unsafe-fl->fx, or
fl->exact-integer work, as Type Checker tells me they're untyped
identifiers. Strangely, it doesn't complain with other things from
racket/unsafe/ops and racket/fixnum. Ideally, it'd be nice to have a
function that works like a cast in C++, rounding down the float to get
an int efficiently. Should I not be trying to use Fixnums? Are they
just as efficient as Integers? Using a C module is one possible
solution, are there any others? Would love some light shed on this

Posted on the users mailing list.