Coder's Guild Mailing List

Re: lisp number converted to c/c++

Posted by Dan Nuffer on 1999-09-06

> I'm sure many of you are familiar with lisp so i'll forgo the
> description of the numbers.
>
> What i'm trying to do is make some c/c++ code that will be able to
> handle numbers like lisp does.  So the question is, how does lisp
> add/sub/mul/div/... numbers?
>

I've written some code that will do arbitrary size integer arithmetic.  It's
a C++ class called BigInteger.  You can use it anywhere you can use an
integer, all operations are supported.  It can get as big as you want,
limited only by the memory you have.  However, some operations are rather
slow, such as division and conversion to base 10 in order to print it out,
but it's fast until you get up to really huge numbers.
Anyway, you can download the code at:

http://students.cs.byu.edu/~nuffer/biginteger.cpp
http://students.cs.byu.edu/~nuffer/biginteger.h

I have run some tests of this code and think it's relatively bug-free,
however I haven't used it extensively, so I not going to guarantee it or
anything, but if you find any bugs, let me know or if you come up with a way
to speed it up (especially for division), that would be great too.

--Dan Nuffer