Added integer-length.

Pascal J. Bourguignon [2014-02-05 23:03]
Added integer-length.
Filename
pjb-cl.el
diff --git a/pjb-cl.el b/pjb-cl.el
index 85f91e7..0e28f6d 100644
--- a/pjb-cl.el
+++ b/pjb-cl.el
@@ -127,6 +127,16 @@ RETURN: Whether `char' is in `bag'.
 ;; Common-Lisp


+(defun integer-length (x)
+  (if (minusp x)
+    (integer-length (- x))
+    (loop
+     until (zerop x)
+     do (setf x (ash x -1))
+     sum 1 into result
+     finally (return result))))
+
+
 ;; -----------------------------
 ;; - 5 - Data and Control Flow -
 ;; -----------------------------
ViewGit