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

Re: (OT) Defining Variables in C with Bases other than 2 or 16



also sprach Martin McCormick <martin@dc.cis.okstate.edu> [2005.02.15.2104 +0100]:
> I have written code that does this sort of modulo arithmetic
> before so it won't be anything special, but I thought I would ask
> to make sure I wasn't re-inventing the wheel.

Well, as I said, there are probably libraries out there. boost
provides them for C++, they must exist for C as well.

In any case, if you are out for performance, avoid the modulo. If
you want a fixed limit, I suggest providing a typedef to an int, and
an add and get function. Use the fact that 2^18 % 12 == 0 and work
with bits 18, 19, and 20 to make automatic use of the integer limit
for rollover.

Sorry, too late to produce code examples, thus left as an exercise
for the reader.

-- 
Please do not send copies of list mail to me; I read the list!
 
 .''`.     martin f. krafft <madduck@debian.org>
: :'  :    proud Debian developer, admin, user, and author
`. `'`
  `-  Debian - when you have better things to do than fixing a system
 
Invalid/expired PGP subkeys? Use subkeys.pgp.net as keyserver!

Attachment: signature.asc
Description: Digital signature


Reply to: