HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerebase-1.21.2Haskell2010

Rebase.Numeric

  • 1 class
  • 23 values
  • Packagerebase-1.21.2
  • Exports24
  • LanguageHaskell2010
  • LicenceMIT
  • SourceFloat.hs
classclass Fractional a => Floating a where
#

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

Methods

  • pi :: a
  • exp :: a -> a
  • log :: a -> a
  • sqrt :: a -> a
  • (**) :: a -> a -> ainfixr 8
  • logBase :: a -> a -> a
  • sin :: a -> a
  • cos :: a -> a
  • tan :: a -> a
  • asin :: a -> a
  • acos :: a -> a
  • atan :: a -> a
  • sinh :: a -> a
  • cosh :: a -> a
  • tanh :: a -> a
  • asinh :: a -> a
  • acosh :: a -> a
  • 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.

  • expm1 :: a -> a

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

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

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

Instances11Floating, …
valuefloatToDigits :: 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
valueshowFloat :: 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.

valuereadInt
  1. :: Num a
  2. => a

    the base

  3. -> (Char -> Bool)

    a predicate distinguishing valid digits in this base

  4. -> (Char -> Int)

    a function converting a valid digit character to an Int

  5. -> ReadS a
#

Reads an unsigned integral value in an arbitrary base.

valueshowSigned
  1. :: Real a
  2. => (a -> ShowS)

    a function that can show unsigned values

  3. -> Int

    the precedence of the enclosing context

  4. -> a

    the value to show

  5. -> ShowS
#

Converts a possibly-negative Real value to a string.

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

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

Read an unsigned number in binary notation.

Example1 expression
readBin "10011"[(19,"")]
valuereadDec :: (Eq a, Num a) => ReadS a
#

Read an unsigned number in decimal notation.

Example1 expression
readDec "0644"[(644,"")]
valuereadFloat :: RealFrac a => ReadS a
#

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

Note that this function takes time linear in the magnitude of its input which can scale exponentially with input size (e.g. "1e100000000" is a very large number while having a very small textual form). For this reason, users should take care to avoid using this function on untrusted input. Users needing to parse floating point values (e.g. Float) are encouraged to instead use read, which does not suffer from this issue.

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

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

Example1 expression
readHex "deadbeef"[(3735928559,"")]
valuereadOct :: (Eq a, Num a) => ReadS a
#

Read an unsigned number in octal notation.

Example1 expression
readOct "0644"[(420,"")]
valueshowEFloat :: 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.

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

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

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

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

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