non-negative 0.0.5.1 → 0.0.6
raw patch · 3 files changed
+35/−3 lines, 3 files
Files
- non-negative.cabal +1/−1
- src/Numeric/NonNegative/Chunky.hs +2/−1
- src/Numeric/NonNegative/ChunkyPrivate.hs +32/−1
non-negative.cabal view
@@ -1,5 +1,5 @@ Name: non-negative-Version: 0.0.5.1+Version: 0.0.6 License: GPL License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>
src/Numeric/NonNegative/Chunky.hs view
@@ -1,5 +1,5 @@ {- |-Copyright : (c) Henning Thielemann 2008+Copyright : (c) Henning Thielemann 2008-2010 Maintainer : haskell@henning-thielemann.de Stability : stable@@ -19,6 +19,7 @@ (T, fromChunks, fromNumber, toChunks, toNumber, zero, normalize, isNull, isPositive, minMaxDiff,+ divModStrict, ) where import Numeric.NonNegative.ChunkyPrivate
src/Numeric/NonNegative/ChunkyPrivate.hs view
@@ -1,5 +1,5 @@ {- |-Copyright : (c) Henning Thielemann 2008+Copyright : (c) Henning Thielemann 2008-2010 Maintainer : haskell@henning-thielemann.de Stability : stable@@ -14,6 +14,7 @@ (T, fromChunks, fromNumber, toChunks, toNumber, zero, normalize, isNull, isPositive, minMaxDiff,+ divModStrict, fromChunksUnsafe, toChunksUnsafe, ) where import qualified Numeric.NonNegative.Class as NonNeg@@ -161,6 +162,36 @@ (*) = lift2 (liftM2 (*)) abs = id signum = fromNumber . (\b -> if b then 1 else 0) . isPositive+++instance (Real a, NonNeg.C a) => Real (T a) where+ toRational = toRational . toNumber++{- required for Integral instance -}+instance (Enum a, NonNeg.C a) => Enum (T a) where+ toEnum = fromNumber . toEnum+ fromEnum = fromEnum . toNumber++instance (Integral a, NonNeg.C a) => Integral (T a) where+ toInteger = toInteger . toNumber+ quot = div+ rem = mod+ quotRem = divMod+ divMod x y =+ case divModStrict x (toNumber y) of+ (q,r) -> (q, fromNumber r)++divModStrict ::+ (Integral a, NonNeg.C a) =>+ T a -> a -> (T a, a)+divModStrict x0 y =+ let recourse [] r = ([], r)+ recourse (x:xs) r0 =+ let (q1,r1) = divMod (x+r0) y+ (q2,r2) = recourse xs r1+ in (q1:q2,r2)+ (cs,rm) = recourse (toChunks x0) 0+ in (fromChunks cs, rm) instance Mn.Monoid (T a) where