From: Markus Mottl <markus@oefai.at>
To: yminsky@cs.cornell.edu
Cc: Jean-Christophe Filliatre <jean-christophe.filliatre@lri.fr>,
Caml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Counting bits in a big_int
Date: Sat, 15 May 2004 13:14:33 +0200 [thread overview]
Message-ID: <20040515111433.GA32168@fichte.ai.univie.ac.at> (raw)
In-Reply-To: <891bd3390405141953628db08a@mail.gmail.com>
On Fri, 14 May 2004, Yaron Minsky wrote:
> Here's the fastest bitcounter I've been able to come up with. It's
> about an order of magnitude faster than just counting bit by bit.
How about this:
---------------------------------------------------------------------------
open Big_int
open Nat
let nbits x =
let nat = nat_of_big_int (abs_big_int x) in
let nwords = num_digits_nat nat 0 (length_nat nat) in
Sys.word_size * nwords - num_leading_zero_bits_in_digit nat (nwords - 1)
---------------------------------------------------------------------------
This runs another order of magnitude faster, and it's shorter, too :-)
Regards,
Markus
--
Markus Mottl http://www.oefai.at/~markus markus@oefai.at
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
next prev parent reply other threads:[~2004-05-15 11:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-12 3:22 Yaron Minsky
2004-05-12 4:19 ` Michael Hoisie
[not found] ` <16547.8441.559944.112854@gargle.gargle.HOWL>
[not found] ` <891bd3390405130427180c36d6@mail.gmail.com>
[not found] ` <16547.27869.60461.270873@gargle.gargle.HOWL>
2004-05-15 2:53 ` Yaron Minsky
2004-05-15 11:14 ` Markus Mottl [this message]
2004-05-15 20:19 ` Yaron Minsky
2004-05-16 0:51 ` skaller
2004-05-16 7:30 ` Xavier Leroy
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040515111433.GA32168@fichte.ai.univie.ac.at \
--to=markus@oefai.at \
--cc=caml-list@inria.fr \
--cc=jean-christophe.filliatre@lri.fr \
--cc=yminsky@cs.cornell.edu \
/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