In C, fminimum_mag_num() returns the argument with the smaller magnitude. fminimum_mag_num(-9.0, 3.0) returns 3.0. Only absolute size decides the winner.
If one argument is NaN and the other is a number, you get the number. NaN appears only when both are NaN. This is C23-style math in <math.h> — a newer C library may be required.
Syntax
Pass two floating-point numbers. Start with this call.
C
fminimum_mag_num(-9.0, 3.0);
Call
What it does
fminimum_mag_num(-9.0, 3.0)
Smaller magnitude is 3, so returns 3.0.
fminimum_mag_num(NAN, -1.5)
Prefers the number and returns -1.5.
Include <math.h>. On GCC, link with -lm. Needs C23 support. Stricter sibling: fminimum_mag() returns NaN if either input is NaN.
Library declarations
C
double fminimum_mag_num(double x, double y);
float fminimum_mag_numf(float x, float y);
long double fminimum_mag_numl(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. If one is NaN, returns the other number. NaN only if both are NaN.