module Data.Sparse.PPrint where
import Data.Complex
import Text.Printf
import Numeric.Eps
class PrintDense a where
prd :: a -> IO ()
prd0 :: a -> IO ()
newline :: IO ()
newline = putStrLn ""
printfDouble :: (PrintfArg t, PrintfType t1) => PPrintOptions -> t -> t1
printfDouble opts x = printf pstr x where
pstr = concat ["%" , show ni, ".", show nd, "f"]
nd = pprintDecimals opts
ni = pprintDigits opts nd
data PPrintOptions =
PPrintOptions {
pprintDigits :: Int,
pprintDecimals :: Int } deriving (Eq, Show)
pprintDefaults = PPrintOptions 5 2
newtype C a = C {unC :: Complex a} deriving Eq
instance (Num a, Epsilon a, Ord a, Show a) => Show (C a) where
show (C (r :+ i)) = unwords [show r, oi] where
oi | isNz i = unwords [s, show i' ++ "j"]
| otherwise = []
s | signum i >= 0 = "+"
| otherwise = "-"
i' = abs i