floatshow-0.2.4: Alternative faster String representations for Double and Float, String representations for more general numeric types.

Copyright(c) 2011 Daniel Fischer
LicenseBSD3
MaintainerDaniel Fischer
Stabilityexperimental
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell98

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 where #

A duplicate of the Show class.

Methods

fshow :: a -> String #

fshowsPrec :: Int -> a -> ShowS #

fshowList :: [a] -> ShowS #

fshows :: FShow a => a -> ShowS #

Same as shows, but using an FShow instance.

class RealFloat a => DispFloat a where #

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 -> Int #

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 -> Int #

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

fshowFloat :: DispFloat a => a -> ShowS #

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 -> ShowS #

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 -> ShowS #

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 -> ShowS #

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 #

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

Constructors

D7 Double 

Instances

Eq Double7 # 

Methods

(==) :: Double7 -> Double7 -> Bool #

(/=) :: Double7 -> Double7 -> Bool #

Floating Double7 # 
Fractional Double7 # 
Num Double7 # 
Ord Double7 # 
Real Double7 # 
RealFloat Double7 # 
RealFrac Double7 # 

Methods

properFraction :: Integral b => Double7 -> (b, Double7) #

truncate :: Integral b => Double7 -> b #

round :: Integral b => Double7 -> b #

ceiling :: Integral b => Double7 -> b #

floor :: Integral b => Double7 -> b #

Show Double7 # 
FShow Double7 # 
DispFloat Double7 # 

Methods

decDigits :: Double7 -> Int #

binExp :: Double7 -> Int #

newtype FullDouble #

newtype wrapper for Double. The Show (and FShow) instance displays all significant digits.

Constructors

FD 

Fields

Instances

Eq FullDouble # 
Floating FullDouble # 
Fractional FullDouble # 
Num FullDouble # 
Ord FullDouble # 
Read FullDouble # 
Real FullDouble # 
RealFloat FullDouble # 
RealFrac FullDouble # 
Show FullDouble # 
FShow FullDouble # 
DispFloat FullDouble # 

newtype Float7 #

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

Constructors

F7 Float 

Instances

Eq Float7 # 

Methods

(==) :: Float7 -> Float7 -> Bool #

(/=) :: Float7 -> Float7 -> Bool #

Floating Float7 # 
Fractional Float7 # 
Num Float7 # 
Ord Float7 # 
Real Float7 # 
RealFloat Float7 # 
RealFrac Float7 # 

Methods

properFraction :: Integral b => Float7 -> (b, Float7) #

truncate :: Integral b => Float7 -> b #

round :: Integral b => Float7 -> b #

ceiling :: Integral b => Float7 -> b #

floor :: Integral b => Float7 -> b #

Show Float7 # 
FShow Float7 # 
DispFloat Float7 # 

Methods

decDigits :: Float7 -> Int #

binExp :: Float7 -> Int #

newtype FullFloat #

newtype wrapper for Double. The Show (and FShow) instance displays all significant digits.

Constructors

FF 

Fields

Instances

Eq FullFloat # 
Floating FullFloat # 
Fractional FullFloat # 
Num FullFloat # 
Ord FullFloat # 
Read FullFloat # 
Real FullFloat # 
RealFloat FullFloat # 
RealFrac FullFloat # 
Show FullFloat # 
FShow FullFloat # 
DispFloat FullFloat #