Let Go, Standard Library From Community

Derek Parnell derek at psych.ward
Wed Apr 18 15:15:49 PDT 2007


On Wed, 18 Apr 2007 15:09:12 -0400, Dan wrote:

> I went through tango.core.Array and tango.math.Math and personally found
> several rather junior mistakes like:
> 
> int abs(int x){
>   return x > 0? x : -x;
>  // should be: return x &= 0x7FFF_FFFF;
> }

I disagree strongly with your "improvement" on the grounds that it assumes
a particular implementation of signed integers. The compiler knows better.

If I was to suggest any change it would be 

  return x >= 0 ? x : -x;

because that way if zero is supplied, it won't try to evaluate -zero.

-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell



More information about the Digitalmars-d mailing list