profiling problems

Hal Daume III hdaume@ISI.EDU
Tue, 25 Feb 2003 21:12:23 -0800 (PST)


> floatRat :: Rational -> Int -> Integer
> floatRat r lim =
>     num*10^lim `div` den
>     where
>     num = numerator r
>     den = denominator r

My guess is that the error is here.  There's a bug in ghc where (x `div`
0) and (x `mod` 0) will results in a seg fault.  For now (according to one
of the Simons, this is fixed in the next version) you should do something
like:

floatRat r lim
  | den  == 0 = error "division by zero"
  | otherwise = num * 10 ^ lim `div` den
    where num = numberator r
          den = denominator r

If that doesn't fix the problem, perhaps you can try to whittle the
example down to something shorter.

 - Hal