Proposal: Faster conversion between Rational and Double/Float

Daniel Fischer at
Fri Apr 1 00:15:52 CEST 2011

On Thursday 31 March 2011 23:34:47, Henning Thielemann wrote:
> On Thu, 31 Mar 2011, Daniel Fischer wrote:
> > Summary:
> > 
> > I propose
> > - adding modules implementing integer logarithm functions to
> > integer-gmp and integer-simple
> > - changing the implementation of toRational and fromRational for
> > Double and Float using those to become significantly faster.
> Is there also a rule to, say, convert
>    fromRational . toRational :: Double -> Double
>   to 'id'? Sure 'id' is not quite correct because of NaNs. Maybe
> 'realToFrac'.

There are already rules for realToFrac, but afaik, not for (fromRational . 
toRational). But if those rules don't fire, you get
realToFrac = fromRational . toRational,
which is horrible for performance (and the conversion is less truthful than 
id/double2Float/float2Double which you get from the rules, so you probably 
don't really want the standard-conforming realToFrac for these conversions, 
but if you get it, does it have to be so slow?).

More information about the Libraries mailing list