How would you set a variable to the largest number possible in C?

前端 未结 10 630
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 17:53

How would you set a variable to equal infinity (or any guaranteed largest number value) in C?

10条回答
  •  粉色の甜心
    2020-12-01 18:42

    Normally this is done by 1.0/0.0, but you may get a compile warning on that. I am not aware of other portable ways of doing it in C89, but C99 has macro FP_INFINITE in math.h.

    EDIT: Apparently Sam didn't actually want infinity, but integer limits, which can be found in limits.h like others have stated.

提交回复
热议问题