"Unsigned-related bugs never occur in real code."

2010-01-20 Thread Andrei Alexandrescu
"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;

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread bearophile
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

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread bearophile
And abs() of an unsigned number probably needs a compilation warning. Bye, bearophile

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread Don
bearophile wrote: And abs() of an unsigned number probably needs a compilation warning. Not a warning, it's always an error.

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread Andrei Alexandrescu
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

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread Rainer Deyke
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

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread Andrei Alexandrescu
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.

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread Rainer Deyke
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

Re: "Unsigned-related bugs never occur in real code."

2010-01-21 Thread Andrei Alexandrescu
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