3 07-04-94 ipoole added pi method for Lognum
7 A packeage for log representations of numbers.
12 > data Lognum = LN Double
14 > instance Num Lognum where
15 > LN x * LN y = LN (x+y)
16 > LN x + LN y = LN (d+(mylog 1 (exp (x-d) + exp (y-d))))
18 > LN x - LN y = if y > x then error "subtract LN" else
19 > LN (d+(mylog 2 (exp (x-d) - exp (y-d))))
21 > fromInteger 0 = LN (-1.0e99)
22 > fromInteger x = LN (mylog 3 (fromInteger x))
24 > instance Ord Lognum where
26 > a <= b = not (a > b)
28 > instance Eq Lognum where
29 > LN x == LN y = x == y
31 > instance Floating Lognum where
32 > sqrt (LN x) = LN (x/2.0)
33 > (LN x) ** (LN y) = (LN (x * exp y))
36 > instance Fractional Lognum where
37 > LN x / LN y = LN (x-y)
38 > fromRational x = if x == toRational 0.0 then fromInteger 0
39 > else LN (mylog 4 (toDouble x))
42 > instance Enum Lognum where
43 > enumFrom n = iterate ((fromRational 1.0)+) n
44 > enumFromThen n m = iterate ((m-n)+) n
47 > instance Real Lognum where
48 > toRational (LN x) = toRational (exp x)
50 > toLognum :: Real a => a -> Lognum
51 > toLognum = fromRational . toRational
53 > instance RealFloat Lognum
55 > instance RealFrac Lognum
57 > instance Show{-was:Text-} Lognum
59 > mylog :: Int -> Double -> Double
60 > mylog n x = if toDouble x < 0.0 then error ("mylog" ++ show n) else log x