From: Kevin Ryde <user42@zip.com.au>
Subject: new lognot
Date: Tue, 26 Aug 2003 08:11:39 +1000 [thread overview]
Message-ID: <87ad9xbd5w.fsf@zip.com.au> (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
next reply other threads:[~2003-08-25 22:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-25 22:11 Kevin Ryde [this message]
2003-08-31 17:52 ` new lognot Marius Vollmer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ad9xbd5w.fsf@zip.com.au \
--to=user42@zip.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).