[Haskell-cafe] fast fractional part of floating point number - modf?

Henning Thielemann lemming at henning-thielemann.de
Sat Jan 12 19:08:49 EST 2008

Is there a fast and reliable way to compute the fraction of a floating
point number?

I can implement
  fraction x = snd (properFraction x :: (Int, Double))
  fraction x = x - fromIntegral (truncate x :: Int)
      (actually I need 'floor' not 'truncate' but this is another issue)
but these need considerably more time than
  fraction x = x - GHC.Float.int2Double (GHC.Float.double2Int x)

Is there a fast 'fraction' built-in function? Or do I have to use FFI to
modf ?

More information about the Haskell-Cafe mailing list