[m-rev.] for review: export rational.inverse/1 from rational module

Julien Fischer juliensf at students.cs.mu.OZ.AU
Mon Jan 12 15:16:16 AEDT 2004


Estimated hours taken: 0.5
Branches: main

Export the inverse function from the rational module.  This is a little
cleaner than having to take the reciprocal of a number by dividing one by
it.

NEWS:
	Mention this change.

library/rational.m:
	Export rational.inverse/1 from this module.

tests/hard_coded/rational_test.m:
	Perform this test using the inverse function from the library.
	Delete the definition that was here.


Index: library/rational.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rational.m,v
retrieving revision 1.6
diff -u -r1.6 rational.m
--- library/rational.m	18 Dec 2003 07:48:19 -0000	1.6
+++ library/rational.m	7 Jan 2004 03:14:58 -0000
@@ -64,6 +64,8 @@

 :- func rational__abs(rational) = rational.

+:- func rational__inverse(rational) = rational.
+
 :- func rational__one = rational.

 :- func rational__zero = rational.
@@ -150,9 +152,7 @@

 R1 / R2 = R1 * inverse(R2).

-:- func inverse(rational) = rational.
-
-inverse(r(Num, Den)) =
+rational__inverse(r(Num, Den)) =
 	( Num = integer__zero ->
 		func_error("rational__inverse: division by zero")
 	;
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.325
diff -u -r1.325 NEWS
--- NEWS	22 Dec 2003 11:21:35 -0000	1.325
+++ NEWS	6 Jan 2004 03:22:05 -0000
@@ -206,8 +206,8 @@
 * We've added some constant functions, integer.zero/0 and integer.one/0
   to integer.m.  We have also added a function version of integer.pow/3.

-* We've added some functions, rational.int/1, rational.from_integer/1
-  and rational.from_integers/2 to rational.m
+* We've added some functions, rational.int/1, rational.from_integer/1,
+  rational.from_integers/2 and rational.inverse/1 to rational.m
   The function rational.rational_from_integers/2 has been deprecated.

 Changes to the extras distribution:
Index: tests/hard_coded/rational_test.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/rational_test.m,v
retrieving revision 1.1
diff -u -r1.1 rational_test.m
--- tests/hard_coded/rational_test.m	16 Apr 1998 12:00:32 -0000	1.1
+++ tests/hard_coded/rational_test.m	12 Jan 2004 03:35:14 -0000
@@ -29,9 +29,6 @@
 cf2rat([N|Ns]) = rational(N,1) + inverse(CF) :-
 	CF = cf2rat(Ns).

-:- func inverse(rational) = rational.
-inverse(Rat) = rational(1,1) / Rat.
-
 	% Continued fraction expansion of Euler's constant `e'.
 :- func e_cf(int) = list(int).
 e_cf(N) = CF :-
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list