Fix formatting of negative numbers

This commit is contained in:
Joscha 2019-11-25 23:03:58 +00:00
parent f415595a40
commit d082bc939e

View file

@ -33,12 +33,12 @@ toDec = T.pack . show
toHex :: (Integral a, Show a) => a -> T.Text
toHex a = T.pack $ showHex a ""
-- | @'negative' a@ interprets @a@ as @a - 'maxBound'@ if @a@ is greater than
-- @'maxBound' `div` 2@, and as a positive number otherwise. 'minBound' is
-- | @'negative' a@ interprets @a@ as @a - 'maxBound' - 1@ if @a@ is greater
-- than @'maxBound' `div` 2@, and as a positive number otherwise. 'minBound' is
-- ignored.
negative :: (Integral a, Bounded a, Show a) => (a -> T.Text) -> a -> T.Text
negative f a
| a > maxBound `div` 2 = "-" <> f (-(a - maxBound))
| a > maxBound `div` 2 = "-" <> f (-(a - maxBound - 1))
| otherwise = f a
chunkedBy :: T.Text -> Int -> T.Text -> T.Text