Skip to content

Rounding always throws an arithmetic underflow exception when used with a ratio of natural numbers

I originally reported this in !1878 (closed).

Today I was surprised to find that round does not work at all for Ratio Natural values. For example:

>>> round (1 :: Ratio Natural) :: Natural
*** Exception: arithmetic underflow

As far as I can tell it's true regardless of the value of the Ratio Natural or the result type.

>>> round (1.5 :: Ratio Natural) :: Natural
*** Exception: arithmetic underflow
>>> round (1 :: Ratio Natural) :: Integer
*** Exception: arithmetic underflow

For comparison, rounding works fine for Rational, which is an alias for Ratio Integer.

>>> round (1 :: Rational) :: Integer
1
>>> round (1.5 :: Rational) :: Integer
2
>>> round (1 :: Rational) :: Natural
1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information