diff: Prolog int__bits_per_int

Fergus Henderson fjh at cs.mu.oz.au
Wed May 7 21:28:21 AEST 1997


library/int.nu.nl:
	Add a Prolog implementation of `int__bits_per_int'.

Index: int.nu.nl
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/int.nu.nl,v
retrieving revision 1.1
diff -u -r1.1 int.nu.nl
--- int.nu.nl	1995/07/14 16:53:39	1.1
+++ int.nu.nl	1997/05/07 11:27:06
@@ -16,4 +16,19 @@
 	% but the following is more portable (e.g. works on SWI-Prolog)
 	Float is Int + 0.0.
 
+int__bits_per_int(Bits) :-
+	int__bits_per_int_2(1, 64, Bits).
+
+int__bits_per_int_2(N, Max, Bits) :-
+	( N >= Max ->
+		% Some Prologs (e.g. SICStus) have arbitrary precision
+		% integers, so we have to stop somewhere
+		Bits = Max
+	; (1 << N) < 0 ->
+		Bits is N + 1
+	; 
+		N1 is N + 1,
+		int__bits_per_int_2(N1, Max, Bits)
+	).
+
 %-----------------------------------------------------------------------------%

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