128 bit signed and unsigned integer types

Chad J gamerchad at __spam.is.bad__gmail.com
Mon Dec 29 12:34:02 PST 2008


Andrei Alexandrescu wrote:
> 
> Assume we define a FixedInt(uint bits) structure. That would contain the
> value in-situ so there is no dynamic allocation, no indirection, and
> full-blown copying. For built-in sizes, FixedInt will alias itself away,
> for example:
> 
> template FixedInt(uint n) if (n == 8) { alias byte FixedInt; }
> template FixedInt(uint n) if (n == 16) { alias short FixedInt; }
> template FixedInt(uint n) if (n == 32) { alias int FixedInt; }
> template FixedInt(uint n) if (n == 64) { alias long FixedInt; }
> 
> That's nice because it allows you to use FixedInt with a parameterized
> size throughout, yet still take advantage of builtin optimizations
> whenever applicable.
> 
> For the larger sizes and operations my guess would be that FixedInt will
> be close to what can be achieved via built-ins.
> 
> 
> Andrei

Cool, but don't name it FixedInt unless it implements fixed point
arithmetic.

This name immediately suggests to me that it implements fixed point
arithmetic using an integer of the given size, but then I'd be confused
since I don't know how many bits are allocated to the fractional part.

Maybe just Int.  Less typing.  Makes the point.  The template
instantiation is a huge giveaway as to what is happening.
Int!(64) == long
UInt!(64) == ulong
Int!(8) == byte
etc..
that would be "kicking rad".



More information about the Digitalmars-d mailing list