[Haskell-cafe] Re: Why 'round' does not just round numbers ?

Sterling Clover s.clover at gmail.com
Fri Oct 31 20:41:50 EDT 2008

On Oct 30, 2008, at 5:21 PM, Bertram Felgenhauer wrote:

> George Pollard wrote:
>> There's also the ieee-utils package, which provides an IEEE monad  
>> with
>> `setRound`:
>> http://hackage.haskell.org/packages/archive/ieee-utils/0.4.0/doc/ 
>> html/Numeric-IEEE-RoundMode.html

> When run with +RTS -N2 -RTS, the output randomly alternates
> between Downward and ToNearest - for me at least.
> The problem is that the setRound call will only affect one worker
> thread, while the RTS will sometimes migrate RTS threads from one
> worker to another.
> runIEEE really has to be executed in a bound thread (see forkOS
> documentation). Using `par` will also cause trouble - in fact even
> more.

That's a really nice catch!

Dons has pointed out to me both the very handy forkOnIO which ensures  
the forked thread remains bound to a single CPU, and also the -qm  
flag to the RTS, which prevents thread migration between  
capabilities. Running the example program with +RTS -N2 -qm restores  
the behavior to what's intended. I'll try to get around to changing  
the documentation to reflect this. Also, it's worth noting that the  
IEEE round mode has no effect on rounding done with the `round`  
function, as that's explicitly coded to provide the behavior seen in  
the report.


More information about the Haskell-Cafe mailing list