for review: math.m preds becomes funx

Bert Thompson aet at cs.mu.oz.au
Mon Apr 14 15:24:55 AEST 1997


Andrew,

Can you please review this...

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Estimated hours taken: 1

Changed mathematics predicates into functions, which are generally 
more convenient.

mercury/library/math.m

CVS: ----------------------------------------------------------------------
CVS: Enter Log.  Lines beginning with `CVS: ' are removed automatically
CVS: 
CVS: Modified Files:
CVS: 	math.m 
CVS: ----------------------------------------------------------------------

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Index: math.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/math.m,v
retrieving revision 1.6
diff -u -r1.6 math.m
--- math.m	1997/02/08 17:19:15	1.6
+++ math.m	1997/04/14 05:01:52
@@ -26,143 +26,144 @@
 % Mathematical constants
 
 	% Pythagoras' number
-:- pred math__pi(float).
-:- mode math__pi(out) is det.
+:- func math__pi = float.
+:- mode math__pi = out is det.
+
 
 	% Base of natural logarithms
-:- pred math__e(float).
-:- mode math__e(out) is det.
+:- func math__e = float.
+:- mode math__e = out is det.
 
 %---------------------------------------------------------------------------%
 % "Next integer" operations
 
-	% math__ceiling(X, Ceil) is true if Ceil is the smallest integer
+	% math__ceiling(X) = Ceil is true if Ceil is the smallest integer
 	% not less than X.
-:- pred math__ceiling(float, float).
-:- mode math__ceiling(in, out) is det.
+:- func math__ceiling(float) = float.
+:- mode math__ceiling(in) = out is det.
 
-	% math__floor(X, Floor) is true if Floor is the largest integer
+	% math__floor(X) = Floor is true if Floor is the largest integer
 	% not greater than X.
-:- pred math__floor(float, float).
-:- mode math__floor(in, out) is det.
+:- func math__floor(float) = float.
+:- mode math__floor(in) = out is det.
 
-	% math__round(X, Round) is true if Round is the integer
+	% math__round(X) = Round is true if Round is the integer
 	% closest to X.  If X has a fractional value of 0.5, it
 	% is rounded up.
-:- pred math__round(float, float).
-:- mode math__round(in, out) is det.
+:- func math__round(float) = float.
+:- mode math__round(in) = out is det.
 
-	% math__truncate(X, Trunc) is true if Trunc is the integer
+	% math__truncate(X) = Trunc is true if Trunc is the integer
 	% closest to X such that |Trunc| =< |X|.
-:- pred math__truncate(float, float).
-:- mode math__truncate(in, out) is det.
+:- func math__truncate(float) = float.
+:- mode math__truncate(in) = out is det.
 
 %---------------------------------------------------------------------------%
 % Power/logarithm operations
 
-	% math__sqrt(X, Sqrt) is true if Sqrt is the positive square
+	% math__sqrt(X) = Sqrt is true if Sqrt is the positive square
 	% root of X.
 	%
 	% Domain restriction: X >= 0
-:- pred math__sqrt(float, float).
-:- mode math__sqrt(in, out) is det.
+:- func math__sqrt(float) = float.
+:- mode math__sqrt(in) = out is det.
 
-	% math__pow(X, Y, Res) is true if Res is X raised to the
+	% math__pow(X, Y) = Res is true if Res is X raised to the
 	% power of Y.
 	%
 	% Domain restriction: X >= 0 and (X = 0 implies Y > 0)
-:- pred math__pow(float, float, float).
-:- mode math__pow(in, in, out) is det.
+:- func math__pow(float, float) = float.
+:- mode math__pow(in, in) = out is det.
 
-	% math__exp(X, Exp) is true if Exp is X raised to the
+	% math__exp(X) = Exp is true if Exp is X raised to the
 	% power of e.
-:- pred math__exp(float, float).
-:- mode math__exp(in, out) is det.
+:- func math__exp(float) = float.
+:- mode math__exp(in) = out is det.
 
-	% math__ln(X, Log) is true if Log is the natural logarithm
+	% math__ln(X) = Log is true if Log is the natural logarithm
 	% of X.
 	%
 	% Domain restriction: X > 0
-:- pred math__ln(float, float).
-:- mode math__ln(in, out) is det.
+:- func math__ln(float) = float.
+:- mode math__ln(in) = out is det.
 
-	% math__log10(X, Log) is true if Log is the logarithm to
+	% math__log10(X) = Log is true if Log is the logarithm to
 	% base 10 of X.
 	%
 	% Domain restriction: X > 0
-:- pred math__log10(float, float).
-:- mode math__log10(in, out) is det.
+:- func math__log10(float) = float.
+:- mode math__log10(in) = out is det.
 
-	% math__log2(X, Log) is true if Log is the logarithm to
+	% math__log2(X) = Log is true if Log is the logarithm to
 	% base 2 of X.
 	%
 	% Domain restriction: X > 0
-:- pred math__log2(float, float).
-:- mode math__log2(in, out) is det.
+:- func math__log2(float) = float.
+:- mode math__log2(in) = out is det.
 
-	% math__log(B, X, Log) is true if Log is the logarithm to
+	% math__log(B, X) = Log is true if Log is the logarithm to
 	% base B of X.
 	%
 	% Domain restriction: X > 0 and B > 0 and B \= 1
-:- pred math__log(float, float, float).
-:- mode math__log(in, in, out) is det.
+:- func math__log(float, float) = float.
+:- mode math__log(in, in) = out is det.
 
 %---------------------------------------------------------------------------%
 % Trigonometric operations
 
-	% math__sin(X, Sin) is true if Sin is the sine of X.
-:- pred math__sin(float, float).
-:- mode math__sin(in, out) is det.
-
-	% math__cos(X, Cos) is true if Cos is the cosine of X.
-:- pred math__cos(float, float).
-:- mode math__cos(in, out) is det.
-
-	% math__tan(X, Tan) is true if Tan is the tangent of X.
-:- pred math__tan(float, float).
-:- mode math__tan(in, out) is det.
+	% math__sin(X) = Sin is true if Sin is the sine of X.
+:- func math__sin(float) = float.
+:- mode math__sin(in) = out is det.
+
+	% math__cos(X) = Cos is true if Cos is the cosine of X.
+:- func math__cos(float) = float.
+:- mode math__cos(in) = out is det.
+
+	% math__tan(X) = Tan is true if Tan is the tangent of X.
+:- func math__tan(float) = float.
+:- mode math__tan(in) = out is det.
 
-	% math__asin(X, ASin) is true if ASin is the inverse
+	% math__asin(X) = ASin is true if ASin is the inverse
 	% sine of X, where ASin is in the range [-pi/2,pi/2].
 	%
 	% Domain restriction: X must be in the range [-1,1]
-:- pred math__asin(float, float).
-:- mode math__asin(in, out) is det.
+:- func math__asin(float) = float.
+:- mode math__asin(in) = out is det.
 
-	% math__acos(X, ACos) is true if ACos is the inverse
+	% math__acos(X) = ACos is true if ACos is the inverse
 	% cosine of X, where ACos is in the range [0, pi].
 	%
 	% Domain restriction: X must be in the range [-1,1]
-:- pred math__acos(float, float).
-:- mode math__acos(in, out) is det.
+:- func math__acos(float) = float.
+:- mode math__acos(in) = out is det.
 
-	% math__atan(X, ATan) is true if ATan is the inverse
+	% math__atan(X) = ATan is true if ATan is the inverse
 	% tangent of X, where ATan is in the range [-pi/2,pi/2].
-:- pred math__atan(float, float).
-:- mode math__atan(in, out) is det.
+:- func math__atan(float) = float.
+:- mode math__atan(in) = out is det.
 
-	% math__atan2(Y, X, ATan) is true if ATan is the inverse
+	% math__atan2(Y, X) = ATan is true if ATan is the inverse
 	% tangent of Y/X, where ATan is in the range [-pi,pi].
-:- pred math__atan2(float, float, float).
-:- mode math__atan2(in, in, out) is det.
+:- func math__atan2(float, float) = float.
+:- mode math__atan2(in, in) = out is det.
 
 %---------------------------------------------------------------------------%
 % Hyperbolic functions
 
-	% math__sinh(X, Sinh) is true if Sinh is the hyperbolic
+	% math__sinh(X) = Sinh is true if Sinh is the hyperbolic
 	% sine of X.
-:- pred math__sinh(float, float).
-:- mode math__sinh(in, out) is det.
+:- func math__sinh(float) = float.
+:- mode math__sinh(in) = out is det.
 
-	% math__cosh(X, Cosh) is true if Cosh is the hyperbolic
+	% math__cosh(X) = Cosh is true if Cosh is the hyperbolic
 	% cosine of X.
-:- pred math__cosh(float, float).
-:- mode math__cosh(in, out) is det.
+:- func math__cosh(float) = float.
+:- mode math__cosh(in) = out is det.
 
-	% math__tanh(X, Tanh) is true if Tanh is the hyperbolic
+	% math__tanh(X) = Tanh is true if Tanh is the hyperbolic
 	% tangent of X.
-:- pred math__tanh(float, float).
-:- mode math__tanh(in, out) is det.
+:- func math__tanh(float) = float.
+:- mode math__tanh(in) = out is det.
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%
@@ -210,37 +211,45 @@
 % Mathematical constants from math.m
 %
 	% Pythagoras' number
-:- pragma(c_code, math__pi(Pi::out), "Pi = MERCURY_FLOAT__PI;").
+:- pragma c_code(math__pi = (Pi::out),will_not_call_mercury,"
+	Pi = MERCURY_FLOAT__PI;
+").
 
 	% Base of natural logarithms
-:- pragma(c_code, math__e(E::out), "E = MERCURY_FLOAT__E;").
+:- pragma c_code(math__e = (E::out),will_not_call_mercury,"
+	E = MERCURY_FLOAT__E;
+").
 
 %
-% math__ceiling(X, Ceil) is true if Ceil is the smallest integer
+% math__ceiling(X) = Ceil is true if Ceil is the smallest integer
 % not less than X.
 %
-:- pragma(c_code, math__ceiling(Num::in, Ceil::out), "Ceil = ceil(Num);").
+:- pragma c_code(math__ceiling(Num::in) = (Ceil::out), will_not_call_mercury,"
+	Ceil = ceil(Num);
+").
 
 %
-% math__floor(X, Floor) is true if Floor is the largest integer
+% math__floor(X) = Floor is true if Floor is the largest integer
 % not greater than X.
 %
-:- pragma(c_code, math__floor(Num::in, Floor::out), "Floor = floor(Num);").
+:- pragma c_code(math__floor(Num::in) = (Floor::out), will_not_call_mercury,"
+	Floor = floor(Num);
+").
 
 %
-% math__round(X, Round) is true if Round is the integer
+% math__round(X) = Round is true if Round is the integer
 % closest to X.  If X has a fractional component of 0.5,
 % it is rounded up.
 %
-:- pragma(c_code, math__round(Num::in, Rounded::out), "
+:- pragma c_code(math__round(Num::in) = (Rounded::out), will_not_call_mercury,"
 	Rounded = floor(Num+0.5);
 ").
 
 %
-% math__truncate(X, Trunc) is true if Trunc is the integer
+% math__truncate(X) = Trunc is true if Trunc is the integer
 % closest to X such that |Trunc| =< |X|.
 %
-:- pragma(c_code, math__truncate(X::in, Trunc::out), "
+:- pragma c_code(math__truncate(X::in) = (Trunc::out), will_not_call_mercury,"
 	if (X < 0.0) {
 	    Trunc = ceil(X);
 	} else {
@@ -249,13 +258,13 @@
 ").
 
 %
-% math__sqrt(X, Sqrt) is true if Sqrt is the positive square
+% math__sqrt(X) = Sqrt is true if Sqrt is the positive square
 % root of X.  
 %
 % Domain restrictions:
 %		X >= 0
 %
-:- pragma(c_code, math__sqrt(X::in, SquareRoot::out), "
+:- pragma c_code(math__sqrt(X::in) = (SquareRoot::out), will_not_call_mercury,"
 	if (X < 0.0) {
 	    mercury_domain_error(""math__sqrt"");
 	}
@@ -263,14 +272,14 @@
 ").
 
 %
-% math__pow(X, Y, Res) is true if Res is X raised to the
+% math__pow(X, Y) = Res is true if Res is X raised to the
 % power of Y.
 %
 % Domain restrictions:
 %		X >= 0
 %		X = 0 implies Y > 0
 %
-:- pragma(c_code, math__pow(X::in, Y::in, Res::out), "
+:- pragma c_code(math__pow(X::in, Y::in) = (Res::out), will_not_call_mercury,"
 	if (X < 0.0) {
 	    mercury_domain_error(""math__pow"");
 	}
@@ -285,19 +294,21 @@
 ").
 
 %
-% math__exp(X, Exp) is true if Exp is X raised to the
+% math__exp(X) = Exp is true if Exp is X raised to the
 % power of e.
 %
-:- pragma(c_code, math__exp(X::in, Exp::out), "Exp = exp(X);").
+:- pragma c_code(math__exp(X::in) = (Exp::out), will_not_call_mercury,"
+	Exp = exp(X);
+").
 
 %
-% math__ln(X, Log) is true if Log is the natural logarithm
+% math__ln(X) = Log is true if Log is the natural logarithm
 % of X.
 %
 % Domain restrictions:
 %		X > 0
 %
-:- pragma(c_code, math__ln(X::in, Log::out), "
+:- pragma c_code(math__ln(X::in) = (Log::out), will_not_call_mercury,"
 	if (X <= 0.0) {
 	    mercury_domain_error(""math__ln"");
 	}
@@ -305,26 +316,26 @@
 ").
 
 %
-% math__log10(X, Log) is true if Log is the logarithm to
+% math__log10(X) = Log is true if Log is the logarithm to
 % base 10 of X.
 %
 % Domain restrictions:
 %		X > 0
 %
-:- pragma(c_code, math__log10(X::in, Log10::out), "
+:- pragma c_code(math__log10(X::in) = (Log10::out), will_not_call_mercury,"
 	if (X <= 0.0)
 	    mercury_domain_error(""math__log10"");
 	Log10 = log10(X);
 ").
 
 %
-% math__log2(X, Log) is true if Log is the logarithm to
+% math__log2(X) = Log is true if Log is the logarithm to
 % base 2 of X.
 %
 % Domain restrictions:
 %		X > 0
 %
-:- pragma(c_code, math__log2(X::in, Log2::out), "
+:- pragma c_code(math__log2(X::in) = (Log2::out), will_not_call_mercury,"
 	if (X <= 0.0) {
 	    mercury_domain_error(""math__log2"");
 	}
@@ -332,7 +343,7 @@
 ").
 
 %
-% math__log(B, X, Log) is true if Log is the logarithm to
+% math__log(B, X) = Log is true if Log is the logarithm to
 % base B of X.
 %
 % Domain restrictions:
@@ -340,7 +351,7 @@
 %		B > 0
 %		B \= 1
 %
-:- pragma(c_code, math__log(B::in, X::in, Log::out), "
+:- pragma c_code(math__log(B::in, X::in) = (Log::out), will_not_call_mercury,"
 	if (X <= 0.0 || B <= 0.0) {
 	    mercury_domain_error(""math__log"");
 	}
@@ -351,28 +362,34 @@
 ").
 
 %
-% math__sin(X, Sin) is true if Sin is the sine of X.
+% math__sin(X) = Sin is true if Sin is the sine of X.
 %
-:- pragma(c_code, math__sin(X::in, Sin::out), "Sin = sin(X);").
+:- pragma c_code(math__sin(X::in) = (Sin::out), will_not_call_mercury,"
+	Sin = sin(X);
+").
 
 %
-% math__cos(X, Sin) is true if Cos is the cosine of X.
+% math__cos(X) = Sin is true if Cos is the cosine of X.
 %
-:- pragma(c_code, math__cos(X::in, Cos::out), "Cos = cos(X);").
+:- pragma c_code(math__cos(X::in) = (Cos::out), will_not_call_mercury,"
+	Cos = cos(X);
+").
 
 %
-% math__tan(X, Tan) is true if Tan is the tangent of X.
+% math__tan(X) = Tan is true if Tan is the tangent of X.
 %
-:- pragma(c_code, math__tan(X::in, Tan::out), "Tan = tan(X);").
+:- pragma c_code(math__tan(X::in) = (Tan::out), will_not_call_mercury,"
+	Tan = tan(X);
+").
 
 %
-% math__asin(X, ASin) is true if ASin is the inverse
+% math__asin(X) = ASin is true if ASin is the inverse
 % sine of X, where ASin is in the range [-pi/2,pi/2].
 %
 % Domain restrictions:
 %		X must be in the range [-1,1]
 %
-:- pragma(c_code, math__asin(X::in, ASin::out), "
+:- pragma c_code(math__asin(X::in) = (ASin::out), will_not_call_mercury,"
 	if (X < -1.0 || X > 1.0) {
 	    mercury_domain_error(""math__asin"");
 	}
@@ -380,13 +397,13 @@
 ").
 
 %
-% math__acos(X, ACos) is true if ACos is the inverse
+% math__acos(X) = ACos is true if ACos is the inverse
 % cosine of X, where ACos is in the range [0, pi].
 %
 % Domain restrictions:
 %		X must be in the range [-1,1]
 %
-:- pragma(c_code, math__acos(X::in, ACos::out), "
+:- pragma c_code(math__acos(X::in) = (ACos::out), will_not_call_mercury,"
 	if (X < -1.0 || X > 1.0) {
 	    mercury_domain_error(""math__acos"");
 	}
@@ -394,36 +411,45 @@
 ").
 
 %
-% math__atan(X, ATan) is true if ATan is the inverse
+% math__atan(X) = ATan is true if ATan is the inverse
 % tangent of X, where ATan is in the range [-pi/2,pi/2].
 %
-:- pragma(c_code, math__atan(X::in, ATan::out), "ATan = atan(X);").
+:- pragma c_code(math__atan(X::in) = (ATan::out), will_not_call_mercury,"
+	ATan = atan(X);
+").
 
 %
-% math__atan2(Y, X, ATan) is true if ATan is the inverse
+% math__atan2(Y, X) = ATan is true if ATan is the inverse
 % tangent of Y/X, where ATan is in the range [-pi,pi].
 %
-:- pragma(c_code, math__atan2(Y::in, X::in, ATan2::out), "
+:- pragma c_code(math__atan2(Y::in, X::in) = (ATan2::out), 
+	will_not_call_mercury, "
 	ATan2 = atan2(Y, X);
 ").
 
 %
-% math__sinh(X, Sinh) is true if Sinh is the hyperbolic
+% math__sinh(X) = Sinh is true if Sinh is the hyperbolic
 % sine of X.
 %
-:- pragma(c_code, math__sinh(X::in, Sinh::out), "Sinh = sinh(X);").
+:- pragma c_code(math__sinh(X::in) = (Sinh::out), will_not_call_mercury,"
+	Sinh = sinh(X);
+").
 
 %
-% math__cosh(X, Cosh) is true if Cosh is the hyperbolic
+% math__cosh(X) = Cosh is true if Cosh is the hyperbolic
 % cosine of X.
 %
-:- pragma(c_code, math__cosh(X::in, Cosh::out), "Cosh = cosh(X);").
+:- pragma c_code(math__cosh(X::in) = (Cosh::out), will_not_call_mercury,"
+	Cosh = cosh(X);
+").
 
 %
-% math__tanh(X, Tanh) is true if Tanh is the hyperbolic
+% math__tanh(X) = Tanh is true if Tanh is the hyperbolic
 % tangent of X.
 %
-:- pragma(c_code, math__tanh(X::in, Tanh::out), "Tanh = tanh(X);").
+:- pragma c_code(math__tanh(X::in) = (Tanh::out), will_not_call_mercury,"
+	Tanh = tanh(X);
+").
 
 %---------------------------------------------------------------------------%
 %---------------------------------------------------------------------------%



More information about the developers mailing list