Skip to content

For Ratios, round produces incorrect results for some fixed-width signed integer values

Summary

The implementation of "round" for a ratio of fixed-width signed integers is incorrect when applied to extreme negative values.

Steps to reproduce

GHCi, version 9.8.1: https://www.haskell.org/ghc/  :? for help
ghci> round ((-128) Data.Ratio.% (-16 :: Integer))
8
ghci> round ((-128) Data.Ratio.% (-16 :: Data.Int.Int8))
-8

Expected behavior

GHCi, version 9.8.1: https://www.haskell.org/ghc/  :? for help
ghci> round ((-128) Data.Ratio.% (-16 :: Integer))
8
ghci> round ((-128) Data.Ratio.% (-16 :: Data.Int.Int8))
8

Environment

  • GHC version used: 9.8.1, 9.4.7
  • Operating System: Ubuntu 22.04.3 LTS
  • System Architecture: x86_64
Edited by j6carey
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information