From c683c73c489243e869b39888a37be827599d6879 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 21 Jun 2015 18:00:34 +0200 Subject: Show instance for level now has fixed precision for dB --- src/Trivmix.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/Trivmix.hs') diff --git a/src/Trivmix.hs b/src/Trivmix.hs index 0f84f62..cedc3e3 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs @@ -48,9 +48,14 @@ data Options = Options data Level = Lin Float | DB Float +fixedPrecision :: (RealFrac a, Num a) => a -> a +fixedPrecision x = (fromInteger $ round $ p * x) / p + where + p = 1e3 + instance Show Level where show (Lin x) = show x - show (DB x) = (show x') ++ "dB" + show (DB x) = (show $ fixedPrecision x') ++ "dB" where x' = 20 * (logBase 10 x) -- cgit v1.2.3