In C, fminimum_mag() returns the argument with the smaller magnitude. Sign is ignored for the comparison. fminimum_mag(-9.0, 3.0) returns 3.0 because 3 is closer to zero than 9.
If either argument is NaN, the result is NaN. This is a C23-style function in <math.h>. An older compiler or math library may not have it — you may need a newer C library.
Syntax
Pass two floating-point numbers. Start with this call.
C
fminimum_mag(-9.0, 3.0);
Call
What it does
fminimum_mag(-9.0, 3.0)
Smaller magnitude is 3, so returns 3.0.
fminimum_mag(2.0, NAN)
Returns NaN because one argument is NaN.
Include <math.h>. On GCC, link with -lm. Needs C23 support. Use fminimum_mag_num() if you want to keep a number when the other side is NaN.
Library declarations
C
double fminimum_mag(double x, double y);
float fminimum_magf(float x, float y);
long double fminimum_magl(long double x, long double y);
Parameters
Parameter
Description
x
Required. First floating-point value.
y
Required. Second floating-point value.
Return Value
Return Value
Description
double
The argument with smaller absolute value, or NaN if either argument is NaN.