[m-dev.] diff: fix bug in library/integer.m

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Sep 3 03:07:39 AEST 1999


Estimated hours taken: 0.5

library/integer.m:
	Fix a bug in the definition of `big_plus': it wasn't handling the
	cases where the sign was zero correctly.   I added some additional
	code to handle those cases.
	
	Also a few cosmetic changes to make the layout more consistent.

Workspace: /home/mercury0/fjh/mercury
Index: library/integer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/integer.m,v
retrieving revision 1.3
diff -u -r1.3 integer.m
--- integer.m	1999/07/07 15:19:38	1.3
+++ integer.m	1999/09/02 16:58:35
@@ -39,7 +39,7 @@
 %
 %	5) Use double-ended lists rather than simple lists. This
 %	  would improve the efficiency of the division algorithm,
-%	  which reverse lists.
+%	  which reverses lists.
 %
 %	6) Add bit operations (XOR, AND, OR, etc). We would treat
 %	  the integers as having a 2's complement bit representation.
@@ -274,6 +274,10 @@
 big_plus(i(S1, Ds1), i(S2, Ds2)) = Sum :-
 	( S1 = S2 ->
 		Sum = i(S1, pos_plus(Ds1, Ds2))
+	; S1 = 0 ->
+		Sum = i(S2, Ds2)
+	; S2 = 0 ->
+		Sum = i(S1, Ds1)
 	; S1 = 1 ->
 		C = pos_cmp(Ds1, Ds2),
 		( C = lessthan ->
@@ -285,13 +289,12 @@
 		)
 	;
 		C = pos_cmp(Ds1, Ds2),
-		(
-			C = lessthan ->
-				Sum = i(1, pos_sub(Ds2, Ds1))
-			; C = greaterthan ->
-				Sum = i(-1, pos_sub(Ds1, Ds2))
-			;
-				Sum = zero
+		( C = lessthan ->
+			Sum = i(1, pos_sub(Ds2, Ds1))
+		; C = greaterthan ->
+			Sum = i(-1, pos_sub(Ds1, Ds2))
+		;
+			Sum = zero
 		)
 	).
 
@@ -312,7 +315,7 @@
 			Result = i(Sign, Digs),
 			Digs = string_to_integer_acc(Cs, []),
 			pos_cmp(Digs, []) = Cmp,
-			(Cmp = equal ->
+			( Cmp = equal ->
 				Sign = 0
 			;
 				Sign = -1
@@ -321,7 +324,7 @@
 			Result = i(Sign, Digs),
 			Digs = string_to_integer_acc(CCs, []),
 			pos_cmp(Digs, []) = Cmp,
-			(Cmp = equal ->
+			( Cmp = equal ->
 				Sign = 0
 			;
 				Sign = 1

-- 
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.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list