Skip to content

Commit c723b01

Browse files
committed
Add quot and rem
1 parent 9c9f235 commit c723b01

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Data/BigInt.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module Data.BigInt
2222
, and
2323
, shl
2424
, shr
25+
, quot
26+
, rem
2527
, toNumber
2628
) where
2729

@@ -187,3 +189,11 @@ instance euclideanRingBigInt :: EuclideanRing BigInt where
187189
where yy = abs y
188190

189191
degree = floor <<< toNumber <<< abs
192+
193+
-- | Truncating integer division
194+
quot :: BigInt -> BigInt -> BigInt
195+
quot = biDiv
196+
197+
-- | The remainder after truncating integer division
198+
rem :: BigInt -> BigInt -> BigInt
199+
rem = biMod

test/Main.purs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Prelude hiding (not)
44

55
import Data.Array (filter, range)
66
import Data.Array.NonEmpty as NEA
7-
import Data.BigInt (BigInt, abs, and, digitsInBase, even, fromBase, fromInt, fromNumber, fromString, not, odd, or, pow, prime, shl, shr, toBase, toBase', toNonEmptyString, toNumber, toString, xor)
7+
import Data.BigInt (BigInt, abs, and, digitsInBase, even, fromBase, fromInt, fromNumber, fromString, not, odd, or, pow, prime, shl, shr, toBase, toBase', toNonEmptyString, toNumber, toString, xor, quot, rem)
88
import Data.Foldable (fold)
99
import Data.Int as Int
1010
import Data.Maybe (Maybe(..), fromMaybe)
@@ -118,6 +118,8 @@ main = do
118118
testBinary (/) (/)
119119
testBinary mod mod
120120
testBinary div div
121+
testBinary quot Int.quot
122+
testBinary rem Int.rem
121123

122124
-- To test the multiplication, we need to make sure that Int does not overflow
123125
quickCheck (\x y -> fromSmallInt x * fromSmallInt y == fromInt (runSmallInt x * runSmallInt y))

0 commit comments

Comments
 (0)