On this page
GHC.Float
| Copyright | (c) The University of Glasgow 1994-2002 Portions obtained from hbc (c) Lennart Augusstson |
|---|---|
| License | see libraries/base/LICENSE |
| Maintainer | cvs-ghc@haskell.org |
| Stability | internal |
| Portability | non-portable (GHC Extensions) |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Description
The types Float and Double, the classes Floating and RealFloat and casting between Word32 and Float and Word64 and Double.
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 bexp (fromInteger 0)=fromInteger 1
Minimal complete definition
pi, exp, log, sin, cos, asin, acos, atan, sinh, cosh, asinh, acosh, atanh
Methods
(**) :: a -> a -> a infixr 8 Source
log1p x computes log (1 + x), but provides more precise results for small (absolute) values of x if possible.
Since: base-4.9.0.0
expm1 x computes exp x - 1, but provides more precise results for small (absolute) values of x if possible.
Since: base-4.9.0.0
log1pexp x computes log (1 + exp x), but provides more precise results if possible.
Examples:
- if
xis a large negative number,log (1 + exp x)will be imprecise for the reasons given inlog1p. - if
exp xis close to-1,log (1 + exp x)will be imprecise for the reasons given inexpm1.
Since: base-4.9.0.0
log1mexp x computes log (1 - exp x), but provides more precise results if possible.
Examples:
- if
xis a large negative number,log (1 - exp x)will be imprecise for the reasons given inlog1p. - if
exp xis close to1,log (1 - exp x)will be imprecise for the reasons given inexpm1.
Since: base-4.9.0.0
Instances
class (RealFrac a, Floating a) => RealFloat a where Source
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 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 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
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
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, 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
Constructors
clamp :: Int -> Int -> Int Source
Used to prevent exponent over/underflow when encoding floating point numbers. This is also the same as
\(x,y) -> max (-x) (min x y)
Example
>>> clamp (-10) 5
10
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.
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
n >= 1x = 0.d1d2...dn * (base**e)0 <= di <= base-1
fromRat :: RealFloat a => Rational -> a Source
Converts a Rational value into any type in class RealFloat.
formatRealFloat :: RealFloat a => FFFormat -> Maybe Int -> a -> String Source
log1mexpOrd :: (Ord a, Floating a) => a -> a Source
Default implementation for log1mexp requiring Ord to test against a threshold to decide which implementation variant to use.
plusFloat :: Float -> Float -> Float Source
minusFloat :: Float -> Float -> Float Source
negateFloat :: Float -> Float Source
timesFloat :: Float -> Float -> Float Source
fabsFloat :: Float -> Float Source
integerToFloat# :: Integer -> Float# Source
Convert an Integer to a Float#
integerToBinaryFloat' :: RealFloat a => Integer -> a Source
Converts a positive integer to a floating-point value.
The value nearest to the argument will be returned. If there are two such values, the one with an even significand will be returned (i.e. IEEE roundTiesToEven).
The argument must be strictly positive, and floatRadix (undefined :: a) must be 2.
naturalToFloat# :: Natural -> Float# Source
Convert a Natural to a Float#
divideFloat :: Float -> Float -> Float Source
rationalToFloat :: Integer -> Integer -> Float Source
fromRat'' :: RealFloat a => Int -> Int -> Integer -> Integer -> a Source
properFractionFloat :: Integral b => Float -> (b, Float) Source
truncateFloat :: Integral b => Float -> b Source
roundFloat :: Integral b => Float -> b Source
floorFloat :: Integral b => Float -> b Source
ceilingFloat :: Integral b => Float -> b Source
expFloat :: Float -> Float Source
logFloat :: Float -> Float Source
sqrtFloat :: Float -> Float Source
sinFloat :: Float -> Float Source
cosFloat :: Float -> Float Source
tanFloat :: Float -> Float Source
asinFloat :: Float -> Float Source
acosFloat :: Float -> Float Source
atanFloat :: Float -> Float Source
sinhFloat :: Float -> Float Source
coshFloat :: Float -> Float Source
tanhFloat :: Float -> Float Source
powerFloat :: Float -> Float -&