[MLton] Re: [MLton-commit] r4672

Matthew Fluet fluet@cs.cornell.edu
Tue, 4 Jul 2006 17:55:41 -0400 (EDT)


> Went back to real primitives nextAfter{Down,Up} in place of nextAfter.
> These primitives work nicely without requiring the platform to have
> the C nextafter function (e.g. old Solaris).  And, they have a very
> simple implementation that meshes well with the SML code doing the
> special-case checks for nan, inf, and zero.  Someday, these C routines
> might go away when we have a faster PackReal and PackWord.  But the C
> code is so simple it will be impressive if we can ever get MLton to
> produce equivalently good code.

I don't see why MLton won't produce equivalently good code.  As I said 
before (http://mlton.org/pipermail/mlton/2006-May/028852.html):

   [BTW, what we really need are bitwise coercions between Real64.real and
   Word64.word and Real32.real and Word32.word.  Then the PackReal*
   structures can be implemented using the PackWord* structures.  Also, it
   would be nice to have the coercions for other things: doing sign and class
   functions in ML, rather than via C-functions.]

So, implementing nextAfter{Down,Up} wouldn't need to bounce through 
PackReal/PackWord ops:

fun nextAfterUp r =
   let val w = Primitive.Real64.toWord64 r
       val w' = Word64.+ (w, 0wx1)
       val r' = Primitive.Real64.fromWord64 w'
   in
       r'
   end

I think that will be just as good as the C-function (and better, since 
it'll be inlined).