symmetric signed types

Dominikus Dittes Scherkl Dominikus.Scherkl at continental-corporation.com
Thu Jan 23 04:09:23 PST 2014


There is one mistake in C that D proliverates:

The T.min value of signed types.

e.g.

byte a = -128;
auto b = -a;

What type should b get? (of course "byte" but the value doesn't 
fit!)

Also getting the absolute value of some signed variable
need to return a different type or doesn't work correct for all 
input.
E.g. "ubyte abs(byte)" - this functions which can't even use a 
template,
or has anybody a good idea ho to express "unsigned T abs(T)(T x)"?

So I thought I could design a new type "sbyte" with symmetric 
range
(-127..127) and an additional value NaN (yes, the old 0x80).
(and of course larger, similar types - by the way: why wasn't 
"short"
instead called "word"? Then my new type would be "sword" :-)

It worked all well until I found that the new operators !<> !<= 
etc
can't be overloaded (they are only available for floating types)!
Why is this so?

D made all the floatingpoint stuff so much better than C, but the 
integral types still suffer the same old flaws.


More information about the Digitalmars-d mailing list