numbers 2007.9.23 → 2007.9.24
raw patch · 3 files changed
+64/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Number.Natural: data Natural
+ Data.Number.Natural: instance Enum Natural
+ Data.Number.Natural: instance Eq Natural
+ Data.Number.Natural: instance Integral Natural
+ Data.Number.Natural: instance Num Natural
+ Data.Number.Natural: instance Ord Natural
+ Data.Number.Natural: instance Real Natural
+ Data.Number.Natural: instance Show Natural
Files
- Data/Number/FixedFunctions.hs +6/−6
- Data/Number/Natural.hs +54/−0
- numbers.cabal +4/−2
Data/Number/FixedFunctions.hs view
@@ -360,8 +360,8 @@ -- Inverse hyperbolic tangent with approximation eps -- - | x >= 1 = 1%0- | x <= -1 = -1%0+-- | x >= 1 = 1%0+-- | x <= -1 = -1%0 | otherwise = (1%2) * (log eps ((1 + x) / (1 - x))) asinh :: Rational -> Rational -> Rational@@ -369,8 +369,8 @@ -- -- Inverse hyperbolic sine --- | x == 1%0 = 1%0- | x == -1%0 = -1%0+-- | x == 1%0 = 1%0+-- | x == -1%0 = -1%0 | otherwise = log eps (x + (sqrt eps (x^2 + 1))) acosh :: Rational -> Rational -> Rational@@ -378,8 +378,8 @@ -- -- Inverse hyperbolic cosine --- | x == 1%0 = 1%0- | x < 1 = 1%0+-- | x == 1%0 = 1%0+-- | x < 1 = 1%0 | otherwise = log eps (x + (sqrt eps (x^2 - 1))) ---------------------------------------------------------------------
+ Data/Number/Natural.hs view
@@ -0,0 +1,54 @@+module Data.Number.Natural(Natural) where++data Natural = Z | S Natural++instance Show Natural where+ showsPrec p n = showsPrec p (toInteger n)++instance Eq Natural where+ x == y = x `compare` y == EQ++instance Ord Natural where+ Z `compare` Z = EQ+ Z `compare` S _ = LT+ S _ `compare` Z = GT+ S x `compare` S y = x `compare` y++instance Num Natural where+ Z + y = y+ S x + y = S (x + y)++ x - Z = x+ Z - S _ = error "Natural: (-)"+ S x - S y = x - y++ Z * y = Z+ S x * y = y + x * y++ abs x = x+ signum Z = Z+ signum (S _) = S Z++ fromInteger x | x < 0 = error "Natural: fromInteger"+ fromInteger 0 = Z+ fromInteger x = S (fromInteger (x-1))++instance Integral Natural where+ -- Not the most efficient version, but efficiency isn't the point of this module. :)+ quotRem x y =+ if x < y then+ (0, x)+ else+ let (q, r) = quotRem (x-y) y+ in (q+1, r)+ div = quot+ mod = rem+ toInteger Z = 0+ toInteger (S x) = 1 + toInteger x++instance Real Natural where+ toRational = toRational . toInteger++instance Enum Natural where+ toEnum = fromIntegral+ fromEnum = fromIntegral
numbers.cabal view
@@ -1,5 +1,5 @@ Name: numbers-Version: 2007.9.23+Version: 2007.9.24 License: BSD3 Author: Lennart Augustsson Maintainer: Lennart Augustsson@@ -9,9 +9,11 @@ different numbers: (computable) real numbers, arbitrary precision fixed numbers, arbitrary precision floating point numbers,- differentiable numbers, symbolic numbers.+ differentiable numbers, symbolic numbers,+ natural numbers, interval arithmetic. Build-Depends: base Exposed-modules: Data.Number.Symbolic Data.Number.Dif Data.Number.CReal Data.Number.Fixed Data.Number.Interval Data.Number.BigFloat+ Data.Number.Natural Other-modules: Data.Number.Vectorspace Data.Number.FixedFunctions