diff: int.m: fix bug in `div'

Fergus Henderson fjh at cs.mu.oz.au
Tue Nov 25 02:26:46 AEDT 1997


library/int.m:
	Fix a bug in the definition of `div'.

tests/hard_coded/division_test.m:
	Add some new regression tests for the above-mentioned bug.

cvs diff  library/int.m tests/hard_coded/division_test.m
Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.48
diff -u -r1.48 int.m
--- int.m	1997/11/23 05:19:20	1.48
+++ int.m	1997/11/24 15:18:51
@@ -208,12 +208,18 @@
 
 X div Y = Div :-
 	Trunc = X // Y,
-	( X // Y >= 0 ->
-		Div = Trunc
-	; X rem Y = 0 ->
-		Div = Trunc
+	( X > 0 ->
+		( Y > 0 ->
+			Div = Trunc
+		;
+			Div = Trunc - 1
+		)
 	;
-		Div = Trunc - 1
+		( Y > 0 ->
+			Div = Trunc - 1
+		;
+			Div = Trunc
+		)
 	).
 
 X mod Y = X - (X div Y) * Y.
Index: tests/hard_coded/division_test.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/division_test.m,v
retrieving revision 1.2
diff -u -r1.2 division_test.m
--- division_test.m	1997/03/23 19:44:01	1.2
+++ division_test.m	1997/11/24 14:22:19
@@ -13,6 +13,8 @@
 
 main -->
 	(
+		{ quot_test(3, 8, 0, 3) },		% 3 / 8 = 0 + 3/8
+		{ quot_test(5, 8, 0, 5) },		% 5 / 8 = 0 + 5/8
 		{ quot_test(7, 2, 3, 1) },		% 7 / 2 = 3 + 1/2
 		{ quot_test(100, 13, 7, 9) }		% 100 / 13 = 7 + 9/13
 	->
@@ -21,6 +23,8 @@
 		io__write_string("`//' test failed\n")
 	),
 	(
+		{ rem_test(3, 8, 0, 3) },		% 3 / 8 = 0 + 3/8
+		{ rem_test(5, 8, 0, 5) },		% 5 / 8 = 0 + 5/8
 		{ rem_test(7, 2, 3, 1) },		% 7 / 2 = 3 + 1/2
 		{ rem_test(100, 13, 7, 9) }		% 100 / 13 = 7 + 9/13
 	->
@@ -29,6 +33,8 @@
 		io__write_string("rem test failed\n")
 	),
 	(
+		{ div_test(3, 8, 0, 3) },		% 3 / 8 = 0 + 3/8
+		{ div_test(5, 8, 0, 5) },		% 5 / 8 = 0 + 5/8
 		{ div_test(7, 2, 3, 1) },		% 7 / 2 = 3 + 1/2
 		{ div_test(100, 13, 7, 9) }		% 100 / 13 = 7 + 9/13
 	->
@@ -37,6 +43,8 @@
 		io__write_string("div test failed\n")
 	),
 	(
+		{ mod_test(3, 8, 0, 3) },		% 3 / 8 = 0 + 3/8
+		{ mod_test(5, 8, 0, 5) },		% 5 / 8 = 0 + 5/8
 		{ mod_test(7, 2, 3, 1) },		% 7 / 2 = 3 + 1/2
 		{ mod_test(100, 13, 7, 9) }		% 100 / 13 = 7 + 9/13
 	->
-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list