definition:
|
showFloat :: ShowSpec Float
showFloat t mf mw mp x =
-- convert to better format
let flags = convertFlags mf
width = convertWidth mw
prec = convertPrecision mp
minusFlag = getMinusFlag flags
plusFlag = getPlusFlag flags
zeroFlag = getZeroFlag flags
spaceFlag = getSpaceFlag flags
hashFlag = getHashFlag flags
isPositive = (>=) x 0
-- Convert to Floater format for easier formatting
floa = floatToFloater x
-- apply type
afterType = case t of
'f' -> eliminateExponent floa
'e' -> onePrePoint floa
'E' -> onePrePoint floa
-- apply precision
afterPrec = roundFloater prec afterType
-- apply flags
afterPlusFlag = if (plusFlag && x >= 0)
then setMantissaBeforePoint afterPrec
('+':getMantissaBeforePoint afterPrec)
else afterPrec
afterHashFlag = if (not (isPrefixOf (getMantissaAfterPoint afterPlusFlag)
(repeat '0')) || hashFlag || prec > 0)
then setMantissaAfterPoint afterPlusFlag
('.':getMantissaAfterPoint afterPlusFlag)
else afterPlusFlag
afterSpaceFlag = if (spaceFlag && not plusFlag && isPositive)
then setMantissaBeforePoint afterHashFlag
(' ':getMantissaBeforePoint afterHashFlag)
else if (not isPositive)
then setMantissaBeforePoint afterHashFlag
('-':getMantissaBeforePoint afterHashFlag)
else afterHashFlag
-- convert back from floater data type
unitedFloater = case t of
'f' -> getMantissaBeforePoint afterSpaceFlag
++ getMantissaAfterPoint afterSpaceFlag
'e' -> getMantissaBeforePoint afterSpaceFlag
++ getMantissaAfterPoint afterSpaceFlag
++ "e" ++ showExponent afterSpaceFlag
'E' -> getMantissaBeforePoint afterSpaceFlag
++ getMantissaAfterPoint afterSpaceFlag
++ "E" ++ showExponent afterSpaceFlag
-- apply width
afterWidth = if minusFlag
then fillWithCharsLeftAlign width ' ' unitedFloater
else let filler = if zeroFlag
then '0' else ' '
in fillWithCharsRightAlign width filler
unitedFloater
-- result
in afterWidth
|
demand:
|
no demanded arguments
|
deterministic:
|
deterministic operation
|
documentation:
|
--- The function showFloat formats a Float
--- @param t - A char setting wether to use an exponent or not
--- @param mf - A string containing all flags
--- @param mw - The minimal number of characters to be printed before the point
--- @param mp - The exact amount of numbers to be printed after the point
--- @param x - The Float which should be formatted
--- @return A string containing the formatted float
|
indeterministic:
|
referentially transparent operation
|
infix:
|
no fixity defined
|
iotype:
|
{(_,_,_,_,_) |-> _}
|
name:
|
showFloat
|
precedence:
|
no precedence defined
|
result-values:
|
_
|
signature:
|
Prelude.Char -> Prelude.Maybe String -> Prelude.Maybe Prelude.Int
-> Prelude.Maybe Prelude.Int -> Prelude.Float -> String
|
solution-complete:
|
operation might suspend on free variables
|
terminating:
|
possibly non-terminating
|
totally-defined:
|
possibly non-reducible on same data term
|