Namespaces
Variants

fmax, fmaxf, fmaxl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
fmax
(C99)
(C99)
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
Arguments and return values
Error handling
Fast operation indicators
定義済みヘッダー <math.h>
float fmaxf ( float x, float y ) ;
(1) (C99以降)
double fmax ( double x, double y ) ;
(2) (C99以降)
long double fmaxl ( long double x, long double y ) ;
(3) (C99以降)
定義済みヘッダー <tgmath.h>
#define fmax( x, y )
(4) (C99以降)
1-3) 2つの浮動小数点引数のうち大きい方を返します。NaNは欠損データとして扱われ(NaNと数値の間では数値が選択されます)。
4) 型総称マクロ: いずれかの引数が型 long double を持つ場合、 fmaxl が呼び出される。それ以外の場合、いずれかの引数が整数型または型 double を持つ場合、 fmax が呼び出される。それ以外の場合、 fmaxf が呼び出される。

目次

パラメータ

x, y - 浮動小数点値

戻り値

成功した場合、2つの浮動小数点値のうち大きい方を返します。返される値は正確であり、どの丸めモードにも依存しません。

エラーハンドリング

この関数は、 math_errhandling で指定されているいかなるエラー条件の対象にもなりません。

IEEE浮動小数点演算(IEC 60559)を実装がサポートしている場合、

  • 2つの引数のうち1つがNaNの場合、もう一方の引数の値が返されます。
  • 両方の引数がNaNの場合のみ、NaNが返されます。

注記

この関数はゼロの符号に対して敏感である必要はありませんが、一部の実装では追加で、一方の引数が+0で他方が-0の場合、+0が返されることを強制します。

#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("fmax(2,1)    = %f\n", fmax(2,1));
    printf("fmax(-Inf,0) = %f\n", fmax(-INFINITY,0));
    printf("fmax(NaN,-1) = %f\n", fmax(NAN,-1));
}

出力:

fmax(2,1)    = 2.000000
fmax(-Inf,0) = 0.000000
fmax(NaN,-1) = -1.000000

参考文献

  • C23規格 (ISO/IEC 9899:2024):
  • 7.12.12.2 fmax関数群 (p: TBD)
  • 7.25 総称数学 <tgmath.h> (p: TBD)
  • F.10.9.2 fmax関数群 (p: TBD)
  • C17規格 (ISO/IEC 9899:2018):
  • 7.12.12.2 fmax関数群 (p: 188)
  • 7.25 総称数学 <tgmath.h> (p: 397)
  • F.10.9.2 fmax関数群 (p: 386)
  • C11規格 (ISO/IEC 9899:2011):
  • 7.12.12.2 fmax関数群 (p: 257-258)
  • 7.25 総称数学 <tgmath.h> (p: 373-375)
  • F.10.9.2 fmax関数群 (p: 530)
  • C99規格 (ISO/IEC 9899:1999):
  • 7.12.12.2 fmax関数群 (p: 238-239)
  • 7.22 総称型数学 <tgmath.h> (p: 335-337)
  • F.9.9.2 fmax関数群 (p: 466)

関連項目

第1浮動小数点引数が第2引数より大きいかどうかをチェックする
(関数マクロ)
(C99) (C99) (C99)
2つの浮動小数点値のうち小さい方を決定する
(関数)