Rainer Deyke wrote:
Don wrote:
bearophile wrote:
And abs() of an unsigned number probably needs a compilation warning.
Not a warning, it's always an error.
I can imagine abs(x) being useful in a generic function where x can be
either signed or unsigned.
std.traits has a Unsigned template. I plan to add two functions:
signed(x) and unsigned(x), which transform the integral x into the
signed/unsigned integral of the same size. Generic code could then call
signed or unsigned wherever necessary. For abs, they'd have to call
abs(signed(expr)) which I believe clarifies intent and averts bugs like
mine.
Alas, that's not fixing everything...
Andrei