Copyright | (C) 2015 Anselm Jonas Scholl (C) 2023 Julia Longtin |
---|---|

License | BSD3 |

Maintainer | Julia Longtin <Julia.Longtin@gmail.com> |

Stability | experimental |

Portability | GHC-specific |

Safe Haskell | Safe-Inferred |

Language | Haskell2010 |

Functions for performing conversions between floating point values and Integral values, for retrieving the Unit of Least Precision of a floating point value, and for incrementing / decrementing a value by one ULP..

## Synopsis

- class (Floating f, Integral w) => FloatingBits f w | f -> w where
- coerceToWord :: f -> w
- coerceToFloat :: w -> f
- nextUp :: f -> f
- nextDown :: f -> f
- ulp :: f -> f

- class ShowFloat f where
- showsFloat :: f -> ShowS
- showFloat :: f -> String

- fromCFloat :: CFloat -> Float
- fromCDouble :: CDouble -> Double

# Bitwise operations

class (Floating f, Integral w) => FloatingBits f w | f -> w where Source #

coerceToWord :: f -> w Source #

Coerce a floating point number to an integral number preserving the bitwise representation.

coerceToFloat :: w -> f Source #

Coerce a integral number to an floating point number preserving the bitwise representation.

Note: It is not always possible to do this. In particular, if we coerce
the bit pattern of a NaN value, we might get a NaN value with a different
bit pattern than we wanted, so it is possible that

.`coerceToWord`

(`coerceToFloat`

w) /= w

Return the next floating point value in the direction of +INF. If the argument is NaN, NaN is returned. If the argument is +INF, +INF is returned. If the argument is 0.0, the minimum value greater than 0.0 is returned. If the argument is -INF, -INF is returned.

Return the next floating point value in the direction of -INF. If the argument is NaN, NaN is returned. If the argument is +INF, +INF is returned. If the argument is 0.0, the maximum value smaller than 0.0 is returned. If the argument is -INF, -INF is returned.

# Printing

class ShowFloat f where Source #

showsFloat :: f -> ShowS Source #

Like `showFloat`

, but prepends the value to another string.

showFloat :: f -> String Source #

Convert a float to a string, but show additional information if it is a NaN value.