fs-sim-0.3.0.0: test/Test/Util.hs
module Test.Util (
showPowersOf10
, showPowersOf
) where
import Data.List (find)
import Data.Maybe (fromJust)
import Text.Printf
showPowersOf10 :: Int -> String
showPowersOf10 = showPowersOf 10
showPowersOf :: Int -> Int -> String
showPowersOf factor n
| factor <= 1 = error "showPowersOf: factor must be larger than 1"
| n < 0 = "n < 0"
| n == 0 = "n == 0"
| otherwise = printf "%d <= n < %d" lb ub
where
ub = fromJust (find (n <) (iterate (* factor) factor))
lb = ub `div` factor