Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Show functions.
Synopsis
- num_diff_str_opt :: (Ord a, Num a, Show a) => (Bool, Int) -> a -> String
- num_diff_str :: (Num a, Ord a, Show a) => a -> String
- rational_pp :: (Show a, Integral a) => Ratio a -> String
- ratio_pp_opt :: Bool -> Rational -> String
- ratio_pp :: Rational -> String
- show_rational_decimal :: Int -> Rational -> String
- real_pp :: Real t => Int -> t -> String
- real_pp_unicode :: Real t => Int -> t -> [Char]
- real_pp_trunc :: Real t => Int -> t -> String
- realfloat_pp :: RealFloat a => Int -> a -> String
- float_pp :: Int -> Float -> String
- double_pp :: Int -> Double -> String
- show_bin :: (Integral i, Show i) => Maybe Int -> i -> String
DIFF
num_diff_str_opt :: (Ord a, Num a, Show a) => (Bool, Int) -> a -> String Source #
Show positive and negative values always with sign, maybe show zero, maybe right justify.
map (num_diff_str_opt (True,2)) [-2,-1,0,1,2] == ["-2","-1"," 0","+1","+2"]
num_diff_str :: (Num a, Ord a, Show a) => a -> String Source #
Show only positive and negative values, always with sign.
map num_diff_str [-2,-1,0,1,2] == ["-2","-1","","+1","+2"] map show [-2,-1,0,1,2] == ["-2","-1","0","1","2"]
RATIONAL
rational_pp :: (Show a, Integral a) => Ratio a -> String Source #
Pretty printer for Rational
using /
and eliding denominators of 1
.
map rational_pp [1,3/2,5/4,2] == ["1","3/2","5/4","2"]
ratio_pp_opt :: Bool -> Rational -> String Source #
Pretty print ratio as :
separated integers, if nil is True elide unit denominator.
map (ratio_pp_opt True) [1,3/2,2] == ["1","3:2","2"]
ratio_pp :: Rational -> String Source #
Pretty print ratio as :
separated integers.
map ratio_pp [1,3/2,2] == ["1:1","3:2","2:1"]
show_rational_decimal :: Int -> Rational -> String Source #
Show rational to n decimal places.
let r = approxRational pi 1e-100 r == 884279719003555 / 281474976710656 show_rational_decimal 12 r == "3.141592653590" show_rational_decimal 3 (-100) == "-100.000"
REAL
real_pp :: Real t => Int -> t -> String Source #
Show r as float to k places.
real_pp 4 (1/3 :: Rational) == "0.3333" map (real_pp 4) [1,1.1,1.12,1.123,1.1234,1/0,sqrt (-1)]
real_pp_unicode :: Real t => Int -> t -> [Char] Source #
Variant that writes ∞
for Infinity.
putStrLn $ unwords $ map (real_pp_unicode 4) [1/0,-1/0]
real_pp_trunc :: Real t => Int -> t -> String Source #
Prints n as integral or to at most k decimal places. Does not print -0.
real_pp_trunc 4 (1/3 :: Rational) == "0.3333" map (real_pp_trunc 4) [1,1.1,1.12,1.123,1.1234] == ["1","1.1","1.12","1.123","1.1234"] map (real_pp_trunc 4) [1.00009,1.00001] == ["1.0001","1"] map (real_pp_trunc 2) [59.999,60.001,-0.00,-0.001]
realfloat_pp :: RealFloat a => Int -> a -> String Source #
Variant of showFFloat
. The Show
instance for floats resorts
to exponential notation very readily.
[show 0.01,realfloat_pp 2 0.01] == ["1.0e-2","0.01"] map (realfloat_pp 4) [1,1.1,1.12,1.123,1.1234,1/0,sqrt (-1)]