Skip to content

Commit 6d929d7

Browse files
committed
Remove quot/rem & hide intDiv/intMod
`quot` and `rem` exist in `Data.Int`
1 parent 94ce7ef commit 6d929d7

File tree

4 files changed

+3
-81
lines changed

4 files changed

+3
-81
lines changed

src/Data/EuclideanRing.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,13 @@ exports.intDiv = function (x) {
1212
};
1313
};
1414

15-
exports.quot = function (x) {
16-
return function (y) {
17-
/* jshint bitwise: false */
18-
return x / y | 0;
19-
};
20-
};
21-
2215
exports.intMod = function (x) {
2316
return function (y) {
2417
var yy = Math.abs(y);
2518
return ((x % yy) + yy) % yy;
2619
};
2720
};
2821

29-
exports.rem = function (x) {
30-
return function (y) {
31-
return x % y;
32-
};
33-
};
34-
3522
exports.numDiv = function (n1) {
3623
return function (n2) {
3724
return n1 / n2;

src/Data/EuclideanRing.purs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,9 @@ module Data.EuclideanRing
22
( class EuclideanRing, degree, div, mod, (/)
33
, gcd
44
, lcm
5-
, quot
6-
, rem
75
, module Data.CommutativeRing
86
, module Data.Ring
97
, module Data.Semiring
10-
, intDiv
11-
, intMod
128
) where
139

1410
import Data.BooleanAlgebra ((||))
@@ -100,38 +96,3 @@ lcm a b =
10096
if a == zero || b == zero
10197
then zero
10298
else a * b / gcd a b
103-
104-
-- | The `quot` function provides _truncating_ integer division (see the
105-
-- | documentation for the `EuclideanRing` class). It is identical to `div` in
106-
-- | the `EuclideanRing Int` instance if the dividend is positive, but will be
107-
-- | slightly different if the dividend is negative. For example:
108-
-- |
109-
-- | ```purescript
110-
-- | div 2 3 == 0
111-
-- | quot 2 3 == 0
112-
-- |
113-
-- | div (-2) 3 == (-1)
114-
-- | quot (-2) 3 == 0
115-
-- |
116-
-- | div 2 (-3) == 0
117-
-- | quot 2 (-3) == 0
118-
-- | ```
119-
foreign import quot :: Int -> Int -> Int
120-
121-
-- | The `rem` function provides the remainder after _truncating_ integer
122-
-- | division (see the documentation for the `EuclideanRing` class). It is
123-
-- | identical to `mod` in the `EuclideanRing Int` instance if the dividend is
124-
-- | positive, but will be slightly different if the dividend is negative. For
125-
-- | example:
126-
-- |
127-
-- | ```purescript
128-
-- | mod 2 3 == 2
129-
-- | rem 2 3 == 2
130-
-- |
131-
-- | mod (-2) 3 == 1
132-
-- | rem (-2) 3 == (-2)
133-
-- |
134-
-- | mod 2 (-3) == 2
135-
-- | rem 2 (-3) == 2
136-
-- | ```
137-
foreign import rem :: Int -> Int -> Int

src/Prelude.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import Data.Bounded (class Bounded, bottom, top)
4141
import Data.CommutativeRing (class CommutativeRing)
4242
import Data.DivisionRing (class DivisionRing, recip)
4343
import Data.Eq (class Eq, eq, notEq, (/=), (==))
44-
import Data.EuclideanRing (class EuclideanRing, degree, div, mod, quot, rem, (/), gcd, lcm)
44+
import Data.EuclideanRing (class EuclideanRing, degree, div, mod, (/), gcd, lcm)
4545
import Data.Field (class Field)
4646
import Data.Function (const, flip, ($), (#))
4747
import Data.Functor (class Functor, flap, map, void, ($>), (<#>), (<$), (<$>), (<@>))

test/Test/Main.purs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Test.Main where
22

33
import Prelude
4-
import Data.EuclideanRing (intDiv, intMod)
54
import Data.Ord (abs)
65

76
type AlmostEff = Unit -> Unit
@@ -12,7 +11,6 @@ main = do
1211
testOrderings
1312
testOrdUtils
1413
testIntDivMod
15-
testIntQuotRem
1614
testIntDegree
1715

1816
foreign import testNumberShow :: (Number -> String) -> AlmostEff
@@ -103,39 +101,15 @@ testIntDivMod = do
103101
where
104102
go a b =
105103
let
106-
q = intDiv a b
107-
r = intMod a b
104+
q = a / b
105+
r = a `mod` b
108106
msg = show a <> " / " <> show b <> ": "
109107
in do
110108
assert (msg <> "Quotient/remainder law") $
111109
q * b + r == a
112110
assert (msg <> "Remainder should be between 0 and `abs b`, got: " <> show r) $
113111
0 <= r && r < abs b
114112

115-
testIntQuotRem :: AlmostEff
116-
testIntQuotRem = do
117-
-- Check when dividend goes into divisor exactly
118-
go 8 2
119-
go (-8) 2
120-
go 8 (-2)
121-
go (-8) (-2)
122-
123-
-- Check when dividend does not go into divisor exactly
124-
go 2 3
125-
go (-2) 3
126-
go 2 (-3)
127-
go (-2) (-3)
128-
129-
where
130-
go a b =
131-
let
132-
q = quot a b
133-
r = rem a b
134-
msg = show a <> " / " <> show b <> ": "
135-
in do
136-
assert (msg <> "Quotient/remainder law") $
137-
q * b + r == a
138-
139113
testIntDegree :: AlmostEff
140114
testIntDegree = do
141115
let bot = bottom :: Int

0 commit comments

Comments
 (0)