Skip to content

Commit 58d513c

Browse files
committed
Merge branch 'compiler/0.12' into records
2 parents c524f9e + 3c7f84a commit 58d513c

File tree

4 files changed

+7
-86
lines changed

4 files changed

+7
-86
lines changed

src/Data/EuclideanRing.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,19 @@ exports.intDegree = function (x) {
88
// https://en.m.wikipedia.org/wiki/Modulo_operation.
99
exports.intDiv = function (x) {
1010
return function (y) {
11+
if (y == 0) return 0;
1112
return y > 0 ? Math.floor(x / y) : -Math.floor(x / -y);
1213
};
1314
};
1415

15-
exports.quot = function (x) {
16-
return function (y) {
17-
/* jshint bitwise: false */
18-
return x / y | 0;
19-
};
20-
};
21-
2216
exports.intMod = function (x) {
2317
return function (y) {
18+
if (y == 0) return 0;
2419
var yy = Math.abs(y);
2520
return ((x % yy) + yy) % yy;
2621
};
2722
};
2823

29-
exports.rem = function (x) {
30-
return function (y) {
31-
return x % y;
32-
};
33-
};
34-
3524
exports.numDiv = function (n1) {
3625
return function (n2) {
3726
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: 4 additions & 33 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.HeytingAlgebra (ff, tt, implies)
65
import Data.Ord (abs)
76

@@ -13,7 +12,6 @@ main = do
1312
testOrderings
1413
testOrdUtils
1514
testIntDivMod
16-
testIntQuotRem
1715
testIntDegree
1816
testRecordInstances
1917

@@ -33,10 +31,6 @@ testOrd x y ord =
3331
nan :: Number
3432
nan = 0.0/0.0
3533

36-
-- Unfortunately, NaN inhabits our Int
37-
intNan :: Int
38-
intNan = mod 1 0
39-
4034
plusInfinity :: Number
4135
plusInfinity = 1.0/0.0
4236

@@ -64,7 +58,8 @@ testOrderings = do
6458
assert "NaN > 1 should be false" $ (nan > 1.0) == false
6559
assert "NaN < 1 should be false" $ (nan < 1.0) == false
6660
assert "NaN == 1 should be false" $ nan /= 1.0
67-
testOrd intNan 2147483647 GT
61+
testOrd (1 / 0) 0 EQ
62+
testOrd (mod 1 0) 0 EQ
6863
testOrd 'a' 'b' LT
6964
testOrd 'b' 'A' GT
7065
testOrd "10" "0" GT
@@ -105,39 +100,15 @@ testIntDivMod = do
105100
where
106101
go a b =
107102
let
108-
q = intDiv a b
109-
r = intMod a b
103+
q = a / b
104+
r = a `mod` b
110105
msg = show a <> " / " <> show b <> ": "
111106
in do
112107
assert (msg <> "Quotient/remainder law") $
113108
q * b + r == a
114109
assert (msg <> "Remainder should be between 0 and `abs b`, got: " <> show r) $
115110
0 <= r && r < abs b
116111

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

0 commit comments

Comments
 (0)