Page 1 of 1

challenge for infinitely sized integer in C++

Posted: Wed Sep 12, 2007 8:01 pm
by AndrewAPrice
I challenge someone to make a class in C++ that can hold any specified-sized variable like:

var<bool float, int size>

Therefore an int would be:
var<false,32>

A short would be:
var<false,16>

A float would be:
var<true,16>

Although this isn't useful for standard sizes (16,32,64-bit) but when dealing with odd sizes like 96-bit and even 2048-bit+ numbers.

Posted: Wed Sep 12, 2007 9:02 pm
by Zacariaz
even i can wrap something up which can hold "infiniti" sized intefers. The deficult part is putting the value in, and getting it out again.
fx.
std::bitset<somenumber> B
and then set all the bits manually ;)

Posted: Thu Sep 13, 2007 12:12 am
by jnc100
Gmp has a c++ interface.

Regards,
John.