"It's an academic problem. Don't worry about it and move on."
That's what Walter kept on telling me. Yet I've spent the better part of
an hour reducing a bug down to the following:
import std.math, std.stdio;
void main() {
auto a = [ 4, 4, 2, 3, 2 ];
float avgdist = 0;
uint count;
Andrei Alexandrescu:
>May this post be an innocent victim of the war against unsigned-related bugs.<
Unsigned numbers are evil (especially if you use them in a language with no
integral overflow tests).
A partial solution to this problem is:
1) to use them in a program only where you really need
And abs() of an unsigned number probably needs a compilation warning.
Bye,
bearophile
bearophile wrote:
And abs() of an unsigned number probably needs a compilation warning.
Not a warning, it's always an error.
Don wrote:
bearophile wrote:
And abs() of an unsigned number probably needs a compilation warning.
Not a warning, it's always an error.
Ok, makes sense. I'll operate the change in Phobos.
Andrei
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.
--
Rainer Deyke - rain...@eldwood.com
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.
Andrei Alexandrescu wrote:
> 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
Rainer Deyke wrote:
Andrei Alexandrescu wrote:
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 ab