Namespaces
Variants

INFINITY

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
INFINITY DEC_INFINITY
(C99) (C23)
(C99) (C23)
Arguments and return values
Error handling
Fast operation indicators
定义于头文件 <math.h>
#define INFINITY /*由实现定义*/
(C99 起)

如果实现支持浮点无穷大,宏 INFINITY 将展开为类型 float 的常量表达式,其值为正无穷或无符号无穷。

如果实现不支持浮点无穷大,宏 INFINITY 将扩展为一个保证在编译时使 float 类型溢出的正值,且使用该宏会产生编译器警告。

用于打印无穷大的样式由实现定义。

示例

显示用于打印无穷大和IEEE格式的样式。

#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
int main(void)
{
    double f = INFINITY;
    uint64_t fn; memcpy(&fn, &f, sizeof f);
    printf("INFINITY:   %f %" PRIx64 "\n", f, fn);
}

可能的输出:

INFINITY:   inf 7ff0000000000000

参考文献

  • C11 标准 (ISO/IEC 9899:2011):
  • 7.12/4 INFINITY (页: 231-232)
  • C99 标准 (ISO/IEC 9899:1999):
  • 7.12/4 INFINITY (页: 212-213)

参阅

(C99)
检查给定数字是否为无穷大
(函数宏)
分别表示 float double long double 无法表示的过大值(无穷大)
(宏常量)
C++ 文档 关于 INFINITY