Namespaces
Variants

fmin, fminf, fminl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
(C99)
fmin
(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 fminf ( float x, float y ) ;
(1) (C99 起)
double fmin ( double x, double y ) ;
(2) (C99 起)
long double fminl ( long double x, long double y ) ;
(3) (C99 起)
定义于头文件 <tgmath.h>
#define fmin( x, y )
(4) (C99 起)
1-3) 返回两个浮点参数中的较小值,将 NaN 视为缺失数据(在 NaN 与数值之间,选择数值)。
4) 类型泛型宏:若任一参数类型为 long double ,则调用 fminl 。否则,若任一参数具有整数类型或类型为 double ,则调用 fmin 。否则调用 fminf

目录

参数

x, y - 浮点数值

返回值

如果成功,返回两个浮点值中的较小值。返回值是精确的,且不依赖于任何舍入模式。

错误处理

此函数不受 math_errhandling 中指定的任何错误条件影响。

如果实现支持 IEEE 浮点算术 (IEC 60559),

  • 如果两个参数中有一个是 NaN,则返回另一个参数的值
  • 仅当两个参数都是 NaN 时,才返回 NaN

注释

此函数无需对零的符号敏感,但某些实现会额外规定:若一个参数为+0而另一个为-0,则返回-0。

示例

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

可能的输出:

fmin(2,1)    = 1.000000
fmin(-Inf,0) = -inf
fmin(NaN,-1) = -1.000000

参考文献

  • C23 标准 (ISO/IEC 9899:2024):
  • 7.12.12.3 fmin 函数集 (p: TBD)
  • 7.25 泛型数学 <tgmath.h> (p: TBD)
  • F.10.9.3 fmin 函数集 (p: TBD)
  • C17 标准 (ISO/IEC 9899:2018):
  • 7.12.12.3 fmin 函数集 (p: TBD)
  • 7.25 类型泛型数学 <tgmath.h> (p: TBD)
  • F.10.9.3 fmin 函数集 (p: TBD)
  • C11 标准 (ISO/IEC 9899:2011):
  • 7.12.12.3 fmin 函数 (p: 258)
  • 7.25 类型泛型数学 <tgmath.h> (p: 373-375)
  • F.10.9.3 fmin 函数 (p: 530)
  • C99标准(ISO/IEC 9899:1999):
  • 7.12.12.3 fmin函数 (p: 239)
  • 7.22 泛型数学 <tgmath.h> (p: 335-337)
  • F.9.9.3 fmin函数 (p: 466)

参考

(C99)
检查第一个浮点参数是否小于第二个
(函数宏)
(C99) (C99) (C99)
确定两个浮点值的较大者
(函数)