fastest way to negate a number

后端 未结 7 1586
南旧
南旧 2020-12-29 03:20

I was thinking this morning here, what would be the fastest way to reverse a number of positive to negative and from negative to positive, of course, the simplest way might

7条回答
  •  别那么骄傲
    2020-12-29 03:45

    Use something that is readable, such as

    a *= -1;
    

    or

    a = -a;
    

    Leave the rest to the optimizer.

提交回复
热议问题