views:

298

answers:

6

Hi everyone,

Summer is coming, and a group of friends and I are getting ready for it :)

We decided to build a compile-time Arbitrary precision Unsigned Integers. We would like to provide a set of integers algorithms(functions) with the library. We have seen a number of requests for such a library(SoC2010, C++0x Standard Library wishlist). Also, a regular run-time bigint is requested usually with that, but we don't want to go into the hassle of memory management. The idea came to me from a library called TTMath, unfortunately this library works only on specific platforms because Assembly was used extensively in the library. We would like to write a standard library, depending on the C++ standard library and Boost. Also, we would like to use the available C++0x facilities in current compilers like user-defined literals and others. This would technically make the library non-standard for a while, but we think that it is a matter of time the new standards will be official.

Your hints on the whole process including design, implementation, documentation, maintainable of the library are more than welcom. We are a group of students and fresh graduates who are looking for something interesting in the summer, but we see that Boost is full of gurus and we don't want to forget something too obvious. We are communicating on-line, so there is no shared white-boards :(

Here is an example of using such a library:

typedef our_namespace::uint<512> uint512_t;
// declaring an unsigned int with 512 bits width.
// After that the user is supposed to deal with it just like the native types.

Thanks,

+2  A: 

My hint: go to the boost website and follow the instructions that answer your exact question.

Noah Roberts
@Noah Roberts Thanks! Requirements are here:https://svn.boost.org/trac/boost/wiki/Guidelines/Requirements and we are following them. Is there anything else that comes to your mind?
AraK
Be prepared to back your product with argument. You'll have both skeptics and fans.
Noah Roberts
+4  A: 

First of all you should read Boost Library Requirements and Guidelines.

Kirill V. Lyadvinsky
These are explicit requirements that we *have* to follow either way. How would you see this design decision for example: We are not providing checking for overflow just like the native types? Is that acceptable? I would like to hear some hints on this specific library from whoever did something close or have interest at least. Thanks.
AraK
I see now what are you asking about. I hope some of SO users have a such experience in that area.
Kirill V. Lyadvinsky
@AraK: for this kind of feedback, you should probably ask for a review on the Boost mailing list.
Pavel Minaev
@Arak - That's a discussion for the boost developers newsgroup. If you really want to write a boost library, that's where you need to be.
Noah Roberts
+1  A: 

Start with the motivation for such a thing. I'd be curious what applications there are. By "compile-time" I assume you mean a template meta programming solution, correct?

It sounds like a fun project, but perhaps not useful as part of boost (or perhaps useful.. you'll have to provide that important detail.)

John
@John Thanks. It is requested specifically in SoC2010, see the link in my question. The idea is simple, I will put an example of usage in the question.
AraK
+2  A: 

The idea came to me from a library called TTMath, unfortunately this library works only on specific platforms because Assembly was used extensively in the library.

Do you plan to implement full algebric operations support? (addition, multiplication, square root and so on).

If you do, also look at the CryptoPP::Integer class. It is a fully-featured, arbitrary-precision integer class supporting full arithmetic operations. It is also cross-platform.

The problem with it is that it is resigned with complex algebra in mind (for cryptographic operations) so it is much more than a generic integer class.

It also supports BER/DER and OpenPGP encoding and decoding as part of the class, along with lots of other operations that should probably not be part of a generic integer implementation.

Your hints on the whole process including design, implementation, documentation, maintainable of the library are more than welcom.

You could also look into developing an decimal class (similar to the c# decimal), similar to float/double, but not loosing precision on overflowing. The math part at least would be much simpler.

utnapistim
+6  A: 

Two additional hints:

a) Planning for a pure C++0x library seems not to be a good idea in the context of Boost. One of Boost's goals is to provide cross-platform/cross-compiler libraries. Usually Boost authors interested in using C++0x features do that as an alternative enabled when using a C++0x compiler. For that purpose Boost predefines a whole set of preprocessor macros, one for each of the C++0x features.

b) Please consider writing to the Boost devel list with your ideas, outlining the feature set of your planned library. You may ask the same questions there, btw. I'm sure you'd get a lot of useful answers and suggestions if you did.

hkaiser
Thanks. We will take your advice, and go with pure C++03.
AraK
@Arak It'd be nice if you included user-defined literal declarations. Just wrap them in the appropriate `#ifndef` (BOOST_NO_RAW_LITERALS I think)
KitsuneYMG
+2  A: 

Please implement an efficient modpow function. Similar to Java's [BigInteger.modPow][1]

RSA encryption is quite simple when you get down to it. Two primes and some regular math operators. It is trivial to implement <32 bit encryption with standard C++.

A pair of those operations can be quite CPU intensive, a power then followed by a modulo. There has been lots of research as RSA is used extensively, and those two operations can be efficiently combined. The new operation is called modpow.

So given an efficient abitrary precision iteger library with an efficient modpow, full strength RSA can be trivially implemented. A full crypto solution would also need to generate some random primes but that is a larger scope.

[1]: http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html#modPow(java.math.BigInteger, java.math.BigInteger)

caspin