www.digitalmars.com         C & C++   DMDScript  

D - larger fixed integers

What about an integer type that contains an integer of any number of bytes, 1
through N, where N is at least 1024?  This would allow a lot of computations to
be done for cryptography, for example.  I'm not talking about an variable sized
number, the size would be known at compile time.  One syntax might be to use an
integer template: integer!(4) and uinteger!(4).

For sizes 1,2,4,8, the type would be equivalent to existing integers.  For any
size that has hardware support the value could be done in hardware; otherwise
fall back to a simple "numerical recipe" for multiplication, division, etc.

For template programming, this would be especially useful; it would allow
someone to use .sizeof on a type and get a corresponding unsigned type:

template TFoo(T)
bar(T v)
{
uinteger!(T.size) v2 = v;
..
}

Often there are libraries that have functions like this:

SwapInt2();
SwapInt4();
SwapInt8();
SwapUint2();
SwapUint4();
SwapUint8();

If the basic types were accessible via the integer!(#) syntax, these could all
collapse to two functions: signed and unsigned, with compile time instantiation
of different sizes.

Kevin Bealer
Apr 28 2004