Proposal: Better power for Rational

Daniel Fischer daniel.is.fischer at web.de
Mon Oct 4 10:00:53 EDT 2010


On Monday 04 October 2010 11:57:06, Simon Peyton-Jones wrote:
> Henning
>
> | I'll try to create a patch, however I may need some assistance
> | compiling base libraries.
>
> Thank you.  Creating a patch, attaching to a ticket with some rationale,
> and submitting it to the libraries list, is the best way to push your
> work over the hill and into the actual code base.   I'm sure others will
> help.  If you get stuck, yell!
>
> Daniel Fischer is working in this patch too.
>
> Simon

Since I'm working on GHC.Float anyway, I'll include Henning's rounding etc. 
code too.

Speaking of GHC.Float, there are a few points where I would like some 
guidance on where to put things.

I could of course put everything in GHC.Float, but it's big already and I'd 
prefer not to clutter it up further.

For toRational, to avoid wasting time in gcd, I need an array for the 
number of trailing 0-bits in a byte. Also, since bit-fiddling of Integers 
is considerably slower than for fixed width types, I'd need to import 
GHC.IntWord64 since a Double mantissa won't fit in an Int on 32-bit 
systems. This could go into GHC.Float or into a GHC.Float.Utils module.

For fromRational, I need a fast integerLog2. For that, I need access to the 
internal representation of Integers when using integer-gmp and an 
alternative implementation for integer-simple (which would be much slower, 
but if you use integer-simple, performance probably isn't your foremost 
concern). I might need a few more odds and ends if special-casing for the 
results of toRational (whose denominator is a power of 2) proves to be a 
gain.

Putting all the auxiliary stuff in GHC.Float wrapped in #ifdefs is IMO an 
appalling idea.

integerLog2 and more generally integerLogBase are useful enough to be added 
to GHC.Integer (Int/Word is not yet available, so it'd be the '#' versions, 
where would the wrappers returning an Int or Word go?).
If I need the stuff for special casing, my preferred solution would be to 
put it in GHC.Integer.Variant.Internals or add a small dedicated module for 
them to the package.

So what's the best place to put stuff?


More information about the Libraries mailing list