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

Open Beginner friendly
#18 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
haskell
Domain
tooling

Research direction

Start with Data/Text/Format/Int.hs at decimal, then reproduce the minBound examples for Int and Integer from the issue. Check the formatting behavior at the minimum representable values and verify that the result is never "-0" while the neighboring negative values remain unchanged.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Haskell
Stars
34
Forks
25
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from haskell/text-format

All issues in haskell/text-format

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.