Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

## Synopsis

- class (RealFrac a, Floating a) => RealFloat a where
- floatToDigits :: RealFloat a => Integer -> a -> ([Int], Int)
- 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
- showHFloat :: RealFloat a => a -> ShowS

# RealFloat

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

Efficient, machine-independent access to the components of a floating-point number.

floatRadix, floatDigits, floatRange, decodeFloat, encodeFloat, isNaN, isInfinite, isDenormalized, isNegativeZero, isIEEE

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

yields `decodeFloat`

x`(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) <= `

, where `abs`

m < b^d`d`

is
the value of

.
In particular, `floatDigits`

x

. If the type
contains a negative zero, also `decodeFloat`

0 = (0,0)

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

is one of the two closest representable
floating-point numbers to `encodeFloat`

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

.

and for finite nonzero `exponent`

0 = 0`x`

,

.
If `exponent`

x = snd (`decodeFloat`

x) + `floatDigits`

x`x`

is a finite floating-point number, it is equal in value to

, where `significand`

x * b ^^ `exponent`

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

`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

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

,

computes the angle
(from the positive x-axis) of the vector from the origin to the
point `atan2`

y x`(x,y)`

.

returns a value in the range [`atan2`

y x`-pi`

,
`pi`

]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported.

, with `atan2`

y 1`y`

in a type
that is `RealFloat`

, should return the same value as

.
A default definition of `atan`

y`atan2`

is provided, but implementors
can provide a more accurate implementation.

## Instances

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

n >= 1

x = 0.d1d2...dn * (base**e)

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

, if `showEFloat`

digs val`digs`

is `Nothing`

,
the value is shown to full precision; if `digs`

is

,
then at most `Just`

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

, if `showFFloat`

digs val`digs`

is `Nothing`

,
the value is shown to full precision; if `digs`

is

,
then at most `Just`

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

, if `showGFloat`

digs val`digs`

is `Nothing`

,
the value is shown to full precision; if `digs`

is

,
then at most `Just`

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

`>>>`

"0x1.a86b851eb851fp7"`showHFloat (212.21 :: Double) ""`

`>>>`

"-0x1.9851ecp3"`showHFloat (-12.76 :: Float) ""`

`>>>`

"-0x0p+0"`showHFloat (-0 :: Double) ""`