C#. Whats the fastest way to make an integer positive

Posted by maxima120 on Stack Overflow See other posts from Stack Overflow or by maxima120
Published on 2010-03-22T01:09:13Z Indexed on 2010/03/22 1:11 UTC
Read the original article Hit count: 313

Filed under:
|

I asked wrong question previously and was swamped with negative votes... Let me try again...

What is absolutely fastest way to make an int positive (given 50/50 distribution of pos/neg over time).

To be nominated for an answer I will require MSIL analysis and not a guess or measuring of time with granny's watch...

P.S. as one of variations I proposed i * i not because I wanted to do Sqrt(i * i) afterwards but because i will be used only once to be compared to a const. And if i * i will win competition I simply multiply the const.. Hence the following solution is valid:

int trigger = realTrigger * realTrigger;

i = SomeCalcs();
i = i * i;
if(i < trigger)
   DoSomething();

P.P.S. pointless rant is not acceptable.. like: why do you need this, its BS! C# cannot tolerate developers like you!

© Stack Overflow or respective owner

Related posts about c#

Related posts about optimisation