Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      fmax, fmaxf, fmaxl

      From cppreference.com
      <c‎ |numeric‎ |math
       
       
       
      Common mathematical functions
      Functions
      Basic operations
      (C99)
      (C99)
      (C99)
      (C99)(C99)(C99)(C23)
      Maximum/minimum operations
      fmax
      (C99)
      (C99)
      Exponential functions
      (C23)
      (C99)
      (C99)
      (C23)
      (C23)

      (C99)
      (C99)(C23)
      (C23)
      (C23)
      Power functions
      (C99)
      (C23)
      (C23)

      (C99)
      (C23)
      (C23)
      Trigonometric and hyperbolic functions
      (C23)
      (C23)
      (C23)
      (C23)
      (C99)
      (C99)
      (C99)
      Nearest integer floating-point
      (C99)(C99)(C99)
      (C23)(C23)(C23)(C23)
      Floating-point manipulation
      (C99)(C99)
      (C99)(C23)
      (C99)
      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
      (C99)(C23)
      Arguments and return values
      Error handling
      Fast operation indicators
       
      Defined in header<math.h>
      float       fmaxf(float x,float y);
      (1)(since C99)
      double      fmax(double x,double y);
      (2)(since C99)
      longdouble fmaxl(longdouble x,longdouble y);
      (3)(since C99)
      Defined in header<tgmath.h>
      #define fmax( x, y )
      (4)(since C99)
      1-3) Returns the larger of two floating-point arguments, treating NaNs as missing data (between a NaN and a numeric value, the numeric value is chosen).
      4) Type-generic macro: If any argument has typelongdouble,fmaxl is called. Otherwise, if any argument has integer type or has typedouble,fmax is called. Otherwise,fmaxf is called.

      Contents

      [edit]Parameters

      x, y - floating-point values

      [edit]Return value

      If successful, returns the larger of two floating-point values. The value returned is exact and does not depend on any rounding modes.

      [edit]Error handling

      This function is not subject to any of the error conditions specified inmath_errhandling.

      If the implementation supports IEEE floating-point arithmetic (IEC 60559),

      • If one of the two arguments is NaN, the value of the other argument is returned.
      • Only if both arguments are NaN is NaN returned.

      [edit]Notes

      This function is not required to be sensitive to the sign of zero, although some implementations additionally enforce that if one argument is +0 and the other is -0, then +0 is returned.

      [edit]Example

      Run this code
      #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));}

      Output:

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

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.12.12.2 The fmax functions (p: TBD)
      • 7.25 Type-generic math <tgmath.h> (p: TBD)
      • F.10.9.2 The fmax functions (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.12.12.2 The fmax functions (p: 188)
      • 7.25 Type-generic math <tgmath.h> (p: 397)
      • F.10.9.2 The fmax functions (p: 386)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.12.12.2 The fmax functions (p: 257-258)
      • 7.25 Type-generic math <tgmath.h> (p: 373-375)
      • F.10.9.2 The fmax functions (p: 530)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.12.12.2 The fmax functions (p: 238-239)
      • 7.22 Type-generic math <tgmath.h> (p: 335-337)
      • F.9.9.2 The fmax functions (p: 466)

      [edit]See also

      checks if the first floating-point argument is greater than the second
      (function macro)[edit]
      (C99)(C99)(C99)
      determines smaller of two floating-point values
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/math/fmax&oldid=172015"

      [8]ページ先頭

      ©2009-2025 Movatter.jp