unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* new lognot
@ 2003-08-25 22:11 Kevin Ryde
  2003-08-31 17:52 ` Marius Vollmer
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Ryde @ 2003-08-25 22:11 UTC (permalink / raw)


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"
	    "argument.\n"
	    "\n"
	    "@lisp\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 {
    SCM_WRONG_TYPE_ARG (SCM_ARG1, n);
  }
}
#undef FUNC_NAME


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: new lognot
  2003-08-25 22:11 new lognot Kevin Ryde
@ 2003-08-31 17:52 ` Marius Vollmer
  0 siblings, 0 replies; 2+ messages in thread
From: Marius Vollmer @ 2003-08-31 17:52 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> I'd like to suggest the rewrite below for lognot.

Ok!

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-08-31 17:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-25 22:11 new lognot Kevin Ryde
2003-08-31 17:52 ` Marius Vollmer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).