Documentation on PlutusTx.Ratio.denominator says that the "[denominator] will always be greater than, or equal to, 1, although the type does not describe this." However, using PlutusTx.Ratio.reduce, it is possible to build negative rational with negative integer on the denominator.
PlutusTx.Ratio.reduce can be deprecated entirely since PlutusTx.Ratio.unsafeRatio serves identical purpose while correctly taking care of negative integer on denominator input.
Summary
Documentation on
PlutusTx.Ratio.denominator
says that the "[denominator] will always be greater than, or equal to, 1, although the type does not describe this." However, usingPlutusTx.Ratio.reduce
, it is possible to build negative rational with negative integer on the denominator.Steps to reproduce the behavior
Actual Result
Expected Result
Describe the approach you would take to fix this
PlutusTx.Ratio.reduce
can be deprecated entirely sincePlutusTx.Ratio.unsafeRatio
serves identical purpose while correctly taking care of negative integer on denominator input.Also, adding invariant notes to
PlutusTx.Ratio.Rational
's haddock documentation would be helpful. As it is currently not included in haddock: https://github.com/IntersectMBO/plutus/blob/master/plutus-tx/src/PlutusTx/Ratio.hs#L69-L72System info