Copyright | (c) 2018-2023 Kowainik |
---|---|
License | MIT |
Maintainer | Kowainik <xrom.xkov@gmail.com> |
Stability | Stable |
Portability | Portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Relude.Numeric
Contents
Description
Provides numerical data types and functions.
Since: 0.5.0
Synopsis
- xor :: Bits a => a -> a -> a
- toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b
- module Data.Int
- data Word8
- data Word
- data Word64
- data Word32
- data Word16
- byteSwap16 :: Word16 -> Word16
- byteSwap32 :: Word32 -> Word32
- byteSwap64 :: Word64 -> Word64
- minInt :: Int
- maxInt :: Int
- data Float = F# Float#
- data Double = D# Double#
- class Fractional a => Floating a where
- class (RealFrac a, Floating a) => RealFloat a where
- floatRadix :: a -> Integer
- floatDigits :: a -> Int
- floatRange :: a -> (Int, Int)
- decodeFloat :: a -> (Integer, Int)
- encodeFloat :: Integer -> Int -> a
- isNaN :: a -> Bool
- isInfinite :: a -> Bool
- isDenormalized :: a -> Bool
- isNegativeZero :: a -> Bool
- isIEEE :: a -> Bool
- atan2 :: a -> a -> a
- data Integer
- class Num a where
- subtract :: Num a => a -> a -> a
- class Num a => Fractional a where
- (/) :: a -> a -> a
- recip :: a -> a
- fromRational :: Rational -> a
- fromIntegral :: (Integral a, Num b) => a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
- class (Real a, Enum a) => Integral a where
- class (Num a, Ord a) => Real a where
- toRational :: a -> Rational
- class (Real a, Fractional a) => RealFrac a where
- data Ratio a
- type Rational = Ratio Integer
- (^) :: (Num a, Integral b) => a -> b -> a
- numerator :: Ratio a -> a
- denominator :: Ratio a -> a
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- data Natural
- integerToBounded :: (Integral a, Bounded a) => Integer -> Maybe a
- integerToNatural :: Integer -> Maybe Natural
Reexports
toIntegralSized :: (Integral a, Integral b, Bits a, Bits b) => a -> Maybe b #
Attempt to convert an Integral
type a
to an Integral
type b
using
the size of the types as measured by Bits
methods.
A simpler version of this function is:
toIntegral :: (Integral a, Integral b) => a -> Maybe b toIntegral x | toInteger x == toInteger y = Just y | otherwise = Nothing where y = fromIntegral x
This version requires going through Integer
, which can be inefficient.
However, toIntegralSized
is optimized to allow GHC to statically determine
the relative type sizes (as measured by bitSizeMaybe
and isSigned
) and
avoid going through Integer
for many types. (The implementation uses
fromIntegral
, which is itself optimized with rules for base
types but may
go through Integer
for some type pairs.)
@since base-4.8.0.0
module Data.Int
8-bit unsigned integer type
Instances
PrintfArg Word8 | Since: base-2.1 |
Defined in Text.Printf | |
NFData Word8 | |
Defined in Control.DeepSeq | |
Bits Word8 | @since base-2.01 |
Defined in GHC.Internal.Word Methods (.&.) :: Word8 -> Word8 -> Word8 # (.|.) :: Word8 -> Word8 -> Word8 # xor :: Word8 -> Word8 -> Word8 # complement :: Word8 -> Word8 # shift :: Word8 -> Int -> Word8 # rotate :: Word8 -> Int -> Word8 # setBit :: Word8 -> Int -> Word8 # clearBit :: Word8 -> Int -> Word8 # complementBit :: Word8 -> Int -> Word8 # testBit :: Word8 -> Int -> Bool # bitSizeMaybe :: Word8 -> Maybe Int # shiftL :: Word8 -> Int -> Word8 # unsafeShiftL :: Word8 -> Int -> Word8 # shiftR :: Word8 -> Int -> Word8 # unsafeShiftR :: Word8 -> Int -> Word8 # rotateL :: Word8 -> Int -> Word8 # | |
FiniteBits Word8 | @since base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word8 -> Int # countLeadingZeros :: Word8 -> Int # countTrailingZeros :: Word8 -> Int # | |
Data Word8 | @since base-4.0.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word8 -> c Word8 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word8 # dataTypeOf :: Word8 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word8) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word8) # gmapT :: (forall b. Data b => b -> b) -> Word8 -> Word8 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word8 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word8 -> r # gmapQ :: (forall d. Data d => d -> u) -> Word8 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word8 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word8 -> m Word8 # | |
Bounded Word8 | @since base-2.01 |
Enum Word8 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Ix Word8 | @since base-2.01 |
Num Word8 | @since base-2.01 |
Read Word8 | @since base-2.01 |
Integral Word8 | @since base-2.01 |
Real Word8 | @since base-2.01 |
Defined in GHC.Internal.Word Methods toRational :: Word8 -> Rational # | |
Show Word8 | @since base-2.01 |
Eq Word8 | @since base-2.01 |
Ord Word8 | @since base-2.01 |
Hashable Word8 | |
Defined in Data.Hashable.Class | |
Lift Word8 | |
Instances
PrintfArg Word | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
NFData Word | |||||
Defined in Control.DeepSeq | |||||
Bits Word | @since base-2.01 | ||||
Defined in GHC.Internal.Bits Methods (.&.) :: Word -> Word -> Word # (.|.) :: Word -> Word -> Word # complement :: Word -> Word # shift :: Word -> Int -> Word # rotate :: Word -> Int -> Word # setBit :: Word -> Int -> Word # clearBit :: Word -> Int -> Word # complementBit :: Word -> Int -> Word # testBit :: Word -> Int -> Bool # bitSizeMaybe :: Word -> Maybe Int # shiftL :: Word -> Int -> Word # unsafeShiftL :: Word -> Int -> Word # shiftR :: Word -> Int -> Word # unsafeShiftR :: Word -> Int -> Word # rotateL :: Word -> Int -> Word # | |||||
FiniteBits Word | @since base-4.6.0.0 | ||||
Defined in GHC.Internal.Bits Methods finiteBitSize :: Word -> Int # countLeadingZeros :: Word -> Int # countTrailingZeros :: Word -> Int # | |||||
Data Word | @since base-4.0.0.0 | ||||
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word -> c Word # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word # dataTypeOf :: Word -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word) # gmapT :: (forall b. Data b => b -> b) -> Word -> Word # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word -> r # gmapQ :: (forall d. Data d => d -> u) -> Word -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word -> m Word # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word -> m Word # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word -> m Word # | |||||
Bounded Word | @since base-2.01 | ||||
Enum Word | @since base-2.01 | ||||
Num Word | @since base-2.01 | ||||
Read Word | @since base-4.5.0.0 | ||||
Integral Word | @since base-2.01 | ||||
Real Word | @since base-2.01 | ||||
Defined in GHC.Internal.Real Methods toRational :: Word -> Rational # | |||||
Show Word | @since base-2.01 | ||||
Eq Word | |||||
Ord Word | |||||
Hashable Word | |||||
Defined in Data.Hashable.Class | |||||
Lift Word | |||||
Generic1 (URec Word :: k -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Foldable (UWord :: Type -> Type) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => UWord m -> m # foldMap :: Monoid m => (a -> m) -> UWord a -> m # foldMap' :: Monoid m => (a -> m) -> UWord a -> m # foldr :: (a -> b -> b) -> b -> UWord a -> b # foldr' :: (a -> b -> b) -> b -> UWord a -> b # foldl :: (b -> a -> b) -> b -> UWord a -> b # foldl' :: (b -> a -> b) -> b -> UWord a -> b # foldr1 :: (a -> a -> a) -> UWord a -> a # foldl1 :: (a -> a -> a) -> UWord a -> a # elem :: Eq a => a -> UWord a -> Bool # maximum :: Ord a => UWord a -> a # minimum :: Ord a => UWord a -> a # | |||||
Traversable (UWord :: Type -> Type) | @since base-4.9.0.0 | ||||
Functor (URec Word :: Type -> Type) | @since base-4.9.0.0 | ||||
Generic (URec Word p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Show (URec Word p) | @since base-4.9.0.0 | ||||
Eq (URec Word p) | @since base-4.9.0.0 | ||||
Ord (URec Word p) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
data URec Word (p :: k) | Used for marking occurrences of @since base-4.9.0.0 | ||||
type Rep1 (URec Word :: k -> Type) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
type Rep (URec Word p) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics |
64-bit unsigned integer type
Instances
PrintfArg Word64 | Since: base-2.1 |
Defined in Text.Printf | |
NFData Word64 | |
Defined in Control.DeepSeq | |
Bits Word64 | @since base-2.01 |
Defined in GHC.Internal.Word Methods (.&.) :: Word64 -> Word64 -> Word64 # (.|.) :: Word64 -> Word64 -> Word64 # xor :: Word64 -> Word64 -> Word64 # complement :: Word64 -> Word64 # shift :: Word64 -> Int -> Word64 # rotate :: Word64 -> Int -> Word64 # setBit :: Word64 -> Int -> Word64 # clearBit :: Word64 -> Int -> Word64 # complementBit :: Word64 -> Int -> Word64 # testBit :: Word64 -> Int -> Bool # bitSizeMaybe :: Word64 -> Maybe Int # shiftL :: Word64 -> Int -> Word64 # unsafeShiftL :: Word64 -> Int -> Word64 # shiftR :: Word64 -> Int -> Word64 # unsafeShiftR :: Word64 -> Int -> Word64 # rotateL :: Word64 -> Int -> Word64 # | |
FiniteBits Word64 | @since base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word64 -> Int # countLeadingZeros :: Word64 -> Int # countTrailingZeros :: Word64 -> Int # | |
Data Word64 | @since base-4.0.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word64 -> c Word64 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word64 # toConstr :: Word64 -> Constr # dataTypeOf :: Word64 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word64) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word64) # gmapT :: (forall b. Data b => b -> b) -> Word64 -> Word64 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word64 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word64 -> r # gmapQ :: (forall d. Data d => d -> u) -> Word64 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word64 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word64 -> m Word64 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word64 -> m Word64 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word64 -> m Word64 # | |
Bounded Word64 | @since base-2.01 |
Enum Word64 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Ix Word64 | @since base-2.01 |
Num Word64 | @since base-2.01 |
Read Word64 | @since base-2.01 |
Integral Word64 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Real Word64 | @since base-2.01 |
Defined in GHC.Internal.Word Methods toRational :: Word64 -> Rational # | |
Show Word64 | @since base-2.01 |
Eq Word64 | @since base-2.01 |
Ord Word64 | @since base-2.01 |
Hashable Word64 | |
Defined in Data.Hashable.Class | |
Lift Word64 | |
32-bit unsigned integer type
Instances
PrintfArg Word32 | Since: base-2.1 |
Defined in Text.Printf | |
NFData Word32 | |
Defined in Control.DeepSeq | |
Bits Word32 | @since base-2.01 |
Defined in GHC.Internal.Word Methods (.&.) :: Word32 -> Word32 -> Word32 # (.|.) :: Word32 -> Word32 -> Word32 # xor :: Word32 -> Word32 -> Word32 # complement :: Word32 -> Word32 # shift :: Word32 -> Int -> Word32 # rotate :: Word32 -> Int -> Word32 # setBit :: Word32 -> Int -> Word32 # clearBit :: Word32 -> Int -> Word32 # complementBit :: Word32 -> Int -> Word32 # testBit :: Word32 -> Int -> Bool # bitSizeMaybe :: Word32 -> Maybe Int # shiftL :: Word32 -> Int -> Word32 # unsafeShiftL :: Word32 -> Int -> Word32 # shiftR :: Word32 -> Int -> Word32 # unsafeShiftR :: Word32 -> Int -> Word32 # rotateL :: Word32 -> Int -> Word32 # | |
FiniteBits Word32 | @since base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word32 -> Int # countLeadingZeros :: Word32 -> Int # countTrailingZeros :: Word32 -> Int # | |
Data Word32 | @since base-4.0.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word32 -> c Word32 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word32 # toConstr :: Word32 -> Constr # dataTypeOf :: Word32 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word32) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word32) # gmapT :: (forall b. Data b => b -> b) -> Word32 -> Word32 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word32 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word32 -> r # gmapQ :: (forall d. Data d => d -> u) -> Word32 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word32 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word32 -> m Word32 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word32 -> m Word32 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word32 -> m Word32 # | |
Bounded Word32 | @since base-2.01 |
Enum Word32 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Ix Word32 | @since base-2.01 |
Num Word32 | @since base-2.01 |
Read Word32 | @since base-2.01 |
Integral Word32 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Real Word32 | @since base-2.01 |
Defined in GHC.Internal.Word Methods toRational :: Word32 -> Rational # | |
Show Word32 | @since base-2.01 |
Eq Word32 | @since base-2.01 |
Ord Word32 | @since base-2.01 |
Hashable Word32 | |
Defined in Data.Hashable.Class | |
Lift Word32 | |
16-bit unsigned integer type
Instances
PrintfArg Word16 | Since: base-2.1 |
Defined in Text.Printf | |
NFData Word16 | |
Defined in Control.DeepSeq | |
Bits Word16 | @since base-2.01 |
Defined in GHC.Internal.Word Methods (.&.) :: Word16 -> Word16 -> Word16 # (.|.) :: Word16 -> Word16 -> Word16 # xor :: Word16 -> Word16 -> Word16 # complement :: Word16 -> Word16 # shift :: Word16 -> Int -> Word16 # rotate :: Word16 -> Int -> Word16 # setBit :: Word16 -> Int -> Word16 # clearBit :: Word16 -> Int -> Word16 # complementBit :: Word16 -> Int -> Word16 # testBit :: Word16 -> Int -> Bool # bitSizeMaybe :: Word16 -> Maybe Int # shiftL :: Word16 -> Int -> Word16 # unsafeShiftL :: Word16 -> Int -> Word16 # shiftR :: Word16 -> Int -> Word16 # unsafeShiftR :: Word16 -> Int -> Word16 # rotateL :: Word16 -> Int -> Word16 # | |
FiniteBits Word16 | @since base-4.6.0.0 |
Defined in GHC.Internal.Word Methods finiteBitSize :: Word16 -> Int # countLeadingZeros :: Word16 -> Int # countTrailingZeros :: Word16 -> Int # | |
Data Word16 | @since base-4.0.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Word16 -> c Word16 # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Word16 # toConstr :: Word16 -> Constr # dataTypeOf :: Word16 -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Word16) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Word16) # gmapT :: (forall b. Data b => b -> b) -> Word16 -> Word16 # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Word16 -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Word16 -> r # gmapQ :: (forall d. Data d => d -> u) -> Word16 -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Word16 -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Word16 -> m Word16 # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Word16 -> m Word16 # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Word16 -> m Word16 # | |
Bounded Word16 | @since base-2.01 |
Enum Word16 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Ix Word16 | @since base-2.01 |
Num Word16 | @since base-2.01 |
Read Word16 | @since base-2.01 |
Integral Word16 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Real Word16 | @since base-2.01 |
Defined in GHC.Internal.Word Methods toRational :: Word16 -> Rational # | |
Show Word16 | @since base-2.01 |
Eq Word16 | @since base-2.01 |
Ord Word16 | @since base-2.01 |
Hashable Word16 | |
Defined in Data.Hashable.Class | |
Lift Word16 | |
byteSwap16 :: Word16 -> Word16 #
Reverse order of bytes in Word16
.
@since base-4.7.0.0
byteSwap32 :: Word32 -> Word32 #
Reverse order of bytes in Word32
.
@since base-4.7.0.0
byteSwap64 :: Word64 -> Word64 #
Reverse order of bytes in Word64
.
@since base-4.7.0.0
Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.
Instances
PrintfArg Float | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
NFData Float | |||||
Defined in Control.DeepSeq | |||||
Data Float | @since base-4.0.0.0 | ||||
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Float -> c Float # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Float # dataTypeOf :: Float -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Float) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Float) # gmapT :: (forall b. Data b => b -> b) -> Float -> Float # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Float -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Float -> r # gmapQ :: (forall d. Data d => d -> u) -> Float -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Float -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Float -> m Float # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Float -> m Float # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Float -> m Float # | |||||
Floating Float | @since base-2.01 | ||||
RealFloat Float | @since base-2.01 | ||||
Defined in GHC.Internal.Float Methods floatRadix :: Float -> Integer # floatDigits :: Float -> Int # floatRange :: Float -> (Int, Int) # decodeFloat :: Float -> (Integer, Int) # encodeFloat :: Integer -> Int -> Float # significand :: Float -> Float # scaleFloat :: Int -> Float -> Float # isInfinite :: Float -> Bool # isDenormalized :: Float -> Bool # isNegativeZero :: Float -> Bool # | |||||
Read Float | @since base-2.01 | ||||
Eq Float | Note that due to the presence of
Also note that
| ||||
Ord Float | See | ||||
Hashable Float | Note: prior to The Since: hashable-1.3.0.0 | ||||
Defined in Data.Hashable.Class | |||||
Lift Float | |||||
Generic1 (URec Float :: k -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Foldable (UFloat :: Type -> Type) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => UFloat m -> m # foldMap :: Monoid m => (a -> m) -> UFloat a -> m # foldMap' :: Monoid m => (a -> m) -> UFloat a -> m # foldr :: (a -> b -> b) -> b -> UFloat a -> b # foldr' :: (a -> b -> b) -> b -> UFloat a -> b # foldl :: (b -> a -> b) -> b -> UFloat a -> b # foldl' :: (b -> a -> b) -> b -> UFloat a -> b # foldr1 :: (a -> a -> a) -> UFloat a -> a # foldl1 :: (a -> a -> a) -> UFloat a -> a # elem :: Eq a => a -> UFloat a -> Bool # maximum :: Ord a => UFloat a -> a # minimum :: Ord a => UFloat a -> a # | |||||
Traversable (UFloat :: Type -> Type) | @since base-4.9.0.0 | ||||
Functor (URec Float :: Type -> Type) | @since base-4.9.0.0 | ||||
Generic (URec Float p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Show (URec Float p) | |||||
Eq (URec Float p) | |||||
Ord (URec Float p) | |||||
Defined in GHC.Internal.Generics | |||||
data URec Float (p :: k) | Used for marking occurrences of @since base-4.9.0.0 | ||||
type Rep1 (URec Float :: k -> Type) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
type Rep (URec Float p) | |||||
Defined in GHC.Internal.Generics |
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
Instances
PrintfArg Double | Since: base-2.1 | ||||
Defined in Text.Printf | |||||
NFData Double | |||||
Defined in Control.DeepSeq | |||||
Data Double | @since base-4.0.0.0 | ||||
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Double -> c Double # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Double # toConstr :: Double -> Constr # dataTypeOf :: Double -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Double) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Double) # gmapT :: (forall b. Data b => b -> b) -> Double -> Double # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Double -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Double -> r # gmapQ :: (forall d. Data d => d -> u) -> Double -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Double -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Double -> m Double # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Double -> m Double # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Double -> m Double # | |||||
Floating Double | @since base-2.01 | ||||
RealFloat Double | @since base-2.01 | ||||
Defined in GHC.Internal.Float Methods floatRadix :: Double -> Integer # floatDigits :: Double -> Int # floatRange :: Double -> (Int, Int) # decodeFloat :: Double -> (Integer, Int) # encodeFloat :: Integer -> Int -> Double # significand :: Double -> Double # scaleFloat :: Int -> Double -> Double # isInfinite :: Double -> Bool # isDenormalized :: Double -> Bool # isNegativeZero :: Double -> Bool # | |||||
Read Double | @since base-2.01 | ||||
Eq Double | Note that due to the presence of
Also note that
| ||||
Ord Double | IEEE 754 IEEE 754-2008, section 5.11 requires that if at least one of arguments of
IEEE 754-2008, section 5.10 defines Thus, users must be extremely cautious when using Moving further, the behaviour of IEEE 754-2008 compliant | ||||
Hashable Double | Note: prior to The Since: hashable-1.3.0.0 | ||||
Defined in Data.Hashable.Class | |||||
Lift Double | |||||
Generic1 (URec Double :: k -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Foldable (UDouble :: Type -> Type) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => UDouble m -> m # foldMap :: Monoid m => (a -> m) -> UDouble a -> m # foldMap' :: Monoid m => (a -> m) -> UDouble a -> m # foldr :: (a -> b -> b) -> b -> UDouble a -> b # foldr' :: (a -> b -> b) -> b -> UDouble a -> b # foldl :: (b -> a -> b) -> b -> UDouble a -> b # foldl' :: (b -> a -> b) -> b -> UDouble a -> b # foldr1 :: (a -> a -> a) -> UDouble a -> a # foldl1 :: (a -> a -> a) -> UDouble a -> a # elem :: Eq a => a -> UDouble a -> Bool # maximum :: Ord a => UDouble a -> a # minimum :: Ord a => UDouble a -> a # | |||||
Traversable (UDouble :: Type -> Type) | @since base-4.9.0.0 | ||||
Functor (URec Double :: Type -> Type) | @since base-4.9.0.0 | ||||
Generic (URec Double p) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Show (URec Double p) | @since base-4.9.0.0 | ||||
Eq (URec Double p) | @since base-4.9.0.0 | ||||
Ord (URec Double p) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics Methods compare :: URec Double p -> URec Double p -> Ordering # (<) :: URec Double p -> URec Double p -> Bool # (<=) :: URec Double p -> URec Double p -> Bool # (>) :: URec Double p -> URec Double p -> Bool # (>=) :: URec Double p -> URec Double p -> Bool # | |||||
data URec Double (p :: k) | Used for marking occurrences of @since base-4.9.0.0 | ||||
type Rep1 (URec Double :: k -> Type) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
type Rep (URec Double p) | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics |
class Fractional a => Floating a where #
Trigonometric and hyperbolic functions and related functions.
The Haskell Report defines no laws for Floating
. However, (
, +
)(
and *
)exp
are customarily expected to define an exponential field and have
the following properties:
exp (a + b)
=exp a * exp b
exp (fromInteger 0)
=fromInteger 1
Minimal complete definition
pi, exp, log, sin, cos, asin, acos, atan, sinh, cosh, asinh, acosh, atanh
Instances
class (RealFrac a, Floating a) => RealFloat a where #
Efficient, machine-independent access to the components of a floating-point number.
Minimal complete definition
floatRadix, floatDigits, floatRange, decodeFloat, encodeFloat, isNaN, isInfinite, isDenormalized, isNegativeZero, isIEEE
Methods
floatRadix :: a -> Integer #
a constant function, returning the radix of the representation
(often 2
)
floatDigits :: a -> Int #
a constant function, returning the number of digits of
floatRadix
in the significand
floatRange :: a -> (Int, Int) #
a constant function, returning the lowest and highest values the exponent may assume
decodeFloat :: a -> (Integer, Int) #
The function decodeFloat
applied to a real floating-point
number returns the significand expressed as an Integer
and an
appropriately scaled exponent (an Int
). If
yields decodeFloat
x(m,n)
, then x
is equal in value to m*b^^n
, where b
is the floating-point radix, and furthermore, either m
and n
are both zero or else b^(d-1) <=
, where abs
m < b^dd
is
the value of
.
In particular, floatDigits
x
. If the type
contains a negative zero, also decodeFloat
0 = (0,0)
.
The result of decodeFloat
(-0.0) = (0,0)
is unspecified if either of
decodeFloat
x
or isNaN
x
is isInfinite
xTrue
.
encodeFloat :: Integer -> Int -> a #
encodeFloat
performs the inverse of decodeFloat
in the
sense that for finite x
with the exception of -0.0
,
.
uncurry
encodeFloat
(decodeFloat
x) = x
is one of the two closest representable
floating-point numbers to encodeFloat
m nm*b^^n
(or ±Infinity
if overflow
occurs); usually the closer, but if m
contains too many bits,
the result may be rounded in the wrong direction.
True
if the argument is an IEEE "not-a-number" (NaN) value
isInfinite :: a -> Bool #
True
if the argument is an IEEE infinity or negative infinity
isDenormalized :: a -> Bool #
True
if the argument is too small to be represented in
normalized format
isNegativeZero :: a -> Bool #
True
if the argument is an IEEE negative zero
True
if the argument is an IEEE floating point number
a version of arctangent taking two real floating-point arguments.
For real floating x
and y
,
computes the angle
(from the positive x-axis) of the vector from the origin to the
point atan2
y x(x,y)
.
returns a value in the range [atan2
y x-pi
,
pi
]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported.
, with atan2
y 1y
in a type
that is RealFloat
, should return the same value as
.
A default definition of atan
yatan2
is provided, but implementors
can provide a more accurate implementation.
Instances
Arbitrary precision integers. In contrast with fixed-size integral types
such as Int
, the Integer
type represents the entire infinite range of
integers.
Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.
If the value is small (i.e., fits into an Int
), the IS
constructor is
used. Otherwise IP
and IN
constructors are used to store a BigNat
representing the positive or the negative value magnitude, respectively.
Invariant: IP
and IN
are used iff the value does not fit in IS
.
Instances
PrintfArg Integer | Since: base-2.1 |
Defined in Text.Printf | |
NFData Integer | |
Defined in Control.DeepSeq | |
Bits Integer | @since base-2.01 |
Defined in GHC.Internal.Bits Methods (.&.) :: Integer -> Integer -> Integer # (.|.) :: Integer -> Integer -> Integer # xor :: Integer -> Integer -> Integer # complement :: Integer -> Integer # shift :: Integer -> Int -> Integer # rotate :: Integer -> Int -> Integer # setBit :: Integer -> Int -> Integer # clearBit :: Integer -> Int -> Integer # complementBit :: Integer -> Int -> Integer # testBit :: Integer -> Int -> Bool # bitSizeMaybe :: Integer -> Maybe Int # shiftL :: Integer -> Int -> Integer # unsafeShiftL :: Integer -> Int -> Integer # shiftR :: Integer -> Int -> Integer # unsafeShiftR :: Integer -> Int -> Integer # rotateL :: Integer -> Int -> Integer # | |
Data Integer | @since base-4.0.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Integer -> c Integer # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Integer # toConstr :: Integer -> Constr # dataTypeOf :: Integer -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Integer) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Integer) # gmapT :: (forall b. Data b => b -> b) -> Integer -> Integer # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Integer -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Integer -> r # gmapQ :: (forall d. Data d => d -> u) -> Integer -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Integer -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Integer -> m Integer # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Integer -> m Integer # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Integer -> m Integer # | |
Enum Integer | @since base-2.01 |
Num Integer | @since base-2.01 |
Read Integer | @since base-2.01 |
Integral Integer | @since base-2.0.1 |
Defined in GHC.Internal.Real | |
Real Integer | @since base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Integer -> Rational # | |
Show Integer | @since base-2.01 |
Eq Integer | |
Ord Integer | |
Hashable Integer | |
Defined in Data.Hashable.Class | |
Lift Integer | |
Basic numeric class.
The Haskell Report defines no laws for Num
. However, (
and +
)(
are
customarily expected to define a ring and have the following properties:*
)
- Associativity of
(
+
) (x + y) + z
=x + (y + z)
- Commutativity of
(
+
) x + y
=y + x
is the additive identityfromInteger
0x + fromInteger 0
=x
negate
gives the additive inversex + negate x
=fromInteger 0
- Associativity of
(
*
) (x * y) * z
=x * (y * z)
is the multiplicative identityfromInteger
1x * fromInteger 1
=x
andfromInteger 1 * x
=x
- Distributivity of
(
with respect to*
)(
+
) a * (b + c)
=(a * b) + (a * c)
and(b + c) * a
=(b * a) + (c * a)
- Coherence with
toInteger
- if the type also implements
Integral
, thenfromInteger
is a left inverse fortoInteger
, i.e.fromInteger (toInteger i) == i
Note that it isn't customarily expected that a type instance of both Num
and Ord
implement an ordered ring. Indeed, in base
only Integer
and
Rational
do.
Methods
Unary negation.
Absolute value.
Sign of a number.
The functions abs
and signum
should satisfy the law:
abs x * signum x == x
For real numbers, the signum
is either -1
(negative), 0
(zero)
or 1
(positive).
fromInteger :: Integer -> a #
Conversion from an Integer
.
An integer literal represents the application of the function
fromInteger
to the appropriate value of type Integer
,
so such literals have type (
.Num
a) => a
Instances
Num Int16 | @since base-2.01 |
Num Int32 | @since base-2.01 |
Num Int64 | @since base-2.01 |
Num Int8 | @since base-2.01 |
Num Word16 | @since base-2.01 |
Num Word32 | @since base-2.01 |
Num Word64 | @since base-2.01 |
Num Word8 | @since base-2.01 |
Num I8 | |
Num Size | |
Num Integer | @since base-2.01 |
Num Natural | Note that @since base-4.8.0.0 |
Num Int | @since base-2.01 |
Num Word | @since base-2.01 |
RealFloat a => Num (Complex a) | Since: base-2.1 |
Num a => Num (Max a) | Since: base-4.9.0.0 |
Num a => Num (Min a) | Since: base-4.9.0.0 |
Num a => Num (Identity a) | @since base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity | |
Num a => Num (Down a) | @since base-4.11.0.0 |
Num a => Num (Product a) | @since base-4.7.0.0 |
Defined in GHC.Internal.Data.Semigroup.Internal | |
Num a => Num (Sum a) | @since base-4.7.0.0 |
Integral a => Num (Ratio a) | @since base-2.0.1 |
HasResolution a => Num (Fixed a) | Multiplication is not associative or distributive:
Since: base-2.1 |
Num a => Num (Op a b) | |
Num a => Num (Const a b) | @since base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const | |
(Applicative f, Num a) => Num (Ap f a) | Note that even if the underlying Commutativity:
Additive inverse:
Distributivity:
@since base-4.12.0.0 |
Num (f a) => Num (Alt f a) | @since base-4.8.0.0 |
Num (f (g a)) => Num (Compose f g a) | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods (+) :: Compose f g a -> Compose f g a -> Compose f g a # (-) :: Compose f g a -> Compose f g a -> Compose f g a # (*) :: Compose f g a -> Compose f g a -> Compose f g a # negate :: Compose f g a -> Compose f g a # abs :: Compose f g a -> Compose f g a # signum :: Compose f g a -> Compose f g a # fromInteger :: Integer -> Compose f g a # |
class Num a => Fractional a where #
Fractional numbers, supporting real division.
The Haskell Report defines no laws for Fractional
. However, (
and
+
)(
are customarily expected to define a division ring and have the
following properties:*
)
recip
gives the multiplicative inversex * recip x
=recip x * x
=fromInteger 1
- Totality of
toRational
toRational
is total- Coherence with
toRational
- if the type also implements
Real
, thenfromRational
is a left inverse fortoRational
, i.e.fromRational (toRational i) = i
Note that it isn't customarily expected that a type instance of
Fractional
implement a field. However, all instances in base
do.
Minimal complete definition
fromRational, (recip | (/))
Methods
Fractional division.
Reciprocal fraction.
fromRational :: Rational -> a #
Conversion from a Rational
(that is
).
A floating literal stands for an application of Ratio
Integer
fromRational
to a value of type Rational
, so such literals have type
(
.Fractional
a) => a
Instances
RealFloat a => Fractional (Complex a) | Since: base-2.1 |
Fractional a => Fractional (Identity a) | @since base-4.9.0.0 |
Fractional a => Fractional (Down a) | @since base-4.14.0.0 |
Integral a => Fractional (Ratio a) | @since base-2.0.1 |
HasResolution a => Fractional (Fixed a) | Since: base-2.1 |
Fractional a => Fractional (Op a b) | |
Fractional a => Fractional (Const a b) | @since base-4.9.0.0 |
Fractional (f (g a)) => Fractional (Compose f g a) | Since: base-4.20.0.0 |
fromIntegral :: (Integral a, Num b) => a -> b #
General coercion from Integral
types.
WARNING: This function performs silent truncation if the result type is not at least as big as the argument's type.
realToFrac :: (Real a, Fractional b) => a -> b #
General coercion to Fractional
types.
WARNING: This function goes through the Rational
type, which does not have values for NaN
for example.
This means it does not round-trip.
For Double
it also behaves differently with or without -O0:
Prelude> realToFrac nan -- With -O0 -Infinity Prelude> realToFrac nan NaN
class (Real a, Enum a) => Integral a where #
Integral numbers, supporting integer division.
The Haskell Report defines no laws for Integral
. However, Integral
instances are customarily expected to define a Euclidean domain and have the
following properties for the div
/mod
and quot
/rem
pairs, given
suitable Euclidean functions f
and g
:
x
=y * quot x y + rem x y
withrem x y
=fromInteger 0
org (rem x y)
<g y
x
=y * div x y + mod x y
withmod x y
=fromInteger 0
orf (mod x y)
<f y
An example of a suitable Euclidean function, for Integer
's instance, is
abs
.
In addition, toInteger
should be total, and fromInteger
should be a left
inverse for it, i.e. fromInteger (toInteger i) = i
.
Methods
quot :: a -> a -> a infixl 7 #
Integer division truncated toward zero.
WARNING: This function is partial (because it throws when 0 is passed as
the divisor) for all the integer types in base
.
Integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
WARNING: This function is partial (because it throws when 0 is passed as
the divisor) for all the integer types in base
.
Integer division truncated toward negative infinity.
WARNING: This function is partial (because it throws when 0 is passed as
the divisor) for all the integer types in base
.
Integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
WARNING: This function is partial (because it throws when 0 is passed as
the divisor) for all the integer types in base
.
WARNING: This function is partial (because it throws when 0 is passed as
the divisor) for all the integer types in base
.
WARNING: This function is partial (because it throws when 0 is passed as
the divisor) for all the integer types in base
.
Conversion to Integer
.
Instances
Integral Int16 | @since base-2.01 |
Integral Int32 | @since base-2.01 |
Integral Int64 | @since base-2.01 |
Integral Int8 | @since base-2.01 |
Integral Word16 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Integral Word32 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Integral Word64 | @since base-2.01 |
Defined in GHC.Internal.Word | |
Integral Word8 | @since base-2.01 |
Integral I8 | |
Integral Integer | @since base-2.0.1 |
Defined in GHC.Internal.Real | |
Integral Natural | @since base-4.8.0.0 |
Defined in GHC.Internal.Real | |
Integral Int | @since base-2.0.1 |
Integral Word | @since base-2.01 |
Integral a => Integral (Identity a) | @since base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods quot :: Identity a -> Identity a -> Identity a # rem :: Identity a -> Identity a -> Identity a # div :: Identity a -> Identity a -> Identity a # mod :: Identity a -> Identity a -> Identity a # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) # divMod :: Identity a -> Identity a -> (Identity a, Identity a) # | |
Integral a => Integral (Const a b) | @since base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b # rem :: Const a b -> Const a b -> Const a b # div :: Const a b -> Const a b -> Const a b # mod :: Const a b -> Const a b -> Const a b # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) # divMod :: Const a b -> Const a b -> (Const a b, Const a b) # | |
Integral (f (g a)) => Integral (Compose f g a) | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods quot :: Compose f g a -> Compose f g a -> Compose f g a # rem :: Compose f g a -> Compose f g a -> Compose f g a # div :: Compose f g a -> Compose f g a -> Compose f g a # mod :: Compose f g a -> Compose f g a -> Compose f g a # quotRem :: Compose f g a -> Compose f g a -> (Compose f g a, Compose f g a) # divMod :: Compose f g a -> Compose f g a -> (Compose f g a, Compose f g a) # |
class (Num a, Ord a) => Real a where #
Real numbers.
The Haskell report defines no laws for Real
, however Real
instances
are customarily expected to adhere to the following law:
- Coherence with
fromRational
- if the type also implements
Fractional
, thenfromRational
is a left inverse fortoRational
, i.e.fromRational (toRational i) = i
The law does not hold for Float
, Double
, CFloat
,
CDouble
, etc., because these types contain non-finite values,
which cannot be roundtripped through Rational
.
Instances
class (Real a, Fractional a) => RealFrac a where #
Extracting components of fractions.
Minimal complete definition
Methods
properFraction :: Integral b => a -> (b, a) #
The function properFraction
takes a real fractional number x
and returns a pair (n,f)
such that x = n+f
, and:
n
is an integral number with the same sign asx
; andf
is a fraction with the same type and sign asx
, and with absolute value less than1
.
The default definitions of the ceiling
, floor
, truncate
and round
functions are in terms of properFraction
.
truncate :: Integral b => a -> b #
returns the integer nearest truncate
xx
between zero and x
round :: Integral b => a -> b #
returns the nearest integer to round
xx
;
the even integer if x
is equidistant between two integers
ceiling :: Integral b => a -> b #
returns the least integer not less than ceiling
xx
floor :: Integral b => a -> b #
returns the greatest integer not greater than floor
xx
Instances
RealFrac a => RealFrac (Identity a) | @since base-4.9.0.0 |
RealFrac a => RealFrac (Down a) | @since base-4.14.0.0 |
Integral a => RealFrac (Ratio a) | @since base-2.0.1 |
HasResolution a => RealFrac (Fixed a) | Since: base-2.1 |
RealFrac a => RealFrac (Const a b) | @since base-4.9.0.0 |
RealFrac (f (g a)) => RealFrac (Compose f g a) | Since: base-4.20.0.0 |
Rational numbers, with numerator and denominator of some Integral
type.
Note that Ratio
's instances inherit the deficiencies from the type
parameter's. For example, Ratio Natural
's Num
instance has similar
problems to Natural
's.
Instances
NFData1 Ratio | Available on Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Integral a => Lift (Ratio a :: Type) | |
NFData a => NFData (Ratio a) | |
Defined in Control.DeepSeq | |
(Data a, Integral a) => Data (Ratio a) | @since base-4.0.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ratio a -> c (Ratio a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ratio a) # toConstr :: Ratio a -> Constr # dataTypeOf :: Ratio a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Ratio a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ratio a)) # gmapT :: (forall b. Data b => b -> b) -> Ratio a -> Ratio a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r # gmapQ :: (forall d. Data d => d -> u) -> Ratio a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ratio a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) # | |
Integral a => Enum (Ratio a) | @since base-2.0.1 |
Integral a => Num (Ratio a) | @since base-2.0.1 |
(Integral a, Read a) => Read (Ratio a) | @since base-2.01 |
Integral a => Fractional (Ratio a) | @since base-2.0.1 |
Integral a => Real (Ratio a) | @since base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Ratio a -> Rational # | |
Integral a => RealFrac (Ratio a) | @since base-2.0.1 |
Show a => Show (Ratio a) | @since base-2.0.1 |
Eq a => Eq (Ratio a) | @since base-2.01 |
Integral a => Ord (Ratio a) | @since base-2.0.1 |
Hashable a => Hashable (Ratio a) | |
Defined in Data.Hashable.Class |
Extract the numerator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
denominator :: Ratio a -> a #
Extract the denominator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 #
raise a number to an integral power
gcd :: Integral a => a -> a -> a #
is the non-negative factor of both gcd
x yx
and y
of which
every common factor of x
and y
is also a factor; for example
, gcd
4 2 = 2
, gcd
(-4) 6 = 2
= gcd
0 44
.
= gcd
0 00
.
(That is, the common divisor that is "greatest" in the divisibility
preordering.)
Note: Since for signed fixed-width integer types,
,
the result may be negative if one of the arguments is abs
minBound
< 0
(and
necessarily is if the other is minBound
0
or
) for such types.minBound
lcm :: Integral a => a -> a -> a #
is the smallest positive integer that both lcm
x yx
and y
divide.
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS
constructor
Instances
PrintfArg Natural | Since: base-4.8.0.0 |
Defined in Text.Printf | |
NFData Natural | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Bits Natural | @since base-4.8.0 |
Defined in GHC.Internal.Bits Methods (.&.) :: Natural -> Natural -> Natural # (.|.) :: Natural -> Natural -> Natural # xor :: Natural -> Natural -> Natural # complement :: Natural -> Natural # shift :: Natural -> Int -> Natural # rotate :: Natural -> Int -> Natural # setBit :: Natural -> Int -> Natural # clearBit :: Natural -> Int -> Natural # complementBit :: Natural -> Int -> Natural # testBit :: Natural -> Int -> Bool # bitSizeMaybe :: Natural -> Maybe Int # shiftL :: Natural -> Int -> Natural # unsafeShiftL :: Natural -> Int -> Natural # shiftR :: Natural -> Int -> Natural # unsafeShiftR :: Natural -> Int -> Natural # rotateL :: Natural -> Int -> Natural # | |
Data Natural | @since base-4.8.0.0 |
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Natural -> c Natural # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Natural # toConstr :: Natural -> Constr # dataTypeOf :: Natural -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Natural) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Natural) # gmapT :: (forall b. Data b => b -> b) -> Natural -> Natural # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r # gmapQ :: (forall d. Data d => d -> u) -> Natural -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Natural -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Natural -> m Natural # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural # | |
Enum Natural | @since base-4.8.0.0 |
Num Natural | Note that @since base-4.8.0.0 |
Read Natural | @since base-4.8.0.0 |
Integral Natural | @since base-4.8.0.0 |
Defined in GHC.Internal.Real | |
Real Natural | @since base-4.8.0.0 |
Defined in GHC.Internal.Real Methods toRational :: Natural -> Rational # | |
Show Natural | @since base-4.8.0.0 |
Eq Natural | |
Ord Natural | |
Hashable Natural | |
Defined in Data.Hashable.Class | |
KnownNat n => HasResolution (n :: Nat) | For example, |
Defined in Data.Fixed Methods resolution :: p n -> Integer # | |
TestCoercion SNat | @since base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
TestEquality SNat | @since base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
Lift Natural | |
type Compare (a :: Natural) (b :: Natural) | |
Defined in GHC.Internal.Data.Type.Ord |
Combinators
integerToBounded :: (Integral a, Bounded a) => Integer -> Maybe a Source #
Transforms an integer number to a bounded integral.
It returns Nothing
for integers outside the bound of the return type.
>>>
integerToBounded @Int 42
Just 42
>>>
integerToBounded @Int8 1024
Nothing
>>>
integerToBounded @Int (toInteger (minBound :: Int))
Just (-9223372036854775808)>>>
integerToBounded @Int $ (toInteger (minBound :: Int)) - 1
Nothing
>>>
integerToBounded @Int (toInteger (maxBound :: Int))
Just 9223372036854775807>>>
integerToBounded @Int $ (toInteger (maxBound :: Int)) + 1
Nothing
If you want to convert Int
or Word
to a bounded type, take a look at
toIntegralSized
function instead.
Since: 0.5.0