How to portably find out min(INT_MAX, abs(INT_MIN))?

前端 未结 6 1366
感情败类
感情败类 2020-12-11 00:10

How can I portably find out the smallest of INT_MAX and abs(INT_MIN)? (That\'s the mathematical absolute value of INT_MIN, not a call

6条回答
  •  借酒劲吻你
    2020-12-11 00:32

    -INT_MAX is representable as an int in all C and C++ dialects, as far as I know. Therefore:

    -INT_MAX <= INT_MIN ? -INT_MIN : INT_MAX
    

提交回复
热议问题