foundation-0.0.19: Alternative prelude with batteries and no dependencies

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

# Documentation

class (Enum a, Eq a, Ord a, Integral a) => IsIntegral a where #

Number literals, convertible through the generic Integer type.

all number are Enum'erable, meaning that you can move to next element

Minimal complete definition

toInteger

Methods

toInteger :: a -> Integer #

Instances

 Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods IsIntegral (Offset ty) MethodstoInteger :: Offset ty -> Integer # MethodstoInteger :: CountOf ty -> Integer #

class (Enum a, Eq a, Ord a, Integral a, IsIntegral a) => IsNatural a where #

Non Negative Number literals, convertible through the generic Natural type

Minimal complete definition

toNatural

Methods

toNatural :: a -> Natural #

Instances

 Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods IsNatural (Offset ty) MethodstoNatural :: Offset ty -> Natural # IsNatural (CountOf ty) MethodstoNatural :: CountOf ty -> Natural #

class Signed a where Source #

types that have sign and can be made absolute

Minimal complete definition

Methods

abs :: a -> a Source #

signum :: a -> Sign Source #

Instances

 Source # Methods Source # Methods Source # Methodsabs :: Int -> Int Source # Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods

Represent class of things that can be added together, contains a neutral element and is commutative.

x + azero = x
azero + x = x
x + y = y + x

Minimal complete definition

Methods

azero :: a #

(+) :: a -> a -> a infixl 6 #

scale :: IsNatural n => n -> a -> a #

Instances

 Methods(+) :: Double -> Double -> Double #scale :: IsNatural n => n -> Double -> Double # Methods(+) :: Float -> Float -> Float #scale :: IsNatural n => n -> Float -> Float # Methods(+) :: Int -> Int -> Int #scale :: IsNatural n => n -> Int -> Int # Methods(+) :: Int8 -> Int8 -> Int8 #scale :: IsNatural n => n -> Int8 -> Int8 # Methods(+) :: Int16 -> Int16 -> Int16 #scale :: IsNatural n => n -> Int16 -> Int16 # Methods(+) :: Int32 -> Int32 -> Int32 #scale :: IsNatural n => n -> Int32 -> Int32 # Methods(+) :: Int64 -> Int64 -> Int64 #scale :: IsNatural n => n -> Int64 -> Int64 # Methodsscale :: IsNatural n => n -> Integer -> Integer # Methodsscale :: IsNatural n => n -> Natural -> Natural # Methods(+) :: Word -> Word -> Word #scale :: IsNatural n => n -> Word -> Word # Methods(+) :: Word8 -> Word8 -> Word8 #scale :: IsNatural n => n -> Word8 -> Word8 # Methods(+) :: Word16 -> Word16 -> Word16 #scale :: IsNatural n => n -> Word16 -> Word16 # Methods(+) :: Word32 -> Word32 -> Word32 #scale :: IsNatural n => n -> Word32 -> Word32 # Methods(+) :: Word64 -> Word64 -> Word64 #scale :: IsNatural n => n -> Word64 -> Word64 # Methods(+) :: COff -> COff -> COff #scale :: IsNatural n => n -> COff -> COff # Methods(+) :: CChar -> CChar -> CChar #scale :: IsNatural n => n -> CChar -> CChar # Methods(+) :: CSChar -> CSChar -> CSChar #scale :: IsNatural n => n -> CSChar -> CSChar # Methods(+) :: CUChar -> CUChar -> CUChar #scale :: IsNatural n => n -> CUChar -> CUChar # Methods(+) :: CShort -> CShort -> CShort #scale :: IsNatural n => n -> CShort -> CShort # Methodsscale :: IsNatural n => n -> CUShort -> CUShort # Methods(+) :: CInt -> CInt -> CInt #scale :: IsNatural n => n -> CInt -> CInt # Methods(+) :: CUInt -> CUInt -> CUInt #scale :: IsNatural n => n -> CUInt -> CUInt # Methods(+) :: CLong -> CLong -> CLong #scale :: IsNatural n => n -> CLong -> CLong # Methods(+) :: CULong -> CULong -> CULong #scale :: IsNatural n => n -> CULong -> CULong # Methods(+) :: CLLong -> CLLong -> CLLong #scale :: IsNatural n => n -> CLLong -> CLLong # Methodsscale :: IsNatural n => n -> CULLong -> CULLong # Methods(+) :: CFloat -> CFloat -> CFloat #scale :: IsNatural n => n -> CFloat -> CFloat # Methodsscale :: IsNatural n => n -> CDouble -> CDouble # Methodsscale :: IsNatural n => n -> CPtrdiff -> CPtrdiff # Methods(+) :: CSize -> CSize -> CSize #scale :: IsNatural n => n -> CSize -> CSize # Methods(+) :: CWchar -> CWchar -> CWchar #scale :: IsNatural n => n -> CWchar -> CWchar # Methodsscale :: IsNatural n => n -> CSigAtomic -> CSigAtomic # Methods(+) :: CClock -> CClock -> CClock #scale :: IsNatural n => n -> CClock -> CClock # Methods(+) :: CTime -> CTime -> CTime #scale :: IsNatural n => n -> CTime -> CTime # Methodsscale :: IsNatural n => n -> CUSeconds -> CUSeconds # Methodsscale :: IsNatural n => n -> CSUSeconds -> CSUSeconds # Methodsscale :: IsNatural n => n -> CIntPtr -> CIntPtr # Methodsscale :: IsNatural n => n -> CUIntPtr -> CUIntPtr # Methodsscale :: IsNatural n => n -> CIntMax -> CIntMax # Methodsscale :: IsNatural n => n -> CUIntMax -> CUIntMax # Methodsscale :: IsNatural n => n -> Word256 -> Word256 # Methodsscale :: IsNatural n => n -> Word128 -> Word128 # # Methodsscale :: IsNatural n => n -> Seconds -> Seconds # # Methodsscale :: IsNatural n => n -> NanoSeconds -> NanoSeconds # Additive (Offset ty) Methodsazero :: Offset ty #(+) :: Offset ty -> Offset ty -> Offset ty #scale :: IsNatural n => n -> Offset ty -> Offset ty # Additive (CountOf ty) Methodsazero :: CountOf ty #(+) :: CountOf ty -> CountOf ty -> CountOf ty #scale :: IsNatural n => n -> CountOf ty -> CountOf ty # (KnownNat n, NatWithinBound Word64 n) => Additive (Zn64 n) Methodsazero :: Zn64 n #(+) :: Zn64 n -> Zn64 n -> Zn64 n #scale :: IsNatural n => n -> Zn64 n -> Zn64 n # KnownNat n => Additive (Zn n) Methodsazero :: Zn n #(+) :: Zn n -> Zn n -> Zn n #scale :: IsNatural n => n -> Zn n -> Zn n #

class Subtractive a where #

Represent class of things that can be subtracted.

Note that the result is not necessary of the same type as the operand depending on the actual type.

For example:

(-) :: Int -> Int -> Int
(-) :: DateTime -> DateTime -> Seconds
(-) :: Ptr a -> Ptr a -> PtrDiff
(-) :: Natural -> Natural -> Maybe Natural

Minimal complete definition

(-)

Associated Types

type Difference a :: * #

Methods

(-) :: a -> a -> Difference a infixl 6 #

Instances

 Associated Typestype Difference Char :: * # Methods Associated Typestype Difference Double :: * # Methods Associated Typestype Difference Float :: * # Methods Associated Typestype Difference Int :: * # Methods(-) :: Int -> Int -> Difference Int # Associated Typestype Difference Int8 :: * # Methods Associated Typestype Difference Int16 :: * # Methods Associated Typestype Difference Int32 :: * # Methods Associated Typestype Difference Int64 :: * # Methods Associated Typestype Difference Integer :: * # Methods Associated Typestype Difference Natural :: * # Methods Associated Typestype Difference Word :: * # Methods Associated Typestype Difference Word8 :: * # Methods Associated Typestype Difference Word16 :: * # Methods Associated Typestype Difference Word32 :: * # Methods Associated Typestype Difference Word64 :: * # Methods Associated Typestype Difference COff :: * # Methods Associated Typestype Difference CChar :: * # Methods Associated Typestype Difference CSChar :: * # Methods Associated Typestype Difference CUChar :: * # Methods Associated Typestype Difference CShort :: * # Methods Associated Typestype Difference CUShort :: * # Methods Associated Typestype Difference CInt :: * # Methods Associated Typestype Difference CUInt :: * # Methods Associated Typestype Difference CLong :: * # Methods Associated Typestype Difference CULong :: * # Methods Associated Typestype Difference CLLong :: * # Methods Associated Typestype Difference CULLong :: * # Methods Associated Typestype Difference CBool :: * # Methods Associated Typestype Difference CFloat :: * # Methods Associated Typestype Difference CDouble :: * # Methods Associated Typestype Difference CPtrdiff :: * # Methods Associated Typestype Difference CSize :: * # Methods Associated Typestype Difference CWchar :: * # Methods Associated Typestype Difference CSigAtomic :: * # Methods Associated Typestype Difference CClock :: * # Methods Associated Typestype Difference CTime :: * # Methods Associated Typestype Difference CUSeconds :: * # Methods Associated Typestype Difference CSUSeconds :: * # Methods Associated Typestype Difference CIntPtr :: * # Methods Associated Typestype Difference CUIntPtr :: * # Methods Associated Typestype Difference CIntMax :: * # Methods Associated Typestype Difference CUIntMax :: * # Methods Associated Typestype Difference Word256 :: * # Methods Associated Typestype Difference Word128 :: * # Methods Associated Typestype Difference (Offset ty) :: * # Methods(-) :: Offset ty -> Offset ty -> Difference (Offset ty) # Associated Typestype Difference (CountOf ty) :: * # Methods(-) :: CountOf ty -> CountOf ty -> Difference (CountOf ty) # (KnownNat n, NatWithinBound Word64 n) => Subtractive (Zn64 n) Associated Typestype Difference (Zn64 n) :: * # Methods(-) :: Zn64 n -> Zn64 n -> Difference (Zn64 n) # KnownNat n => Subtractive (Zn n) Associated Typestype Difference (Zn n) :: * # Methods(-) :: Zn n -> Zn n -> Difference (Zn n) #

class Multiplicative a where #

Represent class of things that can be multiplied together

x * midentity = x
midentity * x = x

Minimal complete definition

Methods

midentity :: a #

Identity element over multiplication

(*) :: a -> a -> a infixl 7 #

Multiplication of 2 elements that result in another element

(^) :: (IsNatural n, IDivisible n) => a -> n -> a infixr 8 #

Raise to power, repeated multiplication e.g. > a ^ 2 = a * a > a ^ 10 = (a ^ 5) * (a ^ 5) .. (^) :: (IsNatural n) => a -> n -> a

Instances

 Methods(*) :: Double -> Double -> Double #(^) :: (IsNatural n, IDivisible n) => Double -> n -> Double # Methods(*) :: Float -> Float -> Float #(^) :: (IsNatural n, IDivisible n) => Float -> n -> Float # Methods(*) :: Int -> Int -> Int #(^) :: (IsNatural n, IDivisible n) => Int -> n -> Int # Methods(*) :: Int8 -> Int8 -> Int8 #(^) :: (IsNatural n, IDivisible n) => Int8 -> n -> Int8 # Methods(*) :: Int16 -> Int16 -> Int16 #(^) :: (IsNatural n, IDivisible n) => Int16 -> n -> Int16 # Methods(*) :: Int32 -> Int32 -> Int32 #(^) :: (IsNatural n, IDivisible n) => Int32 -> n -> Int32 # Methods(*) :: Int64 -> Int64 -> Int64 #(^) :: (IsNatural n, IDivisible n) => Int64 -> n -> Int64 # Methods(^) :: (IsNatural n, IDivisible n) => Integer -> n -> Integer # Methods(^) :: (IsNatural n, IDivisible n) => Natural -> n -> Natural # Methods(^) :: (IsNatural n, IDivisible n) => Rational -> n -> Rational # Methods(*) :: Word -> Word -> Word #(^) :: (IsNatural n, IDivisible n) => Word -> n -> Word # Methods(*) :: Word8 -> Word8 -> Word8 #(^) :: (IsNatural n, IDivisible n) => Word8 -> n -> Word8 # Methods(*) :: Word16 -> Word16 -> Word16 #(^) :: (IsNatural n, IDivisible n) => Word16 -> n -> Word16 # Methods(*) :: Word32 -> Word32 -> Word32 #(^) :: (IsNatural n, IDivisible n) => Word32 -> n -> Word32 # Methods(*) :: Word64 -> Word64 -> Word64 #(^) :: (IsNatural n, IDivisible n) => Word64 -> n -> Word64 # Methods(*) :: COff -> COff -> COff #(^) :: (IsNatural n, IDivisible n) => COff -> n -> COff # Methods(*) :: CChar -> CChar -> CChar #(^) :: (IsNatural n, IDivisible n) => CChar -> n -> CChar # Methods(*) :: CSChar -> CSChar -> CSChar #(^) :: (IsNatural n, IDivisible n) => CSChar -> n -> CSChar # Methods(*) :: CUChar -> CUChar -> CUChar #(^) :: (IsNatural n, IDivisible n) => CUChar -> n -> CUChar # Methods(*) :: CShort -> CShort -> CShort #(^) :: (IsNatural n, IDivisible n) => CShort -> n -> CShort # Methods(^) :: (IsNatural n, IDivisible n) => CUShort -> n -> CUShort # Methods(*) :: CInt -> CInt -> CInt #(^) :: (IsNatural n, IDivisible n) => CInt -> n -> CInt # Methods(*) :: CUInt -> CUInt -> CUInt #(^) :: (IsNatural n, IDivisible n) => CUInt -> n -> CUInt # Methods(*) :: CLong -> CLong -> CLong #(^) :: (IsNatural n, IDivisible n) => CLong -> n -> CLong # Methods(*) :: CULong -> CULong -> CULong #(^) :: (IsNatural n, IDivisible n) => CULong -> n -> CULong # Methods(*) :: CLLong -> CLLong -> CLLong #(^) :: (IsNatural n, IDivisible n) => CLLong -> n -> CLLong # Methods(^) :: (IsNatural n, IDivisible n) => CULLong -> n -> CULLong # Methods(*) :: CFloat -> CFloat -> CFloat #(^) :: (IsNatural n, IDivisible n) => CFloat -> n -> CFloat # Methods(^) :: (IsNatural n, IDivisible n) => CDouble -> n -> CDouble # Methods(^) :: (IsNatural n, IDivisible n) => CPtrdiff -> n -> CPtrdiff # Methods(*) :: CSize -> CSize -> CSize #(^) :: (IsNatural n, IDivisible n) => CSize -> n -> CSize # Methods(*) :: CWchar -> CWchar -> CWchar #(^) :: (IsNatural n, IDivisible n) => CWchar -> n -> CWchar # Methods(^) :: (IsNatural n, IDivisible n) => CSigAtomic -> n -> CSigAtomic # Methods(*) :: CClock -> CClock -> CClock #(^) :: (IsNatural n, IDivisible n) => CClock -> n -> CClock # Methods(*) :: CTime -> CTime -> CTime #(^) :: (IsNatural n, IDivisible n) => CTime -> n -> CTime # Methods(^) :: (IsNatural n, IDivisible n) => CUSeconds -> n -> CUSeconds # Methods(^) :: (IsNatural n, IDivisible n) => CSUSeconds -> n -> CSUSeconds # Methods(^) :: (IsNatural n, IDivisible n) => CIntPtr -> n -> CIntPtr # Methods(^) :: (IsNatural n, IDivisible n) => CUIntPtr -> n -> CUIntPtr # Methods(^) :: (IsNatural n, IDivisible n) => CIntMax -> n -> CIntMax # Methods(^) :: (IsNatural n, IDivisible n) => CUIntMax -> n -> CUIntMax # Methods(^) :: (IsNatural n, IDivisible n) => Word256 -> n -> Word256 # Methods(^) :: (IsNatural n, IDivisible n) => Word128 -> n -> Word128 #

class (Additive a, Multiplicative a) => IDivisible a where #

Represent types that supports an euclidian division

(x ‘div‘ y) * y + (x ‘mod‘ y) == x

Minimal complete definition

Methods

div :: a -> a -> a #

mod :: a -> a -> a #

divMod :: a -> a -> (a, a) #

Instances

 Methodsdiv :: Int -> Int -> Int #mod :: Int -> Int -> Int #divMod :: Int -> Int -> (Int, Int) # Methodsdiv :: Int8 -> Int8 -> Int8 #mod :: Int8 -> Int8 -> Int8 #divMod :: Int8 -> Int8 -> (Int8, Int8) # Methodsdiv :: Int16 -> Int16 -> Int16 #mod :: Int16 -> Int16 -> Int16 #divMod :: Int16 -> Int16 -> (Int16, Int16) # Methodsdiv :: Int32 -> Int32 -> Int32 #mod :: Int32 -> Int32 -> Int32 #divMod :: Int32 -> Int32 -> (Int32, Int32) # Methodsdiv :: Int64 -> Int64 -> Int64 #mod :: Int64 -> Int64 -> Int64 #divMod :: Int64 -> Int64 -> (Int64, Int64) # MethodsdivMod :: Integer -> Integer -> (Integer, Integer) # MethodsdivMod :: Natural -> Natural -> (Natural, Natural) # Methodsdiv :: Word -> Word -> Word #mod :: Word -> Word -> Word #divMod :: Word -> Word -> (Word, Word) # Methodsdiv :: Word8 -> Word8 -> Word8 #mod :: Word8 -> Word8 -> Word8 #divMod :: Word8 -> Word8 -> (Word8, Word8) # Methodsdiv :: Word16 -> Word16 -> Word16 #mod :: Word16 -> Word16 -> Word16 #divMod :: Word16 -> Word16 -> (Word16, Word16) # Methodsdiv :: Word32 -> Word32 -> Word32 #mod :: Word32 -> Word32 -> Word32 #divMod :: Word32 -> Word32 -> (Word32, Word32) # Methodsdiv :: Word64 -> Word64 -> Word64 #mod :: Word64 -> Word64 -> Word64 #divMod :: Word64 -> Word64 -> (Word64, Word64) # Methodsdiv :: CChar -> CChar -> CChar #mod :: CChar -> CChar -> CChar #divMod :: CChar -> CChar -> (CChar, CChar) # Methodsdiv :: CSChar -> CSChar -> CSChar #mod :: CSChar -> CSChar -> CSChar #divMod :: CSChar -> CSChar -> (CSChar, CSChar) # Methodsdiv :: CUChar -> CUChar -> CUChar #mod :: CUChar -> CUChar -> CUChar #divMod :: CUChar -> CUChar -> (CUChar, CUChar) # Methodsdiv :: CShort -> CShort -> CShort #mod :: CShort -> CShort -> CShort #divMod :: CShort -> CShort -> (CShort, CShort) # MethodsdivMod :: CUShort -> CUShort -> (CUShort, CUShort) # Methodsdiv :: CInt -> CInt -> CInt #mod :: CInt -> CInt -> CInt #divMod :: CInt -> CInt -> (CInt, CInt) # Methodsdiv :: CUInt -> CUInt -> CUInt #mod :: CUInt -> CUInt -> CUInt #divMod :: CUInt -> CUInt -> (CUInt, CUInt) # Methodsdiv :: CLong -> CLong -> CLong #mod :: CLong -> CLong -> CLong #divMod :: CLong -> CLong -> (CLong, CLong) # Methodsdiv :: CULong -> CULong -> CULong #mod :: CULong -> CULong -> CULong #divMod :: CULong -> CULong -> (CULong, CULong) # Methodsdiv :: CLLong -> CLLong -> CLLong #mod :: CLLong -> CLLong -> CLLong #divMod :: CLLong -> CLLong -> (CLLong, CLLong) # MethodsdivMod :: CULLong -> CULLong -> (CULLong, CULLong) # MethodsdivMod :: CPtrdiff -> CPtrdiff -> (CPtrdiff, CPtrdiff) # Methodsdiv :: CSize -> CSize -> CSize #mod :: CSize -> CSize -> CSize #divMod :: CSize -> CSize -> (CSize, CSize) # Methodsdiv :: CWchar -> CWchar -> CWchar #mod :: CWchar -> CWchar -> CWchar #divMod :: CWchar -> CWchar -> (CWchar, CWchar) # Methods MethodsdivMod :: CIntPtr -> CIntPtr -> (CIntPtr, CIntPtr) # MethodsdivMod :: CUIntPtr -> CUIntPtr -> (CUIntPtr, CUIntPtr) # MethodsdivMod :: CIntMax -> CIntMax -> (CIntMax, CIntMax) # MethodsdivMod :: CUIntMax -> CUIntMax -> (CUIntMax, CUIntMax) # MethodsdivMod :: Word256 -> Word256 -> (Word256, Word256) # MethodsdivMod :: Word128 -> Word128 -> (Word128, Word128) #

class Multiplicative a => Divisible a where #

Support for division between same types

This is likely to change to represent specific mathematic divisions

Minimal complete definition

(/)

Methods

(/) :: a -> a -> a infixl 7 #

Instances

 Methods(/) :: Double -> Double -> Double # Methods(/) :: Float -> Float -> Float # Methods Methods(/) :: CFloat -> CFloat -> CFloat # Methods

data Sign Source #

Sign of a signed number

Constructors

 SignNegative SignZero SignPositive

Instances

 Source # Methods(==) :: Sign -> Sign -> Bool #(/=) :: Sign -> Sign -> Bool #

recip :: Divisible a => a -> a #

class IntegralRounding a where Source #

Minimal complete definition

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

Instances

 Source # MethodsroundUp :: Integral n => Double -> n Source #roundDown :: Integral n => Double -> n Source #roundTruncate :: Integral n => Double -> n Source #roundNearest :: Integral n => Double -> n Source # Source # MethodsroundUp :: Integral n => Float -> n Source #roundDown :: Integral n => Float -> n Source #roundTruncate :: Integral n => Float -> n Source #roundNearest :: Integral n => Float -> n Source # Source # MethodsroundUp :: Integral n => Rational -> n Source #roundDown :: Integral n => Rational -> n Source #roundTruncate :: Integral n => Rational -> n Source #roundNearest :: Integral n => Rational -> n Source #

class FloatingPoint a where Source #

IEEE754 Floating Point

Minimal complete definition

Instances

 Source # Methods Source # Methods