base-4.15.1.0: Basic libraries

GHC.Real

Description

The types Ratio and Rational, and the classes Real, Fractional, Integral, and RealFrac.

Synopsis

# Documentation

data Ratio a Source #

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.

Constructors

 !a :% !a

#### Instances

Instances details
 (Data a, Integral a) => Data (Ratio a) Source # Since: base-4.0.0.0 Instance detailsDefined in Data.Data Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ratio a -> c (Ratio a) Source #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ratio a) Source #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Ratio a)) Source #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ratio a)) Source #gmapT :: (forall b. Data b => b -> b) -> Ratio a -> Ratio a Source #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r Source #gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r Source #gmapQ :: (forall d. Data d => d -> u) -> Ratio a -> [u] Source #gmapQi :: Int -> (forall d. Data d => d -> u) -> Ratio a -> u Source #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source # (Storable a, Integral a) => Storable (Ratio a) Source # Since: base-4.8.0.0 Instance detailsDefined in Foreign.Storable MethodssizeOf :: Ratio a -> Int Source #alignment :: Ratio a -> Int Source #peekElemOff :: Ptr (Ratio a) -> Int -> IO (Ratio a) Source #pokeElemOff :: Ptr (Ratio a) -> Int -> Ratio a -> IO () Source #peekByteOff :: Ptr b -> Int -> IO (Ratio a) Source #pokeByteOff :: Ptr b -> Int -> Ratio a -> IO () Source #peek :: Ptr (Ratio a) -> IO (Ratio a) Source #poke :: Ptr (Ratio a) -> Ratio a -> IO () Source # Integral a => Enum (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methodssucc :: Ratio a -> Ratio a Source #pred :: Ratio a -> Ratio a Source #fromEnum :: Ratio a -> Int Source #enumFrom :: Ratio a -> [Ratio a] Source #enumFromThen :: Ratio a -> Ratio a -> [Ratio a] Source #enumFromTo :: Ratio a -> Ratio a -> [Ratio a] Source #enumFromThenTo :: Ratio a -> Ratio a -> Ratio a -> [Ratio a] Source # Integral a => Num (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods(+) :: Ratio a -> Ratio a -> Ratio a Source #(-) :: Ratio a -> Ratio a -> Ratio a Source #(*) :: Ratio a -> Ratio a -> Ratio a Source #negate :: Ratio a -> Ratio a Source #abs :: Ratio a -> Ratio a Source #signum :: Ratio a -> Ratio a Source # (Integral a, Read a) => Read (Ratio a) Source # Since: base-2.1 Instance detailsDefined in GHC.Read Methods Integral a => Fractional (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods(/) :: Ratio a -> Ratio a -> Ratio a Source #recip :: Ratio a -> Ratio a Source # Integral a => Real (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods Integral a => RealFrac (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real MethodsproperFraction :: Integral b => Ratio a -> (b, Ratio a) Source #truncate :: Integral b => Ratio a -> b Source #round :: Integral b => Ratio a -> b Source #ceiling :: Integral b => Ratio a -> b Source #floor :: Integral b => Ratio a -> b Source # Show a => Show (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real MethodsshowsPrec :: Int -> Ratio a -> ShowS Source #show :: Ratio a -> String Source #showList :: [Ratio a] -> ShowS Source # Eq a => Eq (Ratio a) Source # Since: base-2.1 Instance detailsDefined in GHC.Real Methods(==) :: Ratio a -> Ratio a -> Bool Source #(/=) :: Ratio a -> Ratio a -> Bool Source # Integral a => Ord (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methodscompare :: Ratio a -> Ratio a -> Ordering Source #(<) :: Ratio a -> Ratio a -> Bool Source #(<=) :: Ratio a -> Ratio a -> Bool Source #(>) :: Ratio a -> Ratio a -> Bool Source #(>=) :: Ratio a -> Ratio a -> Bool Source #max :: Ratio a -> Ratio a -> Ratio a Source #min :: Ratio a -> Ratio a -> Ratio a Source #

Arbitrary-precision rational numbers, represented as a ratio of two Integer values. A rational number may be constructed using the % operator.

(%) :: Integral a => a -> a -> Ratio a infixl 7 Source #

Forms the ratio of two integral numbers.

numerator :: Ratio a -> a Source #

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 Source #

Extract the denominator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.

reduce :: Integral a => a -> a -> Ratio a Source #

reduce is a subsidiary function used only in this module. It normalises a ratio by dividing both numerator and denominator by their greatest common divisor.

class (Num a, Ord a) => Real a where Source #

Methods

toRational :: a -> Rational Source #

the rational equivalent of its real argument with full precision

#### Instances

Instances details
 Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.Ptr Methods Source # Instance detailsDefined in Foreign.Ptr Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Int Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Int Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Int Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Int Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Word Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Word Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Word Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Word Methods Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods Source # Since: base-4.8.0.0 Instance detailsDefined in GHC.Real Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Float Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Float Methods Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Real Methods Real a => Real (Identity a) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Identity Methods Real a => Real (Down a) Source # Since: base-4.14.0.0 Instance detailsDefined in Data.Ord Methods Integral a => Real (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods HasResolution a => Real (Fixed a) Source # Since: base-2.1 Instance detailsDefined in Data.Fixed Methods Real a => Real (Const a b) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Const MethodstoRational :: Const a b -> Rational Source #

class (Real a, Enum a) => Integral a where Source #

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 with rem x y = fromInteger 0 or g (rem x y) < g y
• x = y * div x y + mod x y with mod x y = fromInteger 0 or f (mod x y) < f y

An example of a suitable Euclidean function, for Integer's instance, is abs.

Minimal complete definition

Methods

quot :: a -> a -> a infixl 7 Source #

integer division truncated toward zero

rem :: a -> a -> a infixl 7 Source #

integer remainder, satisfying

(x quot y)*y + (x rem y) == x

div :: a -> a -> a infixl 7 Source #

integer division truncated toward negative infinity

mod :: a -> a -> a infixl 7 Source #

integer modulus, satisfying

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

quotRem :: a -> a -> (a, a) Source #

simultaneous quot and rem

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

simultaneous div and mod

toInteger :: a -> Integer Source #

conversion to Integer

#### Instances

Instances details
 Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CBool -> CBool -> (CBool, CBool) Source #divMod :: CBool -> CBool -> (CBool, CBool) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CChar -> CChar -> (CChar, CChar) Source #divMod :: CChar -> CChar -> (CChar, CChar) Source # Source # Instance detailsDefined in Foreign.C.Types Methodsquot :: CInt -> CInt -> CInt Source #rem :: CInt -> CInt -> CInt Source #div :: CInt -> CInt -> CInt Source #mod :: CInt -> CInt -> CInt Source #quotRem :: CInt -> CInt -> (CInt, CInt) Source #divMod :: CInt -> CInt -> (CInt, CInt) Source # Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CLLong -> CLLong -> (CLLong, CLLong) Source #divMod :: CLLong -> CLLong -> (CLLong, CLLong) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CLong -> CLong -> (CLong, CLong) Source #divMod :: CLong -> CLong -> (CLong, CLong) Source # Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CSChar -> CSChar -> (CSChar, CSChar) Source #divMod :: CSChar -> CSChar -> (CSChar, CSChar) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CShort -> CShort -> (CShort, CShort) Source #divMod :: CShort -> CShort -> (CShort, CShort) Source # Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CSize -> CSize -> (CSize, CSize) Source #divMod :: CSize -> CSize -> (CSize, CSize) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CUChar -> CUChar -> (CUChar, CUChar) Source #divMod :: CUChar -> CUChar -> (CUChar, CUChar) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CUInt -> CUInt -> (CUInt, CUInt) Source #divMod :: CUInt -> CUInt -> (CUInt, CUInt) Source # Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CULong -> CULong -> (CULong, CULong) Source #divMod :: CULong -> CULong -> (CULong, CULong) Source # Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types MethodsquotRem :: CWchar -> CWchar -> (CWchar, CWchar) Source #divMod :: CWchar -> CWchar -> (CWchar, CWchar) Source # Source # Instance detailsDefined in Foreign.Ptr MethodsquotRem :: IntPtr -> IntPtr -> (IntPtr, IntPtr) Source #divMod :: IntPtr -> IntPtr -> (IntPtr, IntPtr) Source # Source # Instance detailsDefined in Foreign.Ptr Methods Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsquotRem :: Int16 -> Int16 -> (Int16, Int16) Source #divMod :: Int16 -> Int16 -> (Int16, Int16) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsquotRem :: Int32 -> Int32 -> (Int32, Int32) Source #divMod :: Int32 -> Int32 -> (Int32, Int32) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Int MethodsquotRem :: Int64 -> Int64 -> (Int64, Int64) Source #divMod :: Int64 -> Int64 -> (Int64, Int64) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Int Methodsquot :: Int8 -> Int8 -> Int8 Source #rem :: Int8 -> Int8 -> Int8 Source #div :: Int8 -> Int8 -> Int8 Source #mod :: Int8 -> Int8 -> Int8 Source #quotRem :: Int8 -> Int8 -> (Int8, Int8) Source #divMod :: Int8 -> Int8 -> (Int8, Int8) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsquotRem :: Word16 -> Word16 -> (Word16, Word16) Source #divMod :: Word16 -> Word16 -> (Word16, Word16) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsquotRem :: Word32 -> Word32 -> (Word32, Word32) Source #divMod :: Word32 -> Word32 -> (Word32, Word32) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsquotRem :: Word64 -> Word64 -> (Word64, Word64) Source #divMod :: Word64 -> Word64 -> (Word64, Word64) Source # Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CDev -> CDev -> CDev Source #rem :: CDev -> CDev -> CDev Source #div :: CDev -> CDev -> CDev Source #mod :: CDev -> CDev -> CDev Source #quotRem :: CDev -> CDev -> (CDev, CDev) Source #divMod :: CDev -> CDev -> (CDev, CDev) Source # Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CGid -> CGid -> CGid Source #rem :: CGid -> CGid -> CGid Source #div :: CGid -> CGid -> CGid Source #mod :: CGid -> CGid -> CGid Source #quotRem :: CGid -> CGid -> (CGid, CGid) Source #divMod :: CGid -> CGid -> (CGid, CGid) Source # Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CId -> CId -> CId Source #rem :: CId -> CId -> CId Source #div :: CId -> CId -> CId Source #mod :: CId -> CId -> CId Source #quotRem :: CId -> CId -> (CId, CId) Source #divMod :: CId -> CId -> (CId, CId) Source # Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CIno -> CIno -> CIno Source #rem :: CIno -> CIno -> CIno Source #div :: CIno -> CIno -> CIno Source #mod :: CIno -> CIno -> CIno Source #quotRem :: CIno -> CIno -> (CIno, CIno) Source #divMod :: CIno -> CIno -> (CIno, CIno) Source # Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CKey -> CKey -> CKey Source #rem :: CKey -> CKey -> CKey Source #div :: CKey -> CKey -> CKey Source #mod :: CKey -> CKey -> CKey Source #quotRem :: CKey -> CKey -> (CKey, CKey) Source #divMod :: CKey -> CKey -> (CKey, CKey) Source # Source # Instance detailsDefined in System.Posix.Types MethodsquotRem :: CMode -> CMode -> (CMode, CMode) Source #divMod :: CMode -> CMode -> (CMode, CMode) Source # Source # Instance detailsDefined in System.Posix.Types MethodsquotRem :: CNfds -> CNfds -> (CNfds, CNfds) Source #divMod :: CNfds -> CNfds -> (CNfds, CNfds) Source # Source # Instance detailsDefined in System.Posix.Types MethodsquotRem :: CNlink -> CNlink -> (CNlink, CNlink) Source #divMod :: CNlink -> CNlink -> (CNlink, CNlink) Source # Source # Instance detailsDefined in System.Posix.Types Methodsquot :: COff -> COff -> COff Source #rem :: COff -> COff -> COff Source #div :: COff -> COff -> COff Source #mod :: COff -> COff -> COff Source #quotRem :: COff -> COff -> (COff, COff) Source #divMod :: COff -> COff -> (COff, COff) Source # Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CPid -> CPid -> CPid Source #rem :: CPid -> CPid -> CPid Source #div :: CPid -> CPid -> CPid Source #mod :: CPid -> CPid -> CPid Source #quotRem :: CPid -> CPid -> (CPid, CPid) Source #divMod :: CPid -> CPid -> (CPid, CPid) Source # Source # Instance detailsDefined in System.Posix.Types MethodsquotRem :: CRLim -> CRLim -> (CRLim, CRLim) Source #divMod :: CRLim -> CRLim -> (CRLim, CRLim) Source # Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types MethodsquotRem :: CSsize -> CSsize -> (CSsize, CSsize) Source #divMod :: CSsize -> CSsize -> (CSsize, CSsize) Source # Source # Instance detailsDefined in System.Posix.Types Methods Source # Instance detailsDefined in System.Posix.Types Methodsquot :: CUid -> CUid -> CUid Source #rem :: CUid -> CUid -> CUid Source #div :: CUid -> CUid -> CUid Source #mod :: CUid -> CUid -> CUid Source #quotRem :: CUid -> CUid -> (CUid, CUid) Source #divMod :: CUid -> CUid -> (CUid, CUid) Source # Source # Instance detailsDefined in System.Posix.Types Methodsquot :: Fd -> Fd -> Fd Source #rem :: Fd -> Fd -> Fd Source #div :: Fd -> Fd -> Fd Source #mod :: Fd -> Fd -> Fd Source #quotRem :: Fd -> Fd -> (Fd, Fd) Source #divMod :: Fd -> Fd -> (Fd, Fd) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Word MethodsquotRem :: Word8 -> Word8 -> (Word8, Word8) Source #divMod :: Word8 -> Word8 -> (Word8, Word8) Source # Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods Source # Since: base-4.8.0.0 Instance detailsDefined in GHC.Real Methods Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methodsquot :: Int -> Int -> Int Source #rem :: Int -> Int -> Int Source #div :: Int -> Int -> Int Source #mod :: Int -> Int -> Int Source #quotRem :: Int -> Int -> (Int, Int) Source #divMod :: Int -> Int -> (Int, Int) Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Real Methodsquot :: Word -> Word -> Word Source #rem :: Word -> Word -> Word Source #div :: Word -> Word -> Word Source #mod :: Word -> Word -> Word Source #quotRem :: Word -> Word -> (Word, Word) Source #divMod :: Word -> Word -> (Word, Word) Source # Integral a => Integral (Identity a) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Identity Methodsquot :: Identity a -> Identity a -> Identity a Source #rem :: Identity a -> Identity a -> Identity a Source #div :: Identity a -> Identity a -> Identity a Source #mod :: Identity a -> Identity a -> Identity a Source #quotRem :: Identity a -> Identity a -> (Identity a, Identity a) Source #divMod :: Identity a -> Identity a -> (Identity a, Identity a) Source # Integral a => Integral (Const a b) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Const Methodsquot :: Const a b -> Const a b -> Const a b Source #rem :: Const a b -> Const a b -> Const a b Source #div :: Const a b -> Const a b -> Const a b Source #mod :: Const a b -> Const a b -> Const a b Source #quotRem :: Const a b -> Const a b -> (Const a b, Const a b) Source #divMod :: Const a b -> Const a b -> (Const a b, Const a b) Source #toInteger :: Const a b -> Integer Source #

class Num a => Fractional a where Source #

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 inverse
x * recip x = recip x * x = fromInteger 1

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

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

Fractional division.

recip :: a -> a Source #

Reciprocal fraction.

Conversion from a Rational (that is Ratio Integer). A floating literal stands for an application of fromRational to a value of type Rational, so such literals have type (Fractional a) => a.

#### Instances

Instances details
 Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Note that due to the presence of NaN, not all elements of Double have an multiplicative inverse.>>> 0/0 * (recip 0/0 :: Double) NaN Since: base-2.1 Instance detailsDefined in GHC.Float Methods Source # Note that due to the presence of NaN, not all elements of Float have an multiplicative inverse.>>> 0/0 * (recip 0/0 :: Float) NaN Since: base-2.1 Instance detailsDefined in GHC.Float Methods RealFloat a => Fractional (Complex a) Source # Since: base-2.1 Instance detailsDefined in Data.Complex Methods(/) :: Complex a -> Complex a -> Complex a Source #recip :: Complex a -> Complex a Source # Fractional a => Fractional (Identity a) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Identity Methods(/) :: Identity a -> Identity a -> Identity a Source #recip :: Identity a -> Identity a Source # Fractional a => Fractional (Down a) Source # Since: base-4.14.0.0 Instance detailsDefined in Data.Ord Methods(/) :: Down a -> Down a -> Down a Source #recip :: Down a -> Down a Source # Integral a => Fractional (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real Methods(/) :: Ratio a -> Ratio a -> Ratio a Source #recip :: Ratio a -> Ratio a Source # HasResolution a => Fractional (Fixed a) Source # Since: base-2.1 Instance detailsDefined in Data.Fixed Methods(/) :: Fixed a -> Fixed a -> Fixed a Source #recip :: Fixed a -> Fixed a Source # Fractional a => Fractional (Op a b) Source # Instance detailsDefined in Data.Functor.Contravariant Methods(/) :: Op a b -> Op a b -> Op a b Source #recip :: Op a b -> Op a b Source # Fractional a => Fractional (Const a b) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Const Methods(/) :: Const a b -> Const a b -> Const a b Source #recip :: Const a b -> Const a b Source #

class (Real a, Fractional a) => RealFrac a where Source #

Extracting components of fractions.

Minimal complete definition

properFraction

Methods

properFraction :: Integral b => a -> (b, a) Source #

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 as x; and
• f is a fraction with the same type and sign as x, and with absolute value less than 1.

The default definitions of the ceiling, floor, truncate and round functions are in terms of properFraction.

truncate :: Integral b => a -> b Source #

truncate x returns the integer nearest x between zero and x

round :: Integral b => a -> b Source #

round x returns the nearest integer to x; the even integer if x is equidistant between two integers

ceiling :: Integral b => a -> b Source #

ceiling x returns the least integer not less than x

floor :: Integral b => a -> b Source #

floor x returns the greatest integer not greater than x

#### Instances

Instances details
 Source # Instance detailsDefined in Foreign.C.Types MethodsproperFraction :: Integral b => CDouble -> (b, CDouble) Source #truncate :: Integral b => CDouble -> b Source #round :: Integral b => CDouble -> b Source #ceiling :: Integral b => CDouble -> b Source #floor :: Integral b => CDouble -> b Source # Source # Instance detailsDefined in Foreign.C.Types MethodsproperFraction :: Integral b => CFloat -> (b, CFloat) Source #truncate :: Integral b => CFloat -> b Source #round :: Integral b => CFloat -> b Source #ceiling :: Integral b => CFloat -> b Source #floor :: Integral b => CFloat -> b Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Float MethodsproperFraction :: Integral b => Double -> (b, Double) Source #truncate :: Integral b => Double -> b Source #round :: Integral b => Double -> b Source #ceiling :: Integral b => Double -> b Source #floor :: Integral b => Double -> b Source # Source # Since: base-2.1 Instance detailsDefined in GHC.Float MethodsproperFraction :: Integral b => Float -> (b, Float) Source #truncate :: Integral b => Float -> b Source #round :: Integral b => Float -> b Source #ceiling :: Integral b => Float -> b Source #floor :: Integral b => Float -> b Source # RealFrac a => RealFrac (Identity a) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Identity MethodsproperFraction :: Integral b => Identity a -> (b, Identity a) Source #truncate :: Integral b => Identity a -> b Source #round :: Integral b => Identity a -> b Source #ceiling :: Integral b => Identity a -> b Source #floor :: Integral b => Identity a -> b Source # RealFrac a => RealFrac (Down a) Source # Since: base-4.14.0.0 Instance detailsDefined in Data.Ord MethodsproperFraction :: Integral b => Down a -> (b, Down a) Source #truncate :: Integral b => Down a -> b Source #round :: Integral b => Down a -> b Source #ceiling :: Integral b => Down a -> b Source #floor :: Integral b => Down a -> b Source # Integral a => RealFrac (Ratio a) Source # Since: base-2.0.1 Instance detailsDefined in GHC.Real MethodsproperFraction :: Integral b => Ratio a -> (b, Ratio a) Source #truncate :: Integral b => Ratio a -> b Source #round :: Integral b => Ratio a -> b Source #ceiling :: Integral b => Ratio a -> b Source #floor :: Integral b => Ratio a -> b Source # HasResolution a => RealFrac (Fixed a) Source # Since: base-2.1 Instance detailsDefined in Data.Fixed MethodsproperFraction :: Integral b => Fixed a -> (b, Fixed a) Source #truncate :: Integral b => Fixed a -> b Source #round :: Integral b => Fixed a -> b Source #ceiling :: Integral b => Fixed a -> b Source #floor :: Integral b => Fixed a -> b Source # RealFrac a => RealFrac (Const a b) Source # Since: base-4.9.0.0 Instance detailsDefined in Data.Functor.Const MethodsproperFraction :: Integral b0 => Const a b -> (b0, Const a b) Source #truncate :: Integral b0 => Const a b -> b0 Source #round :: Integral b0 => Const a b -> b0 Source #ceiling :: Integral b0 => Const a b -> b0 Source #floor :: Integral b0 => Const a b -> b0 Source #

numericEnumFromThen :: Fractional a => a -> a -> [a] Source #

numericEnumFromTo :: (Ord a, Fractional a) => a -> a -> [a] Source #

numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a] Source #

fromIntegral :: (Integral a, Num b) => a -> b Source #

general coercion from integral types

Convert an Int into a Natural, throwing an underflow exception for negative values.

realToFrac :: (Real a, Fractional b) => a -> b Source #

general coercion to fractional types

Arguments

 :: Real a => (a -> ShowS) a function that can show unsigned values -> Int the precedence of the enclosing context -> a the value to show -> ShowS

Converts a possibly-negative Real value to a string.

even :: Integral a => a -> Bool Source #

odd :: Integral a => a -> Bool Source #

(^) :: (Num a, Integral b) => a -> b -> a infixr 8 Source #

raise a number to a non-negative integral power

(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 Source #

raise a number to an integral power

gcd :: Integral a => a -> a -> a Source #

gcd x y is the non-negative factor of both x 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 4 = 4. gcd 0 0 = 0. (That is, the common divisor that is "greatest" in the divisibility preordering.)

Note: Since for signed fixed-width integer types, abs minBound < 0, the result may be negative if one of the arguments is minBound (and necessarily is if the other is 0 or minBound) for such types.

lcm :: Integral a => a -> a -> a Source #

lcm x y is the smallest positive integer that both x and y divide.

integralEnumFrom :: (Integral a, Bounded a) => a -> [a] Source #

integralEnumFromThen :: (Integral a, Bounded a) => a -> a -> [a] Source #

integralEnumFromTo :: Integral a => a -> a -> [a] Source #

integralEnumFromThenTo :: Integral a => a -> a -> a -> [a] Source #