Proposal: Faster toRational and fromRational

Daniel Fischer at
Thu Oct 21 15:35:30 EDT 2010


Proposal: include faster implementations for

   1. toRational :: Float -> Rational
   2. toRational :: Double -> Rational
   3. fromRational :: Rational -> Float
   4. fromRational :: Rational -> Double 

The semantics of these functions shall remain the same as it is now, only 
their speed will be affected.

For fromRational, a fast integer logarithm is essential. Without access to 
the internal representation of Integer, it would be significantly slower, 
so this proposal includes the addition of modules defining the needed 
integer logarithm functions to the packages integer-gmp and integer-simple.

Since Int is not available in the integer-* packages, those functions would 
return Int# values. I suggest adding wrappers integerLog2 :: Integer -> Int 
and integerLogBase :: Integer -> Integer -> Int to some module in base 
because those functions are far more generally useful. Currently 
integerLogBase is available from GHC.Float, so we might stick them there, 
although it's not very intuitive. Suggestions welcome.

Discussion period: one week, until 29th October 2010 (I'd like to see it in 

there's a bundle containing the proposed new implementations, QuickCheck 
tests and benchmarks.
I get a pretty impressive speedup.


More information about the Libraries mailing list