base-4.13.0.0: Basic libraries

GHC.Float

Description

The types Float and Double, the classes Floating and RealFloat and casting between Word32 and Float and Word64 and Double.

Synopsis

# Documentation

class Fractional a => Floating a where Source #

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

Methods

pi :: a Source #

exp :: a -> a Source #

log :: a -> a Source #

sqrt :: a -> a Source #

(**) :: a -> a -> a infixr 8 Source #

logBase :: a -> a -> a Source #

sin :: a -> a Source #

cos :: a -> a Source #

tan :: a -> a Source #

asin :: a -> a Source #

acos :: a -> a Source #

atan :: a -> a Source #

sinh :: a -> a Source #

cosh :: a -> a Source #

tanh :: a -> a Source #

asinh :: a -> a Source #

acosh :: a -> a Source #

atanh :: a -> a Source #

log1p :: a -> a Source #

log1p x computes log (1 + x), but provides more precise results for small (absolute) values of x if possible.

Since: 4.9.0.0

expm1 :: a -> a Source #

expm1 x computes exp x - 1, but provides more precise results for small (absolute) values of x if possible.

Since: 4.9.0.0

log1pexp :: a -> a Source #

log1pexp x computes log (1 + exp x), but provides more precise results if possible.

Examples:

• if x is a large negative number, log (1 + exp x) will be imprecise for the reasons given in log1p.
• if exp x is close to -1, log (1 + exp x) will be imprecise for the reasons given in expm1.

Since: 4.9.0.0

log1mexp :: a -> a Source #

log1mexp x computes log (1 - exp x), but provides more precise results if possible.

Examples:

• if x is a large negative number, log (1 - exp x) will be imprecise for the reasons given in log1p.
• if exp x is close to 1, log (1 - exp x) will be imprecise for the reasons given in expm1.

Since: 4.9.0.0

#### Instances

Instances details
 Source # Since: 2.1 Instance detailsDefined in GHC.Float Methods Source # Since: 2.1 Instance detailsDefined in GHC.Float Methods Source # Instance detailsDefined in Foreign.C.Types Methods Source # Instance detailsDefined in Foreign.C.Types Methods Floating a => Floating (Identity a) Source # Since: 4.9.0.0 Instance detailsDefined in Data.Functor.Identity Methodsexp :: Identity a -> Identity a Source #log :: Identity a -> Identity a Source #sqrt :: Identity a -> Identity a Source #(**) :: Identity a -> Identity a -> Identity a Source #logBase :: Identity a -> Identity a -> Identity a Source #sin :: Identity a -> Identity a Source #cos :: Identity a -> Identity a Source #tan :: Identity a -> Identity a Source #asin :: Identity a -> Identity a Source #acos :: Identity a -> Identity a Source #atan :: Identity a -> Identity a Source #sinh :: Identity a -> Identity a Source #cosh :: Identity a -> Identity a Source #tanh :: Identity a -> Identity a Source #asinh :: Identity a -> Identity a Source #acosh :: Identity a -> Identity a Source #atanh :: Identity a -> Identity a Source #log1p :: Identity a -> Identity a Source #expm1 :: Identity a -> Identity a Source # RealFloat a => Floating (Complex a) Source # Since: 2.1 Instance detailsDefined in Data.Complex Methodsexp :: Complex a -> Complex a Source #log :: Complex a -> Complex a Source #sqrt :: Complex a -> Complex a Source #(**) :: Complex a -> Complex a -> Complex a Source #logBase :: Complex a -> Complex a -> Complex a Source #sin :: Complex a -> Complex a Source #cos :: Complex a -> Complex a Source #tan :: Complex a -> Complex a Source #asin :: Complex a -> Complex a Source #acos :: Complex a -> Complex a Source #atan :: Complex a -> Complex a Source #sinh :: Complex a -> Complex a Source #cosh :: Complex a -> Complex a Source #tanh :: Complex a -> Complex a Source #asinh :: Complex a -> Complex a Source #acosh :: Complex a -> Complex a Source #atanh :: Complex a -> Complex a Source #log1p :: Complex a -> Complex a Source #expm1 :: Complex a -> Complex a Source # Floating a => Floating (Op a b) Source # Instance detailsDefined in Data.Functor.Contravariant Methodspi :: Op a b Source #exp :: Op a b -> Op a b Source #log :: Op a b -> Op a b Source #sqrt :: Op a b -> Op a b Source #(**) :: Op a b -> Op a b -> Op a b Source #logBase :: Op a b -> Op a b -> Op a b Source #sin :: Op a b -> Op a b Source #cos :: Op a b -> Op a b Source #tan :: Op a b -> Op a b Source #asin :: Op a b -> Op a b Source #acos :: Op a b -> Op a b Source #atan :: Op a b -> Op a b Source #sinh :: Op a b -> Op a b Source #cosh :: Op a b -> Op a b Source #tanh :: Op a b -> Op a b Source #asinh :: Op a b -> Op a b Source #acosh :: Op a b -> Op a b Source #atanh :: Op a b -> Op a b Source #log1p :: Op a b -> Op a b Source #expm1 :: Op a b -> Op a b Source #log1pexp :: Op a b -> Op a b Source #log1mexp :: Op a b -> Op a b Source # Floating a => Floating (Const a b) Source # Since: 4.9.0.0 Instance detailsDefined in Data.Functor.Const Methodspi :: Const a b Source #exp :: Const a b -> Const a b Source #log :: Const a b -> Const a b Source #sqrt :: Const a b -> Const a b Source #(**) :: Const a b -> Const a b -> Const a b Source #logBase :: Const a b -> Const a b -> Const a b Source #sin :: Const a b -> Const a b Source #cos :: Const a b -> Const a b Source #tan :: Const a b -> Const a b Source #asin :: Const a b -> Const a b Source #acos :: Const a b -> Const a b Source #atan :: Const a b -> Const a b Source #sinh :: Const a b -> Const a b Source #cosh :: Const a b -> Const a b Source #tanh :: Const a b -> Const a b Source #asinh :: Const a b -> Const a b Source #acosh :: Const a b -> Const a b Source #atanh :: Const a b -> Const a b Source #log1p :: Const a b -> Const a b Source #expm1 :: Const a b -> Const a b Source #log1pexp :: Const a b -> Const a b Source #log1mexp :: Const a b -> Const a b Source #

class (RealFrac a, Floating a) => RealFloat a where Source #

Minimal complete definition

Methods

floatRadix :: a -> Integer Source #

a constant function, returning the radix of the representation (often 2)

floatDigits :: a -> Int Source #

a constant function, returning the number of digits of floatRadix in the significand

floatRange :: a -> (Int, Int) Source #

a constant function, returning the lowest and highest values the exponent may assume

decodeFloat :: a -> (Integer, Int) Source #

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 decodeFloat x yields (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) <= abs m < b^d, where d is the value of floatDigits x. In particular, decodeFloat 0 = (0,0). If the type contains a negative zero, also decodeFloat (-0.0) = (0,0). The result of decodeFloat x is unspecified if either of isNaN x or isInfinite x is True.

encodeFloat :: Integer -> Int -> a Source #

encodeFloat performs the inverse of decodeFloat in the sense that for finite x with the exception of -0.0, uncurry encodeFloat (decodeFloat x) = x. encodeFloat m n is one of the two closest representable floating-point numbers to m*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.

exponent :: a -> Int Source #

exponent corresponds to the second component of decodeFloat. exponent 0 = 0 and for finite nonzero x, exponent x = snd (decodeFloat x) + floatDigits x. If x is a finite floating-point number, it is equal in value to significand x * b ^^ exponent x, where b is the floating-point radix. The behaviour is unspecified on infinite or NaN values.

significand :: a -> a Source #

The first component of decodeFloat, scaled to lie in the open interval (-1,1), either 0.0 or of absolute value >= 1/b, where b is the floating-point radix. The behaviour is unspecified on infinite or NaN values.

scaleFloat :: Int -> a -> a Source #

multiplies a floating-point number by an integer power of the radix

isNaN :: a -> Bool Source #

True if the argument is an IEEE "not-a-number" (NaN) value

isInfinite :: a -> Bool Source #

True if the argument is an IEEE infinity or negative infinity

isDenormalized :: a -> Bool Source #

True if the argument is too small to be represented in normalized format

isNegativeZero :: a -> Bool Source #

True if the argument is an IEEE negative zero

isIEEE :: a -> Bool Source #

True if the argument is an IEEE floating point number

atan2 :: a -> a -> a Source #

a version of arctangent taking two real floating-point arguments. For real floating x and y, atan2 y x computes the angle (from the positive x-axis) of the vector from the origin to the point (x,y). atan2 y x returns a value in the range [-pi, pi]. It follows the Common Lisp semantics for the origin when signed zeroes are supported. atan2 y 1, with y in a type that is RealFloat, should return the same value as atan y. A default definition of atan2 is provided, but implementors can provide a more accurate implementation.

#### Instances

Instances details
 Source # Since: 2.1 Instance detailsDefined in GHC.Float MethodsfloatRange :: Double -> (Int, Int) Source # Source # Since: 2.1 Instance detailsDefined in GHC.Float MethodsfloatRange :: Float -> (Int, Int) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsfloatRange :: CDouble -> (Int, Int) Source # Source # Instance detailsDefined in Foreign.C.Types MethodsfloatRange :: CFloat -> (Int, Int) Source # RealFloat a => RealFloat (Identity a) Source # Since: 4.9.0.0 Instance detailsDefined in Data.Functor.Identity MethodsfloatRange :: Identity a -> (Int, Int) Source #decodeFloat :: Identity a -> (Integer, Int) Source #scaleFloat :: Int -> Identity a -> Identity a Source #isNaN :: Identity a -> Bool Source #atan2 :: Identity a -> Identity a -> Identity a Source # RealFloat a => RealFloat (Const a b) Source # Since: 4.9.0.0 Instance detailsDefined in Data.Functor.Const MethodsfloatRadix :: Const a b -> Integer Source #floatDigits :: Const a b -> Int Source #floatRange :: Const a b -> (Int, Int) Source #decodeFloat :: Const a b -> (Integer, Int) Source #encodeFloat :: Integer -> Int -> Const a b Source #exponent :: Const a b -> Int Source #significand :: Const a b -> Const a b Source #scaleFloat :: Int -> Const a b -> Const a b Source #isNaN :: Const a b -> Bool Source #isInfinite :: Const a b -> Bool Source #isDenormalized :: Const a b -> Bool Source #isNegativeZero :: Const a b -> Bool Source #isIEEE :: Const a b -> Bool Source #atan2 :: Const a b -> Const a b -> Const a b Source #

data FFFormat Source #

Constructors

 FFExponent FFFixed FFGeneric

showFloat :: RealFloat a => a -> ShowS Source #

Show a signed RealFloat value to full precision using standard decimal notation for arguments whose absolute value lies between 0.1 and 9,999,999, and scientific notation otherwise.

roundTo :: Int -> Int -> [Int] -> (Int, [Int]) Source #

floatToDigits :: RealFloat a => Integer -> a -> ([Int], Int) Source #

floatToDigits takes a base and a non-negative RealFloat number, and returns a list of digits and an exponent. In particular, if x>=0, and

floatToDigits base x = ([d1,d2,...,dn], e)

then

1. n >= 1
2. x = 0.d1d2...dn * (base**e)
3. 0 <= di <= base-1

fromRat :: RealFloat a => Rational -> a Source #

Converts a Rational value into any type in class RealFloat.

Arguments

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

clamp :: Int -> Int -> Int Source #

castWord32ToFloat w does a bit-for-bit copy from an integral value to a floating-point value.

Since: 4.10.0.0

castFloatToWord32 f does a bit-for-bit copy from a floating-point value to an integral value.

Since: 4.10.0.0

castWord64ToDouble w does a bit-for-bit copy from an integral value to a floating-point value.

Since: 4.10.0.0

castFloatToWord32 f does a bit-for-bit copy from a floating-point value to an integral value.

Since: 4.10.0.0

data Float #

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.

Constructors

 F# Float#

#### Instances

Instances details

# Monomorphic equality operators

 Source # Since: 2.1 Instance details MethodsenumFrom :: Double -> [Double] Source #enumFromTo :: Double -> Double -> [Double] Source # Source # Since: 2.1 Instance details MethodsenumFrom :: Float -> [Float] Source #enumFromThen :: Float -> Float -> [Float] Source #enumFromTo :: Float -> Float -> [Float] Source #enumFromThenTo :: Float -> Float -> Float -> [Float] Source # 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: 2.1 Instance details 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: 2.1 Instance details Methods Source # Note that due to the presence of NaN, not all elements of Double have an additive inverse.>>> 0/0 + (negate 0/0 :: Double) NaN Also note that due to the presence of -0, Double's Num instance doesn't have an additive identity>>> 0 + (-0 :: Double) 0.0 Since: 2.1 Instance details Methods Source # Note that due to the presence of NaN, not all elements of Float have an additive inverse.>>> 0/0 + (negate 0/0 :: Float) NaN Also note that due to the presence of -0, Float's Num instance doesn't have an additive identity>>> 0 + (-0 :: Float) 0.0 Since: 2.1 Instance details Methods Source # Since: 2.1 Instance details Methods Source # Since: 2.1 Instance details Methods Source # Since: 2.1 Instance details 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: 2.1 Instance details 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 # Source # Since: 2.1 Instance details MethodsshowList :: [Double] -> ShowS Source # Source # Since: 2.1 Instance details MethodsshowList :: [Float] -> ShowS Source #