base-4.10.1.0: Basic libraries

Copyright | (c) The University of Glasgow 2002
License | BSD-style (see the file libraries/base/LICENSE)
Maintainer | libraries@haskell.org
Stability | provisional
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell2010

Numeric

Contents

- Showing
- Reading
- Miscellaneous

Description

Odds and ends, mostly functions for reading and showing `RealFloat`-like kind of values.

Synopsis

- showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS
- showIntAtBase :: (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS
- showInt :: Integral a => a -> ShowS
- showHex :: (Integral a, Show a) => a -> ShowS
- showOct :: (Integral a, Show a) => a -> ShowS
- showEFloat :: RealFloat a => Maybe Int -> a -> ShowS
- showFFloat :: RealFloat a => Maybe Int -> a -> ShowS
- showGFloat :: RealFloat a => Maybe Int -> a -> ShowS
- showFFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS
- showGFloatAlt :: RealFloat a => Maybe Int -> a -> ShowS
- showFloat :: RealFloat a => a -> ShowS
- floatToDigits :: RealFloat a => Integer -> a -> ([Int], Int)
- readSigned :: Real a => ReadS a -> ReadS a
- readInt :: Num a => a -> (Char -> Bool) -> (Char -> Int) -> ReadS a
- readDec :: (Eq a, Num a) => ReadS a
- readOct :: (Eq a, Num a) => ReadS a
- readHex :: (Eq a, Num a) => ReadS a
- readFloat :: RealFrac a => ReadS a
- lexDigits :: ReadS String
- fromRat :: RealFloat a => Rational -> a
- class Fractional a => Floating a where

# Showing

showSigned #

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.

showIntAtBase :: (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS #

Shows a non-negative `Integral` number using the base specified by the first argument, and the character representation specified by the second.

showInt :: Integral a => a -> ShowS #

Show non-negative `Integral` numbers in base 10.

showHex :: (Integral a, Show a) => a -> ShowS #

Show non-negative `Integral` numbers in base 16.

showOct :: (Integral a, Show a) => a -> ShowS #

Show non-negative `Integral` numbers in base 8.

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: 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: 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.

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

# Reading

NB: `readInt` is the 'dual' of `showIntAtBase`, and `readDec` is the `dual' of `showInt`. The inconsistent naming is a historical accident.

readSigned :: Real a => ReadS a -> ReadS a #

Reads a signed `Real` value, given a reader for an unsigned value.

readInt #

Arguments

:: Num a |
=> a | the base
-> (Char -> Bool) | a predicate distinguishing valid digits in this base
-> (Char -> Int) | a function converting a valid digit character to an `Int`
-> ReadS a |

Reads an unsigned `Integral` value in an arbitrary base.

readDec :: (Eq a, Num a) => ReadS a #

Read an unsigned number in decimal notation.

readOct :: (Eq a, Num a) => ReadS a #

Read an unsigned number in octal notation.

readHex :: (Eq a, Num a) => ReadS a #

Read an unsigned number in hexadecimal notation. Both upper or lower case letters are allowed.

readFloat :: RealFrac a => ReadS a #

Reads an unsigned `RealFrac` value, expressed in decimal scientific notation.

lexDigits :: ReadS String #

Reads a non-empty string of decimal digits.

# Miscellaneous

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

Converts a `Rational` value into any type in class `RealFloat`.

class Fractional a => Floating a where #

Trigonometric and hyperbolic functions and related functions.

Minimal complete definition

pi, exp, log, sin, cos, asin, acos, atan, sinh, cosh, asinh, acosh, atanh

Methods

pi :: a #

exp, log, sqrt :: a -> a #

(**), logBase :: a -> a -> a infixr 8 #

sin, cos, tan :: a -> a #

asin, acos, atan :: a -> a #

sinh, cosh, tanh :: a -> a #

asinh, acosh, atanh :: a -> a #

log1p :: a -> a #

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

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

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

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

Floating Double # | Since: 2.1

Methods

pi :: Double #

exp :: Double -> Double #

log :: Double -> Double #

sqrt :: Double -> Double #

(**) :: Double -> Double -> Double #

logBase :: Double -> Double -> Double #

sin :: Double -> Double #

cos :: Double -> Double #

tan :: Double -> Double #

asin :: Double -> Double #

acos :: Double -> Double #

atan :: Double -> Double #

sinh :: Double -> Double #

cosh :: Double -> Double #

tanh :: Double -> Double #

asinh :: Double -> Double #

acosh :: Double -> Double #

atanh :: Double -> Double #

log1p :: Double -> Double #

expm1 :: Double -> Double #

log1pexp :: Double -> Double #

log1mexp :: Double -> Double #

Floating Float # | Since: 2.1

Methods

pi :: Float #

exp :: Float -> Float #

log :: Float -> Float #

sqrt :: Float -> Float #

(**) :: Float -> Float -> Float #

logBase :: Float -> Float -> Float #

sin :: Float -> Float #

cos :: Float -> Float #

tan :: Float -> Float #

asin :: Float -> Float #

acos :: Float -> Float #

atan :: Float -> Float #

sinh :: Float -> Float #

cosh :: Float -> Float #

tanh :: Float -> Float #

asinh :: Float -> Float #

acosh :: Float -> Float #

atanh :: Float -> Float #

log1p :: Float -> Float #

expm1 :: Float -> Float #

log1pexp :: Float -> Float #

log1mexp :: Float -> Float #

Floating CDouble # |

Methods

pi :: CDouble #

exp :: CDouble -> CDouble #

log :: CDouble -> CDouble #

sqrt :: CDouble -> CDouble #

(**) :: CDouble -> CDouble -> CDouble #

logBase :: CDouble -> CDouble -> CDouble #

sin :: CDouble -> CDouble #

cos :: CDouble -> CDouble #

tan :: CDouble -> CDouble #

asin :: CDouble -> CDouble #

acos :: CDouble -> CDouble #

atan :: CDouble -> CDouble #

sinh :: CDouble -> CDouble #

cosh :: CDouble -> CDouble #

tanh :: CDouble -> CDouble #

asinh :: CDouble -> CDouble #

acosh :: CDouble -> CDouble #

atanh :: CDouble -> CDouble #

log1p :: CDouble -> CDouble #

expm1 :: CDouble -> CDouble #

log1pexp :: CDouble -> CDouble #

log1mexp :: CDouble -> CDouble #

Floating CFloat # |

Methods

pi :: CFloat #

exp :: CFloat -> CFloat #

log :: CFloat -> CFloat #

sqrt :: CFloat -> CFloat #

(**) :: CFloat -> CFloat -> CFloat #

logBase :: CFloat -> CFloat -> CFloat #

sin :: CFloat -> CFloat #

cos :: CFloat -> CFloat #

tan :: CFloat -> CFloat #

asin :: CFloat -> CFloat #

acos :: CFloat -> CFloat #

atan :: CFloat -> CFloat #

sinh :: CFloat -> CFloat #

cosh :: CFloat -> CFloat #

tanh :: CFloat -> CFloat #

asinh :: CFloat -> CFloat #

acosh :: CFloat -> CFloat #

atanh :: CFloat -> CFloat #

log1p :: CFloat -> CFloat #

expm1 :: CFloat -> CFloat #

log1pexp :: CFloat -> CFloat #

log1mexp :: CFloat -> CFloat #

Floating a => Floating (Identity a) # |

Methods

pi :: Identity a #

exp :: Identity a -> Identity a #

log :: Identity a -> Identity a #

sqrt :: Identity a -> Identity a #

(**) :: Identity a -> Identity a -> Identity a #

logBase :: Identity a -> Identity a -> Identity a #

sin :: Identity a -> Identity a #

cos :: Identity a -> Identity a #

tan :: Identity a -> Identity a #

asin :: Identity a -> Identity a #

acos :: Identity a -> Identity a #

atan :: Identity a -> Identity a #

sinh :: Identity a -> Identity a #

cosh :: Identity a -> Identity a #

tanh :: Identity a -> Identity a #

asinh :: Identity a -> Identity a #

acosh :: Identity a -> Identity a #

atanh :: Identity a -> Identity a #

log1p :: Identity a -> Identity a #

expm1 :: Identity a -> Identity a #

log1pexp :: Identity a -> Identity a #

log1mexp :: Identity a -> Identity a #

RealFloat a => Floating (Complex a) # | Since: 2.1

Methods

pi :: Complex a #

exp :: Complex a -> Complex a #

log :: Complex a -> Complex a #

sqrt :: Complex a -> Complex a #

(**) :: Complex a -> Complex a -> Complex a #

logBase :: Complex a -> Complex a -> Complex a #

sin :: Complex a -> Complex a #

cos :: Complex a -> Complex a #

tan :: Complex a -> Complex a #

asin :: Complex a -> Complex a #

acos :: Complex a -> Complex a #

atan :: Complex a -> Complex a #

sinh :: Complex a -> Complex a #

cosh :: Complex a -> Complex a #

tanh :: Complex a -> Complex a #

asinh :: Complex a -> Complex a #

acosh :: Complex a -> Complex a #

atanh :: Complex a -> Complex a #

log1p :: Complex a -> Complex a #

expm1 :: Complex a -> Complex a #

log1pexp :: Complex a -> Complex a #

log1mexp :: Complex a -> Complex a #

Floating a => Floating (Const k a b) # |

Methods

pi :: Const k a b #

exp :: Const k a b -> Const k a b #

log :: Const k a b -> Const k a b #

sqrt :: Const k a b -> Const k a b #

(**) :: Const k a b -> Const k a b -> Const k a b #

logBase :: Const k a b -> Const k a b -> Const k a b #

sin :: Const k a b -> Const k a b #

cos :: Const k a b -> Const k a b #

tan :: Const k a b -> Const k a b #

asin :: Const k a b -> Const k a b #

acos :: Const k a b -> Const k a b #

atan :: Const k a b -> Const k a b #

sinh :: Const k a b -> Const k a b #

cosh :: Const k a b -> Const k a b #

tanh :: Const k a b -> Const k a b #

asinh :: Const k a b -> Const k a b #

acosh :: Const k a b -> Const k a b #

atanh :: Const k a b -> Const k a b #

log1p :: Const k a b -> Const k a b #

expm1 :: Const k a b -> Const k a b #

log1pexp :: Const k a b -> Const k a b #

log1mexp :: Const k a b -> Const k a b #