floating-bits-0.3.1.0: Bitwise accurate floating point conversion, and Unit of Lease Precision calculation.
Copyright(C) 2015 Anselm Jonas Scholl (C) 2023 Julia Longtin
LicenseBSD3
MaintainerJulia Longtin <Julia.Longtin@gmail.com>
Stabilityexperimental
PortabilityGHC-specific
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Bits.Floating

Description

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

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. If the argument is -INF, -INF 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 maximum value smaller than 0.0 is returned. If the argument is -INF, -INF is returned.

ulp :: f -> f Source #

Return the size of the Unit of Least Precision 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 or one of the infinities, ulp x == ulp (-x) holds.

Printing

class ShowFloat f where Source #

Minimal complete definition

showsFloat | showFloat

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.

Instances

Instances details
ShowFloat CDouble Source # 
Instance details

Defined in Data.Bits.Floating

ShowFloat CFloat Source # 
Instance details

Defined in Data.Bits.Floating

ShowFloat Double Source # 
Instance details

Defined in Data.Bits.Floating

ShowFloat Float Source # 
Instance details

Defined in Data.Bits.Floating

Utility functions