Am 17.08.2013 11:20, schrieb Orchid Win7 v1:
> int abs(int input)
> {
...
> (My boss has a standard set of ways to implement abs(). They include:
>
> * if (x < 0) return 0-x; else return x;
>
> * return sqrt(x*x); // Evil.
>
> * return str.Remove('-'); // String munging. Very evil!
>
> * if (x < 0) return x ^ 0x8000; else return x; // DOESN'T ACTUALLY WORK!
>
> I'm sure there must be more evil ways of doing this...)
He should also be prepared for
return Math.Abs(input);
possibly with an added comment to the effect that the abs(int) function
should be refactored away at the earliest possible opportunity ;-)
Post a reply to this message
|