planet-mitchell-0.1.0: Planet Mitchell

Num.RealFloat

Contents

Synopsis

# RealFloat

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

Minimal complete definition

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

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 #

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 #

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 #

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

isNaN :: a -> Bool #

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

isIEEE :: a -> Bool #

True if the argument is an IEEE floating point number

atan2 :: a -> a -> a #

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
 Since: base-2.1 Instance detailsDefined in GHC.Float MethodsfloatRange :: Double -> (Int, Int) #decodeFloat :: Double -> (Integer, Int) #isNaN :: Double -> Bool #atan2 :: Double -> Double -> Double # Since: base-2.1 Instance detailsDefined in GHC.Float MethodsfloatRange :: Float -> (Int, Int) #decodeFloat :: Float -> (Integer, Int) #scaleFloat :: Int -> Float -> Float #isNaN :: Float -> Bool #isIEEE :: Float -> Bool #atan2 :: Float -> Float -> Float # Instance detailsDefined in Foreign.C.Types MethodsfloatRange :: CFloat -> (Int, Int) #decodeFloat :: CFloat -> (Integer, Int) #isNaN :: CFloat -> Bool #atan2 :: CFloat -> CFloat -> CFloat # Instance detailsDefined in Foreign.C.Types MethodsfloatRange :: CDouble -> (Int, Int) #decodeFloat :: CDouble -> (Integer, Int) # Instance detailsDefined in Numeric.Half MethodsfloatRange :: Half -> (Int, Int) #decodeFloat :: Half -> (Integer, Int) #exponent :: Half -> Int #scaleFloat :: Int -> Half -> Half #isNaN :: Half -> Bool #isIEEE :: Half -> Bool #atan2 :: Half -> Half -> Half # Instance detailsDefined in Data.Constraint Methods Instance detailsDefined in Data.Constraint Methodsins :: () :- RealFloat Float # RealFloat a => RealFloat (Identity a) Instance detailsDefined in Data.Functor.Identity MethodsfloatDigits :: Identity a -> Int #floatRange :: Identity a -> (Int, Int) #decodeFloat :: Identity a -> (Integer, Int) #exponent :: Identity a -> Int #significand :: Identity a -> Identity a #scaleFloat :: Int -> Identity a -> Identity a #isNaN :: Identity a -> Bool #isInfinite :: Identity a -> Bool #isIEEE :: Identity a -> Bool #atan2 :: Identity a -> Identity a -> Identity a # (RealFloat a) :=> (RealFloat (Identity a)) Instance detailsDefined in Data.Constraint Methods (RealFloat a) :=> (RealFloat (Const a b)) Instance detailsDefined in Data.Constraint Methodsins :: RealFloat a :- RealFloat (Const a b) # (RealFloat a) :=> (Num (Complex a)) Instance detailsDefined in Data.Constraint Methods (RealFloat a) :=> (Fractional (Complex a)) Instance detailsDefined in Data.Constraint Methods (RealFloat a) :=> (Floating (Complex a)) Instance detailsDefined in Data.Constraint Methods Class (RealFrac a, Floating a) (RealFloat a) Instance detailsDefined in Data.Constraint Methodscls :: RealFloat a :- (RealFrac a, Floating a) # RealFloat a => RealFloat (Const a b) Instance detailsDefined in Data.Functor.Const MethodsfloatRadix :: Const a b -> Integer #floatDigits :: Const a b -> Int #floatRange :: Const a b -> (Int, Int) #decodeFloat :: Const a b -> (Integer, Int) #encodeFloat :: Integer -> Int -> Const a b #exponent :: Const a b -> Int #significand :: Const a b -> Const a b #scaleFloat :: Int -> Const a b -> Const a b #isNaN :: Const a b -> Bool #isInfinite :: Const a b -> Bool #isDenormalized :: Const a b -> Bool #isNegativeZero :: Const a b -> Bool #isIEEE :: Const a b -> Bool #atan2 :: Const a b -> Const a b -> Const a b # RealFloat a => RealFloat (Tagged s a) Instance detailsDefined in Data.Tagged MethodsfloatRadix :: Tagged s a -> Integer #floatDigits :: Tagged s a -> Int #floatRange :: Tagged s a -> (Int, Int) #decodeFloat :: Tagged s a -> (Integer, Int) #encodeFloat :: Integer -> Int -> Tagged s a #exponent :: Tagged s a -> Int #significand :: Tagged s a -> Tagged s a #scaleFloat :: Int -> Tagged s a -> Tagged s a #isNaN :: Tagged s a -> Bool #isInfinite :: Tagged s a -> Bool #isDenormalized :: Tagged s a -> Bool #isNegativeZero :: Tagged s a -> Bool #isIEEE :: Tagged s a -> Bool #atan2 :: Tagged s a -> Tagged s a -> Tagged s a #

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

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

## Show

showEFloat :: RealFloat a => Maybe Int -> a -> ShowS #

Show a signed RealFloat value using scientific (exponential) notation (e.g. 2.45e2, 1.5e-3).

In the call showEFloat digs val, if digs is Nothing, the value is shown to full precision; if digs is Just d, then at most d digits after the decimal point are shown.

showFFloat :: RealFloat a => Maybe Int -> a -> ShowS #

Show a signed RealFloat value using standard decimal notation (e.g. 245000, 0.0015).

In the call showFFloat digs val, if digs is Nothing, the value is shown to full precision; if digs is Just d, then at most d digits after the decimal point are shown.

showGFloat :: RealFloat a => Maybe Int -> a -> ShowS #

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

In the call showGFloat digs val, if digs is Nothing, the value is shown to full precision; if digs is Just d, then at most d digits after the decimal point are shown.

showFFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS #

Show a signed RealFloat value using standard decimal notation (e.g. 245000, 0.0015).

This behaves as showFFloat, except that a decimal point is always guaranteed, even if not needed.

Since: base-4.7.0.0

showGFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS #

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

This behaves as showFFloat, except that a decimal point is always guaranteed, even if not needed.

Since: base-4.7.0.0

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

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.

showHFloat :: RealFloat a => a -> ShowS #

Show a floating-point value in the hexadecimal format, similar to the %a specifier in C's printf.

>>> showHFloat (212.21 :: Double) ""
"0x1.a86b851eb851fp7"
>>> showHFloat (-12.76 :: Float) ""
"-0x1.9851ecp3"
>>> showHFloat (-0 :: Double) ""
"-0x0p+0"