Fastest way to check if two integers are on the same side of 0

后端 未结 6 1651
后悔当初
后悔当初 2021-02-02 10:02

I need to check if two integers are on the same side of zero many times. I don\'t care if it\'s positive or negative, just that it\'s the same side... and performance is very im

6条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 10:28

    I would bitcast them to unsigned int, and xor the MSB (most-significant-bit) - much faster than any comparison (which does a subtraction) or multiplication

提交回复
热议问题