[MLton-user] IEEEReal rounding not working

Matthew Fluet fluet at tti-c.org
Fri Jul 27 09:39:44 PDT 2007


On Thu, 26 Jul 2007, Matthew Fluet wrote:
> I checked in the change to the treatment of floating-point operations; it has 
> a negligible effect on the floating-point intensive benchmarks.

While this change produces the correct behavior with the native codegen, 
it still produces the incorrect behavior with the C codegen.  The reason 
is that, as I mentioned previously, with the C codegen, we 
consant-propagate global floating-point constants into the generated C 
code.  So, gcc sees repeated "1.0 / 10.0" operations, and does constant 
folding at compile-time (with round to nearest semantics).

Gcc will also constant fold "(float)2147483647", which should depend on 
the rounding mode (as the integer can't be exactly represented as a 32-bit 
floating point value).

The solution is to not constant-propagate floating point constants into 
the generated C code and to make the Word{S,U}<N>_rndToReal<M> primitives 
non-inlined (since the word constants are constant-propagated).




More information about the MLton-user mailing list