[Haskell-cafe] Re: Desired behaviour of rounding etc.

Daniel Fischer daniel.is.fischer at web.de
Fri Oct 8 09:29:01 EDT 2010


On Friday 08 October 2010 14:08:01, Daniel Fischer wrote:
> On a related note, in my benchmarks,
>
> truncFloatGen :: Integral a => Float -> a
> truncFloatGen = fromInteger . truncFloatInteger
>
> truncFloatInteger :: Float -> Integer
> truncFloatInteger x =
>   case decodeFloat x of
>     (m,e) | e == 0  -> m
>           | e < 0   ->
>             let s = -e
>             in if m < 0
>                   then - ((-m) `shiftR` s)
>                   else m `shiftR` s
>           | otherwise -> m `shiftL` e
>
> is more than twice as fast as GHC.Float.float2Int, the corresponding for
> Double almost twice as fast as double2Int.
>
> Can anybody confirm that the above is faster than float2Int on other
> machines/architectures?

That one is more or less solved. For values inside the Int range, 
float2Int/double2Int are, as expected, much faster.
Only for values outside the Int range the picture changes, and I 
benchmarked over a much larger range.
Still odd that float2Int/double2Int degrade so badly outside the range.


More information about the Haskell-Cafe mailing list