[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new lognot

From: Kevin Ryde
Subject: new lognot
Date: Tue, 26 Aug 2003 08:11:39 +1000
User-agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.3 (gnu/linux)

I'd like to suggest the rewrite below for lognot.  I think it'd be a
good thing if lognot behaved like logand etc and accepted only
integers.  The current use of scm_difference means a flonum or complex
will work, but they're really not sensible operands.

The use of mpz_com is a bit more direct too, though in fact it won't
be much different speed-wise from mpz_sub.

SCM_DEFINE (scm_lognot, "lognot", 1, 0, 0,
            (SCM n),
            "Return the integer which is the ones-complement of the integer\n"
            "(number->string (lognot #b10000000) 2)\n"
            "   @result{} \"-10000001\"\n"
            "(number->string (lognot #b0) 2)\n"
            "   @result{} \"-1\"\n"
            "@end lisp")
#define FUNC_NAME s_scm_lognot
  if (SCM_INUMP (n)) {
    /* No overflow here, just need to toggle all the bits making up the inum.
       Enhancement: No need to unpack and put a new tag etc, could just xor
       a block of 1 bits.  */
    return SCM_MAKINUM (~ SCM_INUM (n));

  } else if (SCM_BIGP (n)) {
    SCM result = scm_i_mkbig ();
    mpz_com (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (n));
    scm_remember_upto_here_1 (n);
    return result;

  } else {
#undef FUNC_NAME

reply via email to

[Prev in Thread] Current Thread [Next in Thread]