/* -*-C-*-
-$Id: artutl.c,v 1.12 1995/09/18 22:32:53 cph Exp $
+$Id: artutl.c,v 1.13 1997/04/22 22:42:16 cph Exp $
-Copyright (c) 1989-95 Massachusetts Institute of Technology
+Copyright (c) 1989-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
#include "scheme.h"
#include <math.h>
+#include "limits.h"
\f
/* Conversions between Scheme types and C types. */
: (bignum_to_integer (result)));
}
}
+\f
+SCHEME_OBJECT
+DEFUN (integer_length_in_bits, (n), SCHEME_OBJECT n)
+{
+ if (FIXNUM_P (n))
+ {
+ long n1 = (FIXNUM_TO_LONG (n));
+ unsigned long n2 = ((n1 < 0) ? (- n1) : n1);
+ unsigned long result = ((sizeof (unsigned long)) * CHAR_BIT);
+ unsigned long m = (1 << (result - 1));
+ while (result > 0)
+ {
+ if (n2 >= m)
+ break;
+ result -= 1;
+ m >>= 1;
+ }
+ return (LONG_TO_UNSIGNED_FIXNUM (result));
+ }
+ else
+ return (bignum_length_in_bits (n));
+}
/* -*-C-*-
-$Id: extern.h,v 9.53 1995/09/18 22:32:54 cph Exp $
+$Id: extern.h,v 9.54 1997/04/22 22:42:25 cph Exp $
-Copyright (c) 1987-95 Massachusetts Institute of Technology
+Copyright (c) 1987-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
SCHEME_OBJECT *, SCHEME_OBJECT *));
extern SCHEME_OBJECT EXFUN (integer_quotient, (SCHEME_OBJECT, SCHEME_OBJECT));
extern SCHEME_OBJECT EXFUN (integer_remainder, (SCHEME_OBJECT, SCHEME_OBJECT));
+extern SCHEME_OBJECT EXFUN (integer_length_in_bits, (SCHEME_OBJECT));
/* Character utilities */
extern long EXFUN (char_downcase, (long));
/* -*-C-*-
-$Id: intprm.c,v 1.4 1992/08/29 13:20:43 jinx Exp $
+$Id: intprm.c,v 1.5 1997/04/22 22:42:41 cph Exp $
-Copyright (c) 1989-1992 Massachusetts Institute of Technology
+Copyright (c) 1989-97 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
INTEGER_UNARY_OPERATION (integer_add_1)
DEFINE_PRIMITIVE ("INTEGER-SUBTRACT-1", Prim_integer_subtract_1, 1, 1, 0)
INTEGER_UNARY_OPERATION (integer_subtract_1)
+DEFINE_PRIMITIVE ("INTEGER-LENGTH-IN-BITS", Prim_integer_length_in_bits, 1, 1, 0)
+ INTEGER_UNARY_OPERATION (integer_length_in_bits)
\f
DEFINE_PRIMITIVE ("INTEGER-DIVIDE", Prim_integer_divide, 2, 2, 0)
{