C fmaximum_mag() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

Definition

In C, fmaximum_mag() returns the argument with the larger magnitude. fmaximum_mag(-5.0, 3.0) is -5.0 because 5 > 3 in size. It is a C23 / newer library API.

You pass two double values. The result is a double that keeps its original sign. Include <math.h>. On GCC, link with -lm and enable a C23 mode when needed. The page slug is fmaximum-mag; the C name uses an underscore.

Syntax

Pass both values. Start with this call.

C
fmaximum_mag(-5.0, 3.0);
CallWhat it does
fmaximum_mag(-5.0, 3.0)Returns -5.0 because |-5| is larger than |3|.
fmaximum_mag(2.0, -2.0)Magnitudes are equal; the maximum of the two values is returned (+2.0).

Include <math.h>. On GCC, link with -lm. Spell the C function fmaximum_mag with an underscore. The tutorial URL uses hyphens: /c/math/function/fmaximum-mag.

Library declarations
C
double fmaximum_mag(double x, double y);
float fmaximum_magf(float x, float y);
long double fmaximum_magl(long double x, long double y);

Parameters

ParameterDescription
xRequired. First value. Compared by absolute size.
yRequired. Second value. Compared by absolute size.

Return Value

Return ValueDescription
doubleThe argument with larger |value|. Equal magnitudes return the maximum of the two values. NaN propagates.

C Examples

Example 1 — Basic Magnitude Maximum

Pick the value whose absolute size is larger.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%.1f\n", fmaximum_mag(-5.0, 3.0));
    printf("%.1f\n", fmaximum_mag(1.5, -4.0));
    return 0;
}

How It Works

  1. Include math.h. Needs C23 support for this name.
  2. First call. |-5| wins, so −5 is returned.
  3. Second call. |-4| wins, so −4 is returned.
  4. Sign is kept. Magnitude chooses; sign stays with the winner.

Example 2 — Equal Magnitudes

When |x| equals |y|, the maximum of the two signed values is returned.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    printf("%.1f\n", fmaximum_mag(2.0, -2.0));
    printf("%.1f\n", fmaximum_mag(-2.0, 2.0));
    return 0;
}

How It Works

  1. Same size. Both sides have magnitude 2.
  2. Tie break. Use the maximum of the signed values.
  3. Positive wins the tie. Result is +2.0 either order.
  4. Not fabs. You still get a signed result, not always positive.

Example 3 — Compare with fmaximum

Signed maximum and magnitude maximum can disagree.

C
#include <stdio.h>
#include <math.h>

int main(void) {
    double x = -8.0;
    double y = 3.0;

    printf("fmaximum     = %.1f\n", fmaximum(x, y));
    printf("fmaximum_mag = %.1f\n", fmaximum_mag(x, y));
    return 0;
}

How It Works

  1. Pick mixed signs. −8 and 3.
  2. Signed max. fmaximum picks 3.
  3. Magnitude max. fmaximum_mag picks −8.
  4. Choose the API. Depends on whether size or signed order matters.

Frequently Asked Questions

fmaximum_mag() returns the argument with the larger magnitude. It is a C23 / newer library API.
C identifiers use underscores. This site uses hyphenated URL slugs. Call fmaximum_mag() in code.
The value with larger absolute size. Equal magnitudes return the maximum of the two values. NaN propagates.
Include <math.h>. On GCC, link with -lm and use a C23 mode when needed.
fmaximum compares signed values. fmaximum_mag compares magnitudes, then keeps the winning value's sign.

Next: fmaximum_num()

C23 magnitude maximum with numeric NaN preference.

fmaximum_num() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful