floatshow-0.1.1: Alternative faster String representations for Double and Float

Portabilitynon-portable (GHC extensions)
Stabilityexperimental
MaintainerDaniel Fischer

Text.FShow.RealFloat

Description

Faster String representations for floating point types. The code is largely taken from code in GHC.Float and the Show instance of Integer in GHC.Num to get the sequence of digits.

Synopsis

Documentation

class FShow a whereSource

A duplicate of the Show class.

fshows :: FShow a => a -> ShowSSource

Same as shows, but using an FShow instance.

class RealFloat a => DispFloat a whereSource

Class for specifying display parameters. The type a is supposed to be an IEEE-ish (real) floating-point type with floating-point radix 2, such that the mantissa returned by decodeFloat satisfies

   2^(binExp x) <= fst (decodeFloat x) < 2^(binExp x + 1)

for x > 0, so binExp x = floatDigits x - 1. The number of decimal digits that may be required is calculated with the formula

   decDigits x = 2 + floor (floatDigits x * logBase 10 2).

The default implementation uses an approximation of logBase 10 2 sufficient for mantissae of up to several thousand bits. Nevertheless, hardcoding the values in instance declarations may yield better performance.

Methods

decDigits :: a -> IntSource

The number of decimal digits that may be needed to uniquely determine a value of type a. For faster conversions which need not satisfy

   x == read (fshow x)

a smaller value can be given.

binExp :: a -> IntSource

The base 2 logarithm of the mantissa returned by decodeFloat x for x > 0.

fshowFloat :: DispFloat a => a -> ShowSSource

Show a signed DispFloat 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. Analogous to showFloat from GHC.Float.

fshowEFloat :: DispFloat a => Maybe Int -> a -> ShowSSource

Show a signed DispFloat value using scientific (exponential) notation (e.g. 2.45e2, 1.5e-3).

In the call fshowEFloat digs val, if digs is Nothing, the value is shown to full precision; if digs is Just d, then max 1 d digits after the decimal point are shown. Analogous to showEFloat from Numeric.

fshowFFloat :: DispFloat a => Maybe Int -> a -> ShowSSource

Show a signed DispFloat value using standard decimal notation (e.g. 245000, 0.0015).

In the call fshowFFloat digs val, if digs is Nothing, the value is shown to full precision; if digs is Just d, then max 0 d digits after the decimal point are shown. Analogous to showFFloat from Numeric.

fshowGFloat :: DispFloat a => Maybe Int -> a -> ShowSSource

Show a signed DispFloat 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 fshowGFloat digs val, if digs is Nothing, the value is shown to full precision; if digs is Just d, then max 1 d digits after the decimal point are shown. Analogous to showGFloat from Numeric.

newtype Double7 Source

newtype wrapper for Double. The Show (and FShow) instance displays numbers rounded to seven significant digits.

Constructors

D7 Double 

newtype Float7 Source

newtype wrapper for Float. The Show (and FShow) instance displays numbers rounded to seven significant digits.

Constructors

F7 Float