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

Henning Thielemann lemming at henning-thielemann.de
Tue Jan 15 01:40:03 EST 2008

On Mon, 14 Jan 2008, John Meacham wrote:

> On Sun, Jan 13, 2008 at 01:08:49AM +0100, Henning Thielemann wrote:
> > Is there a fast and reliable way to compute the fraction of a floating
> > point number?
> no, and this has bothered me to the point I consider it a bug in the
> language spec that all 'rounding' style functions give back an integral
> type.

I find returning an Integral is appropriate. The type expresses perfectly
what kind of values you can expect. Sure, there should be some
optimization rule like
  fromInteger (round x)  =  roundf x  .
 However, the 'fraction' function gets a fraction and returns a fraction
and doesn't care about the type of the integer part. As I see this is also
missing from your RealFrac class extension.

More information about the Haskell-Cafe mailing list