[m-rev.] diff: deprecate int.to_float/2 properly

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Jul 6 18:46:17 AEST 2004


Estimated hours taken: 0.5
Branches: main

Deprecate the predicate int.to_float/2 in favour of float.float/1.
(There has been a comment describing this as obsolete for some time).

NEWS:
	Mention this change.

library/float.m:
	Add an implementation of float.float/1 rather than
	just calling int.to_float/2.

library/int.m:
	Add a pragma obsolete declaration to int.to_float/2.
	The implementation will have to stay until the predicate
	is deleted because importing the float module into this
	one results in type ambiguities.

library/term.m:
profiler/generate_output.m:
profiler/output.m:
profiler/propagate.m:
tests/hard_coded/agg.m:
tests/hard_coded/qual_strang.m:
tests/hard_coded/qual_strung.m:
	Change calls to int.to_float/2 to calls to float.float/1.

Julien.


Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.335
diff -u -r1.335 NEWS
--- NEWS	21 Jun 2004 09:16:11 -0000	1.335
+++ NEWS	6 Jul 2004 08:24:28 -0000
@@ -103,6 +103,8 @@
   int.fold_up2/7 and int.fold_down2/7 support iteration over
   contiguous integer ranges.

+* The predicate int.to_float/2 has now been deprecated.
+
 * We've added a new library module, `array2d', for two-dimensional arrays.

 * We've added a new module, cord, for sequences with O(1) consing and
Index: library/float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/float.m,v
retrieving revision 1.59
diff -u -r1.59 float.m
--- library/float.m	11 Dec 2003 06:34:18 -0000	1.59
+++ library/float.m	6 Jul 2004 05:42:21 -0000
@@ -283,8 +283,26 @@
 %	explicitly.  So every time there's a cast to int, the bounds are
 %	checked first.

-float(Int) = Float :-
-	int__to_float(Int, Float).
+:- pragma foreign_proc("C",
+	float(IntVal::in) = (FloatVal::out),
+	[will_not_call_mercury, promise_pure],
+"
+	FloatVal = IntVal;
+").
+
+:- pragma foreign_proc("C#",
+	float(IntVal::in) = (FloatVal::out),
+	[will_not_call_mercury, promise_pure],
+"
+	FloatVal = (double) IntVal;
+").
+
+:- pragma foreign_proc("Java",
+	float(IntVal::in) = (FloatVal::out),
+	[will_not_call_mercury, promise_pure],
+"
+	FloatVal = (double) IntVal;
+").

 	% float__ceiling_to_int(X) returns the
 	% smallest integer not less than X.
Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.99
diff -u -r1.99 int.m
--- library/int.m	10 Apr 2004 13:05:58 -0000	1.99
+++ library/int.m	6 Jul 2004 08:38:56 -0000
@@ -59,6 +59,7 @@

 	% conversion of integer to floating point
 	% OBSOLETE: use float__float/1 instead.
+:- pragma obsolete(int.to_float/2).
 :- pred int__to_float(int, float) is det.
 :- mode int__to_float(in, out) is det.

Index: library/term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.105
diff -u -r1.105 term.m
--- library/term.m	31 May 2004 04:13:01 -0000	1.105
+++ library/term.m	6 Jul 2004 05:57:00 -0000
@@ -394,7 +394,7 @@
 %-----------------------------------------------------------------------------%

 :- implementation.
-:- import_module bool, char, std_util, require, array, int, string.
+:- import_module bool, char, float, std_util, require, array, int, string.

 %-----------------------------------------------------------------------------%

@@ -512,7 +512,7 @@
 	;
 		IsAditiTuple = yes,
 		Term = term__functor(term__integer(Int), [], _),
-		int__to_float(Int, Float),
+		Float = float__float(Int),
 		type_to_univ(Float, Univ)
 	).
 term__term_to_univ_special_case(IsAditiTuple, "array", "array", [ElemType],
Index: profiler/generate_output.m
===================================================================
RCS file: /home/mercury1/repository/mercury/profiler/generate_output.m,v
retrieving revision 1.19
diff -u -r1.19 generate_output.m
--- profiler/generate_output.m	11 Feb 1998 17:03:30 -0000	1.19
+++ profiler/generate_output.m	6 Jul 2004 06:34:25 -0000
@@ -59,7 +59,7 @@
 generate_output__main(Prof, IndexMap, Output) -->
 	% Get intitial values of use.
 	{ prof_get_entire(Prof, _, _, IntTotalCounts, _, ProfNodeMap, _) },
-	{ int__to_float(IntTotalCounts, _TotalCounts) },
+	{ _TotalCounts = float__float(IntTotalCounts) },

 	{ map__values(ProfNodeMap, ProfNodeList) },

@@ -128,7 +128,7 @@
 generate_output__cycle(ProfNode, Prof, OutputProf0, OutputProf) :-
 	prof_get_entire(Prof, Scale, _Units, IntTotalCounts, _, _,
 								_CycleMap),
-	int__to_float(IntTotalCounts, TotalCounts),
+	TotalCounts = float__float(IntTotalCounts),

 	prof_node_get_entire_cycle(ProfNode, Name, CycleNum, Initial, Prop,
 					_CycleMembers, TotalCalls, SelfCalls),
@@ -138,7 +138,7 @@
 	% Calculate proportion of time in current predicate and its
 	% descendents as a percentage.
 	%
-	int__to_float(Initial, InitialFloat),
+	InitialFloat = float__float(Initial),
 	(
 		TotalCounts = 0.0
 	->
@@ -175,7 +175,7 @@
 generate_output__single_predicate(ProfNode, Prof, OutputProf0, OutputProf) :-
 	prof_get_entire(Prof, Scale, _Units, IntTotalCounts, _, _,
 								CycleMap),
-	int__to_float(IntTotalCounts, TotalCounts),
+	TotalCounts = float__float(IntTotalCounts),

 	prof_node_get_entire_pred(ProfNode, LabelName, CycleNum, Initial, Prop,
 					ParentList, ChildList, TotalCalls,
@@ -197,7 +197,7 @@
 		% descendents as a percentage.
 		% Calculate proportion of time in current predicate
 		% as a percentage.
-		int__to_float(Initial, InitialFloat),
+		InitialFloat = float__float(Initial),
 		(
 			TotalCounts = 0.0
 		->
@@ -268,7 +268,7 @@
 			CycleMap, OutputParentList, OutputCycleParentList) :-
 	remove_cycle_members(Parents0, TotalCalls0, CycleNum, CycleMap,
 				TotalCalls, Parents, OutputCycleParentList),
-	int__to_float(TotalCalls, FltTotalCalls),
+	FltTotalCalls = float__float(TotalCalls),
 	process_prof_node_parents_2(Parents, SelfTime, DescTime, FltTotalCalls,
 						CycleMap, OutputParentList).

@@ -345,7 +345,7 @@
 		ParentCycleNum = 0
 	),

-        int__to_float(Calls, FloatCalls),
+        FloatCalls = float__float(Calls),
         checked_float_divide(FloatCalls, TotalCalls, Proportion),

 	% Calculate the amount of the current predicate's self-time spent
@@ -437,11 +437,11 @@
 	prof_node_get_propagated_counts(ProfNode, Prop),
 	prof_node_get_total_calls(ProfNode, TotalCalls),

-	int__to_float(Initial, InitialFloat),
+	InitialFloat = float__float(Initial),
 	CurrentCount is InitialFloat + Prop,

-	int__to_float(TotalCalls, FloatTotalCalls),
-        int__to_float(Calls, FloatCalls),
+	FloatTotalCalls = float__float(TotalCalls),
+	FloatCalls = float__float(Calls),
         checked_float_divide(FloatCalls, FloatTotalCalls, Proportion),

 	% Calculate the self time spent in the current predicate.
Index: profiler/output.m
===================================================================
RCS file: /home/mercury1/repository/mercury/profiler/output.m,v
retrieving revision 1.19
diff -u -r1.19 output.m
--- profiler/output.m	2 Apr 1998 12:01:41 -0000	1.19
+++ profiler/output.m	6 Jul 2004 06:35:03 -0000
@@ -438,9 +438,8 @@
 	),

 	{
-	int__to_float(SelfCalls, FloatSelfCalls),
-	int__to_float(TotalCalls, FloatTotalCalls0),
-
+	FloatSelfCalls = float__float(SelfCalls),
+	FloatTotalCalls0 = float__float(TotalCalls),
 	FloatTotalCalls is FloatTotalCalls0 + FloatSelfCalls,
 	Calls is SelfCalls + TotalCalls,
 	CumTime is CumTime0 + Self,
Index: profiler/propagate.m
===================================================================
RCS file: /home/mercury1/repository/mercury/profiler/propagate.m,v
retrieving revision 1.11
diff -u -r1.11 propagate.m
--- profiler/propagate.m	22 Dec 2003 11:21:48 -0000	1.11
+++ profiler/propagate.m	6 Jul 2004 06:37:26 -0000
@@ -235,7 +235,7 @@
 		prof_node_get_propagated_counts(ProfNode, PropCounts),
 		prof_node_get_parent_list(ProfNode, ParentList),
 		prof_node_get_total_calls(ProfNode, TotalCalls),
-		int__to_float(InitCounts, InitCountsFloat),
+		InitCountsFloat = float__float(InitCounts),

 		% writeln("Predicate:"),
 		% writeln(Pred),
@@ -246,7 +246,7 @@

 		TotalCounts is InitCountsFloat + PropCounts,

-		int__to_float(TotalCalls, FltTotalCalls),
+		FltTotalCalls = float__float(TotalCalls),

 		propagate__counts_3(ParentList, TotalCounts, FltTotalCalls,
 				AddrDeclMap, ProfNodeMap0, ProfNodeMap1),
@@ -296,8 +296,8 @@


 		% Propagate the counts XXX
-	int__to_float(SelfCounts, FltSelfCounts),
-	int__to_float(Total, TotalCalls),
+	FltSelfCounts = float__float(SelfCounts),
+	TotalCalls = float__float(Total),
 	TotalCounts is FltSelfCounts + PropCounts,
 	propagate__counts_3(ParentList, TotalCounts, TotalCalls, AddrMap,
 						ProfNodeMap1, ProfNodeMap).
@@ -362,7 +362,7 @@

 		% Work out the number of counts to propagate.
 		% XXX Probably need to do a 0.0 check
-	int__to_float(Calls, FloatCalls),
+	FloatCalls = float__float(Calls),
 	ToPropagateCounts is FloatCalls / TotalCalls * TotalCounts,

 		% Add new counts to current propagated counts
Index: tests/hard_coded/agg.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/agg.m,v
retrieving revision 1.2
diff -u -r1.2 agg.m
--- tests/hard_coded/agg.m	15 Mar 1999 16:31:02 -0000	1.2
+++ tests/hard_coded/agg.m	6 Jul 2004 06:43:22 -0000
@@ -84,8 +84,8 @@
 	aggregate(P, agg_pair(count, sum(F)), C-S),
 	( C = 0 ->
 		A = no
-    	;	int__to_float(C, C1),
-		int__to_float(S, S1),
+    	;	C1 = float__float(C),
+		S1 = float__float(S),
 		A = yes(S1/C1)
 	).

Index: tests/hard_coded/qual_strang.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/qual_strang.m,v
retrieving revision 1.6
diff -u -r1.6 qual_strang.m
--- tests/hard_coded/qual_strang.m	26 May 2003 09:01:08 -0000	1.6
+++ tests/hard_coded/qual_strang.m	6 Jul 2004 06:45:29 -0000
@@ -121,7 +121,7 @@
 		(Poly_var = f(F) ->
 			float_abs(F, Ft),
 			int__pow(10, Precision, P),
-			int__to_float(P, Pe),
+			Pe = float__float(P),
 			(
 				Ft > 0.0001,
 				Pe > Ft
@@ -138,7 +138,7 @@
 		(Poly_var = f(F) ->
 			float_abs(F, Ft),
 			int__pow(10, Precision, P),
-			int__to_float(P, Pe),
+			Pe = float__float(P),
 			(
 				Ft > 0.0001,
 				Pe > Ft
Index: tests/hard_coded/qual_strung.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/qual_strung.m,v
retrieving revision 1.6
diff -u -r1.6 qual_strung.m
--- tests/hard_coded/qual_strung.m	26 May 2003 09:01:09 -0000	1.6
+++ tests/hard_coded/qual_strung.m	6 Jul 2004 06:44:45 -0000
@@ -123,7 +123,7 @@
 		(Poly_var = f(F) ->
 			float_abs(F, Ft),
 			int__pow(10, Precision, P),
-			int__to_float(P, Pe),
+			Pe = float__float(P),
 			(
 				Ft > 0.0001,
 				Pe > Ft
@@ -140,7 +140,7 @@
 		(Poly_var = f(F) ->
 			float_abs(F, Ft),
 			int__pow(10, Precision, P),
-			int__to_float(P, Pe),
+			Pe = float__float(P),
 			(
 				Ft > 0.0001,
 				Pe > Ft

--------------------------------------------------------------------------
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