|
|
On 17/08/2013 08:15 PM, Samuel Benge wrote:
> Orchid Win7 v1<voi### [at] devnull> wrote:
>> I'm sure there must be more evil ways of doing this...)
>
> Here's one (probably not the best) way to do it:
>
> return x*(1-2*(x<0));
>
> Not sure how C# handles types, but in C that would return an int.
Well, I mean, the "obvious" way is
if (x<0) return -x; else return x;
But you can phrase that as
return x ? x : -x;
if you prefer.
> Thanks for the laughs, btw :) When Haskell isn't the main subject, you're
> actually pretty funny ;)
If you wanted to find crazy ways to do this in Haskell, you would have
some pretty scary options available... ;-)
Post a reply to this message
|
|