Rate This Document
Findability
Accuracy
Completeness
Readability

fmax

Return the maximum value of the input parameters.

Interface Definition

C interface:

float fmaxf(float x, float y);

double fmax(double x, double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For fmaxf, x is of single-precision floating-point type.
  • For fmax, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For fmaxf, y is of single-precision floating-point type.
  • For fmax, y is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The larger value between x and y is returned.
  • For special values, see the following table.

Input Value (x)

Input Value (y)

Return Value

any

qnan

x

qnan

any

y

any

snan

nan

snan

any

nan

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 1.4, x4 = -2.7;
    double y1 = -0.0, y2 = 0.0, y3 = 1.5, y4 = -2.1;
    // special handing
    double a = INFINITY, b = -INFINITY, c = NAN;
    printf("fmax(0.0, -0.0) = %.15f\n", fmax(x1, y1));
    printf("fmax(-0.0, 0.0) = %.15f\n", fmax(x2, y2));
    printf("fmax(1.4, 1.5) = %.15f\n", fmax(x3, y3));
    printf("fmax(-2.7, -2.1) = %.15f\n", fmax(x4, y4));
    printf("fmax(INFINITY, 1.4) = %.15f\n", fmax(a, x3));
    printf("fmax(-INFINITY, -2.7) = %.15f\n", fmax(b, x4));
    printf("fmax(NAN, 1.4) = %.15f\n", fmax(c, x3));
    printf("fmax(NAN, INFINITY) = %.15f\n", fmax(c, a));
    printf("fmax(NAN, -INFINITY) = %.15f\n", fmax(c, b));
    printf("fmax(INFINITY, -INFINITY) = %.15f\n", fmax(a, b));
    /* 
     * fmax(0.0, -0.0) = 0.000000000000000
     * fmax(-0.0, 0.0) = 0.000000000000000
     * fmax(1.4, 1.5) = 1.500000000000000
     * fmax(-2.7, -2.1) = -2.100000000000000
     * fmax(INFINITY, 1.4) = inf
     * fmax(-INFINITY, -2.7) = -2.700000000000000
     * fmax(NAN, 1.4) = 1.400000000000000
     * fmax(NAN, INFINITY) = inf
     * fmax(NAN, -INFINITY) = -inf
     * fmax(INFINITY, -INFINITY) = inf
     * */