W3cubDocs

/Haskell 8

Numeric

Copyright (c) The University of Glasgow 2002
License BSD-style (see the file libraries/base/LICENSE)
Maintainer [email protected]
Stability provisional
Portability portable
Safe Haskell Trustworthy
Language Haskell2010

Description

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

Showing

showSigned Source

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 Source

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 Source

Show non-negative Integral numbers in base 10.

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

Show non-negative Integral numbers in base 16.

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

Show non-negative Integral numbers in base 8.

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

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 Source

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 Source

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 Source

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 Source

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

  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 Source

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

readInt Source

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 Source

Read an unsigned number in decimal notation.

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

Read an unsigned number in octal notation.

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

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

readFloat :: RealFrac a => ReadS a Source

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

lexDigits :: ReadS String Source

Reads a non-empty string of decimal digits.

Miscellaneous

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

Converts a Rational value into any type in class RealFloat.

class Fractional a => Floating a where Source

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 Source

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

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

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

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

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

asinh, acosh, 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

Floating Double

Since: 2.1

Floating Float

Since: 2.1

Floating CDouble
Floating CFloat
Floating a => Floating (Identity a)
RealFloat a => Floating (Complex a)

Since: 2.1

Floating a => Floating (Const k a b)

Methods

pi :: Const k a b Source

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.2.1/docs/html/libraries/base-4.10.0.0/Numeric.html