How do you check for infinite and indeterminate values in C++?

前端 未结 6 2085
借酒劲吻你
借酒劲吻你 2020-12-29 20:31

In my programs infinity usually arises when a value is divided by zero. I get indeterminate when I divide zero by zero. How do you check for infinite and indeterminate value

6条回答
  •  执笔经年
    2020-12-29 21:17

    Although not strictly a part of C++03, if your compiler provides some of the new C99 features of the standard header file, then you may have access to the following "function-like macros": isfinite, isinf, isnan. If so, these would be the easiest and safest way to perform these checks.

提交回复
热议问题