How to generate NaN, -Infinity and +Infinity in ANSI C?

后端 未结 4 1849
南方客
南方客 2020-12-05 03:53

I use ANSI C89 (not C++), and I want to generate NaN, -Infinity and +Infinity.

Is there any standard way (eg. standard macro)?

4条回答
  •  伪装坚强ぢ
    2020-12-05 04:51

    There is in C99, but not in previous standards AFAIK.

    In C99, you'll have NAN and INFINITY macros.

    From "Mathematics " (§7.12) section

    The macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; ...

    If you're stuck with ANSI C89, you're out of luck. See C-FAQ 14.9.

提交回复
热议问题