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 /*implementation defined*/
(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 (p: 231-232)
  • C99標準 (ISO/IEC 9899:1999):
  • 7.12/4 INFINITY (p: 212-213)

関連項目

(C99)
指定された数値が無限大かどうかをチェックする
(関数マクロ)
float double および long double で表現不可能な(無限大の)値を示す
(マクロ定数)