floating-bits-0.3.0.0: Conversions between floating and integral values.

Copyright (C) 2015 Anselm Jonas Scholl BSD3 Anselm Jonas Scholl experimental GHC-specific None Haskell2010

Data.Bits.Floating

Description

Conversions between floating point values and integral values preserving the bit-patterns.

Synopsis

# Bitwise operations

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

Methods

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

nextUp :: f -> f Source

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.

nextDown :: f -> f Source

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 smaller than 0.0 is returned.

ulp :: f -> f Source

Return the size of an ulp of the argument. If the argument is NaN, NaN is returned. If the argument is +INF or -INF, +INF is returned. If the argument is 0.0, the minimum value greater than 0.0 is returned.

If `x` is not NaN, `ulp x == ulp (-x)` holds.

# Printing

class ShowFloat f where Source

Minimal complete definition

Methods

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.

# Utility functions

Cast a `CFloat` to a `Float`.

Cast a `CDouble` to a `Double`.