fixed

Pure Haskell large fixed-width integers.
git clone git://git.ppad.tech/fixed.git
Log | Files | Refs | README | LICENSE

commit 541746e1e80c91859550010c45853879c7065a88
parent 0b57985c1ec0a60301d2fd4597a8b4d12dda31db
Author: Jared Tobin <jared@jtobin.io>
Date:   Thu, 23 Jan 2025 10:19:36 +0400

test: increase integer range for div test

.. which yields a failing test. As suspected, we weren't testing the
complex cases.

Diffstat:
Mtest/Main.hs | 14++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/test/Main.hs b/test/Main.hs @@ -52,6 +52,16 @@ instance Q.Arbitrary MulMonotonic where Q.arbitrary `Q.suchThat` (\(Q.NonNegative b) -> b * m <= a) pure (MulMonotonic (a, b, m)) +newtype DivMonotonic = DivMonotonic (Integer, Integer) + deriving Show + +instance Q.Arbitrary DivMonotonic where + arbitrary = do + a <- Q.chooseInteger (1, 2 ^ (256 :: Int) - 1) + b <- (Q.chooseInteger (1, 2 ^ (256 :: Int) - 1)) + `Q.suchThat` (\b -> b <= a) + pure (DivMonotonic (a, b)) + -- properties ----------------------------------------------------------------- lt_matches :: Different (Q.NonNegative Integer) -> Bool @@ -136,8 +146,8 @@ mul_512_matches (Q.NonNegative a) (Q.NonNegative b) = !rite = to_word512 (a * b) in left == rite -div_matches :: Monotonic (Q.Positive Integer) -> Bool -div_matches (Monotonic (Q.Positive b, Q.Positive a)) = +div_matches :: DivMonotonic -> Bool +div_matches (DivMonotonic (a, b)) = let !left = to_word256 a `div` to_word256 b !rite = to_word256 (a `Prelude.div` b) in left == rite