-- | Apply CoinPortion to Coin (with rounding up).
--
-- Use it for calculating thresholds.
applyCoinPortionUp :: CoinPortion -> Coin -> Coin
applyCoinPortionUp (getCoinPortion -> p) (unsafeGetCoin -> c) =
    let (d, m) = divMod (toInteger p * toInteger c)
                        (toInteger coinPortionDenominator)
    in if m > 0 then Coin (fromInteger (d + 1))
                else Coin (fromInteger d)
applyCoinPortionUp :: CoinPortion -> Coin -> Coin
applyCoinPortionUp (getCoinPortion -> p) (unsafeGetCoin -> c) =
    let (d, m) = divMod (toInteger p * toInteger c)
                        (toInteger coinPortionDenominator)
    in if m > 0 then Coin (fromInteger (d + 1))
                else Coin (fromInteger d)
applyCoinPortionUp (getCoinPortion -> p) (unsafeGetCoin -> c) =
    let (d, m) = divMod (toInteger p * toInteger c)
                        (toInteger coinPortionDenominator)
    in if m > 0 then Coin (fromInteger (d + 1))
                else Coin (fromInteger d)