Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

fmin — C23 mathematical function

`fmin(x, y)` from `<math.h>` returns the lesser numeric value of two `double` arguments; `fminf` and `fminl` serve the other types. If exactly one argument is NaN, the numeric argument is returned.

Version: C23

Syntax

double fmin(double x, double y);

fmin(x, y) from <math.h> returns the lesser numeric value of two double arguments; fminf and fminl serve the other types. If exactly one argument is NaN, the numeric argument is returned.

The example evaluates fmin(-3.0, 2.0), fmin(NAN, 5.0), and the sign of fmin(-0.0, +0.0). Output -3 5 1 shows the minimum, suppression of one NaN, and the negative zero required by Annex F.

Two NaN arguments produce NaN. x < y ? x : y is not a complete substitute because NaNs, signed zeros, and expression evaluation differ. The function reports no range error; qualify the exact zero-sign choice as an Annex F requirement.

Examples

#include <math.h>
#include <stdio.h>
int main(void) { volatile double nz=-0.0, pz=0.0; printf("%.0f %.0f %d\n", fmin(-3.0,2.0), fmin(NAN,5.0), signbit(fmin(nz,pz)) != 0); return 0; }

Result

-3 5 1

The example evaluates `fmin(-3.0, 2.0)`, `fmin(NAN, 5.0)`, and the sign of `fmin(-0.0, +0.0)`. Output `-3 5 1` shows the minimum, suppression of one NaN, and the negative zero required by Annex F.

Sources