text-format icon indicating copy to clipboard operation
text-format copied to clipboard

`build (minBound :: Int)` renders as "-0"

Open jberryman opened this issue 8 years ago • 1 comments

We're using text-format-0.3.1.1

Data.Text.Buildable Prelude> build (minBound :: Int)
"-0"

Integer is also affected which is a weirder/worse case:

Data.Text.Buildable Prelude> build (-9223372036854775807 :: Integer)
"-9223372036854775807"
Data.Text.Buildable Prelude> build (-9223372036854775808 :: Integer)
"-0"
Data.Text.Buildable Prelude> build (-9223372036854775809 :: Integer)
"-9223372036854775809"

The bug is here:

decimal i
    | i < 0     = minus <> go (-i)  --- < HERE
    | otherwise = go i
  where
    go n | n < 10    = digit n
         | otherwise = go (n `quot` 10) <> digit (n `rem` 10)

Since negate minBound is not representable. In fact I wrote this bug myself a couple weeks ago :) . Will submit a little PR shortly.

jberryman avatar Oct 31 '17 18:10 jberryman

Thanks, I've merged this into the formatting package, which now includes a copy of text-format: https://github.com/chrisdone/formatting/commit/80d210966c3518d3a6de7cfa1549e2ddad8751f9

chrisdone avatar Dec 20 '17 13:12 chrisdone