License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Foundation.Numerical
Description
Compared to the Haskell hierarchy of number classes this provide a more flexible approach that is closer to the mathematical foundation (group, field, etc)
This try to only provide one feature per class, at the expense of the number of classes.
Synopsis
- class (Integral a, Eq a, Ord a) => IsIntegral a where
- class IsIntegral a => IsNatural a where
- class Signed a where
- class Additive a where
- class Subtractive a where
- type Difference a
- (-) :: a -> a -> Difference a
- class Multiplicative a where
- class (Additive a, Multiplicative a) => IDivisible a where
- class Multiplicative a => Divisible a where
- (/) :: a -> a -> a
- data Sign
- recip :: Divisible a => a -> a
- class IntegralRounding a where
- roundUp :: Integral n => a -> n
- roundDown :: Integral n => a -> n
- roundTruncate :: Integral n => a -> n
- roundNearest :: Integral n => a -> n
- class FloatingPoint a where
- floatRadix :: Proxy a -> Integer
- floatDigits :: Proxy a -> Int
- floatRange :: Proxy a -> (Int, Int)
- floatDecode :: a -> (Integer, Int)
- floatEncode :: Integer -> Int -> a
Documentation
class (Integral a, Eq a, Ord a) => IsIntegral a where #
Instances
class IsIntegral a => IsNatural a where #
Instances
types that have sign and can be made absolute
Instances
class Subtractive a where #
Associated Types
type Difference a #
Methods
(-) :: a -> a -> Difference a #
Instances
class Multiplicative a where #
Methods
(^) :: (IsNatural n, Enum n, IDivisible n) => a -> n -> a #
Instances
Multiplicative CChar | |
Multiplicative CClock | |
Multiplicative CDouble | |
Multiplicative CFloat | |
Multiplicative CInt | |
Multiplicative CIntMax | |
Multiplicative CIntPtr | |
Multiplicative CLLong | |
Multiplicative CLong | |
Multiplicative CPtrdiff | |
Multiplicative CSChar | |
Multiplicative CSUSeconds | |
Defined in Basement.Numerical.Multiplicative Methods midentity :: CSUSeconds # (*) :: CSUSeconds -> CSUSeconds -> CSUSeconds # (^) :: (IsNatural n, Enum n, IDivisible n) => CSUSeconds -> n -> CSUSeconds # | |
Multiplicative CShort | |
Multiplicative CSigAtomic | |
Defined in Basement.Numerical.Multiplicative Methods midentity :: CSigAtomic # (*) :: CSigAtomic -> CSigAtomic -> CSigAtomic # (^) :: (IsNatural n, Enum n, IDivisible n) => CSigAtomic -> n -> CSigAtomic # | |
Multiplicative CSize | |
Multiplicative CTime | |
Multiplicative CUChar | |
Multiplicative CUInt | |
Multiplicative CUIntMax | |
Multiplicative CUIntPtr | |
Multiplicative CULLong | |
Multiplicative CULong | |
Multiplicative CUSeconds | |
Multiplicative CUShort | |
Multiplicative CWchar | |
Multiplicative Int16 | |
Multiplicative Int32 | |
Multiplicative Int64 | |
Multiplicative Int8 | |
Multiplicative Rational | |
Multiplicative Word16 | |
Multiplicative Word32 | |
Multiplicative Word64 | |
Multiplicative Word8 | |
Multiplicative COff | |
Multiplicative Word128 | |
Multiplicative Word256 | |
Multiplicative Integer | |
Multiplicative Natural | |
Multiplicative Double | |
Multiplicative Float | |
Multiplicative Int | |
Multiplicative Word | |
SizeValid n => Multiplicative (Bits n) | |
Defined in Basement.Bits |
class (Additive a, Multiplicative a) => IDivisible a where #
Instances
IDivisible CChar | |
IDivisible CInt | |
IDivisible CIntMax | |
IDivisible CIntPtr | |
IDivisible CLLong | |
IDivisible CLong | |
IDivisible CPtrdiff | |
IDivisible CSChar | |
IDivisible CShort | |
IDivisible CSigAtomic | |
Defined in Basement.Numerical.Multiplicative Methods div :: CSigAtomic -> CSigAtomic -> CSigAtomic # mod :: CSigAtomic -> CSigAtomic -> CSigAtomic # divMod :: CSigAtomic -> CSigAtomic -> (CSigAtomic, CSigAtomic) # | |
IDivisible CSize | |
IDivisible CUChar | |
IDivisible CUInt | |
IDivisible CUIntMax | |
IDivisible CUIntPtr | |
IDivisible CULLong | |
IDivisible CULong | |
IDivisible CUShort | |
IDivisible CWchar | |
IDivisible Int16 | |
IDivisible Int32 | |
IDivisible Int64 | |
IDivisible Int8 | |
IDivisible Word16 | |
IDivisible Word32 | |
IDivisible Word64 | |
IDivisible Word8 | |
IDivisible Word128 | |
IDivisible Word256 | |
IDivisible Integer | |
IDivisible Natural | |
IDivisible Int | |
IDivisible Word | |
SizeValid n => IDivisible (Bits n) | |
class Multiplicative a => Divisible a where #
Sign of a signed number
Constructors
SignNegative | |
SignZero | |
SignPositive |
class IntegralRounding a where Source #
Methods
roundUp :: Integral n => a -> n Source #
Round up, to the next integral.
Also known as ceiling
roundDown :: Integral n => a -> n Source #
Round down, to the previous integral
Also known as floor
roundTruncate :: Integral n => a -> n Source #
Truncate to the closest integral to the fractional number closer to 0.
This is equivalent to roundUp for negative Number and roundDown for positive Number
roundNearest :: Integral n => a -> n Source #
Round to the nearest integral
roundNearest 3.6
4 > roundNearest 3.4 3
class FloatingPoint a where Source #
IEEE754 Floating Point
Methods
floatRadix :: Proxy a -> Integer Source #
floatDigits :: Proxy a -> Int Source #
floatRange :: Proxy a -> (Int, Int) Source #
floatDecode :: a -> (Integer, Int) Source #
floatEncode :: Integer -> Int -> a Source #