[Commit] nickle Makefile.am,1.47,1.48 math.5c,1.37,1.38

Bart Massey commit at keithp.com
Thu Feb 26 21:05:20 PST 2004


Committed by: bart

Update of /local/src/CVS/nickle
In directory home.keithp.com:/tmp/cvs-serv16019

Modified Files:
	Makefile.am math.5c 
Log Message:
Added true integer logarithm



Index: Makefile.am
===================================================================
RCS file: /local/src/CVS/nickle/Makefile.am,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- Makefile.am	27 Feb 2004 04:49:07 -0000	1.47
+++ Makefile.am	27 Feb 2004 05:05:18 -0000	1.48
@@ -74,7 +74,7 @@
 debuild debuild-signed: distdir
 	cp -a $(PACKAGE)-$(VERSION) $(PACKAGE)-$(VERSION).orig
 	rm -rf $(PACKAGE)-$(VERSION).orig/debian
-	(cd $(PACKAGE)-$(VERSION)/debian && debuild)
+	(cd $(PACKAGE)-$(VERSION)/debian && debuild -us -uc)
 
 debuild-unsigned: distdir
 	cp -a $(PACKAGE)-$(VERSION) $(PACKAGE)-$(VERSION).orig

Index: math.5c
===================================================================
RCS file: /local/src/CVS/nickle/math.5c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- math.5c	16 Sep 2003 01:18:30 -0000	1.37
+++ math.5c	27 Feb 2004 05:05:18 -0000	1.38
@@ -870,6 +870,40 @@
 	return arg;
     }
 
+
+    /*
+     * Fast integer logarithm via binary search from below (no division).
+     * Returns floor(log(n)/log(base)) with no rounding error
+     */
+    public int ilog(int base, int n) {
+	if (base <= 1)
+	    raise invalid_argument("ilog of bad base", 0, base);
+	if (n <= 0)
+	    raise invalid_argument("ilog of bad value", 1, n);
+	int below = 0;
+	int above = 1;
+	int k = base;
+	while (k <= n) {
+	    k *= k;
+	    below = above;
+	    above *= 2;
+	}
+	while (true) {
+	    int q = base ** below;
+	    k = base;
+	    int nbelow = 0;
+	    int nabove = 1;
+	    while (q * k <= n) {
+		k *= k;
+		nbelow = nabove;
+		nabove *= 2;
+	    }
+	    if (nbelow == 0)
+		break;
+	    below += nbelow;
+	}
+	return below;
+    }
 }
 
 /* XXX these shouldn't be here, but it was *convenient* */




More information about the Commit mailing list