函式
<cmath> <ctgmath>

fmax

     double fmax  (double x     , double y);      float fmaxf (float x      , float y);long double fmaxl (long double x, long double y);
     double fmax (double x     , double y);      float fmax (float x      , float y);long double fmax (long double x, long double y);     double fmax (Type1 x      , Type2 y);       // additional overloads
最大值
返回其引數中較大的一個:xy

如果其中一個引數是 NaN,則返回另一個引數。

標頭檔案 <tgmath.h> 提供了此函式的型別通用宏版本。
此標頭檔案 (<cmath>) 中為其他算術型別 (Type1Type2) 的組合提供了額外的過載:這些過載在計算前會有效地將其引數轉換為 double,除非至少有一個引數的型別是 long double(在這種情況下,兩個引數都會被轉換為 long double)。

引數

x, y
函式從中選擇最大值的數值。

返回值

其引數中的最大數值。

示例

1
2
3
4
5
6
7
8
9
10
11
/* fmax example */
#include <stdio.h>      /* printf */
#include <math.h>       /* fmax */

int main ()
{
  printf ("fmax (100.0, 1.0) = %f\n", fmax(100.0,1.0));
  printf ("fmax (-100.0, 1.0) = %f\n", fmax(-100.0,1.0));
  printf ("fmax (-100.0, -1.0) = %f\n", fmax(-100.0,-1.0));
  return 0;
}

輸出

fmax (100.0, 1.0) = 100.000000
fmax (-100.0, 1.0) = 1.000000
fmax (-100.0,-1.0) = -1.000000


另見