In C, fmaximum_mag_num() looks at two double values and returns the one with the larger magnitude (size). Sign does not decide the winner — only how far from zero matters. fmaximum_mag_num(-9.0, 3.0) returns -9.0 because 9 is bigger than 3.
If one argument is a quiet NaN and the other is a real number, you get the number back. You get NaN only when both are NaN. This is a C23-style helper in <math.h>. An older compiler or library may not provide it yet — you may need a newer C library.
Syntax
Pass two floating-point numbers. Start with this call.
C
fmaximum_mag_num(-9.0, 3.0);
Call
What it does
fmaximum_mag_num(-9.0, 3.0)
Larger magnitude is 9, so returns -9.0.
fmaximum_mag_num(2.0, NAN)
Prefers the number and returns 2.0.
Include <math.h>. On GCC, link with -lm. Needs a C23-capable math library. Compare magnitudes with fmaximum_mag() if you want NaN when either input is NaN.
Library declarations
C
double fmaximum_mag_num(double x, double y);
float fmaximum_mag_numf(float x, float y);
long double fmaximum_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 whose absolute value is larger. If one is NaN, returns the other number. NaN only if both are NaN.
C Examples
Example 1 — Larger Magnitude Wins
Ignore the sign. Pick the value farther from zero.