Skip to content

build (minBound :: Int) renders as "-0" #18

@jberryman

Description

@jberryman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions