Rate This Document
Findability
Accuracy
Completeness
Readability

fdim

Return zero if x is smaller than or equal to y, or return a value of x - y if x is greater than y.

Interface Definition

C interface:

float fdimf(float x, float y);

double fdim(double x, double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For fdimf, x is of single-precision floating-point type.
  • For fdim, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For fdimf, y is of single-precision floating-point type.
  • For fdim, y is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • errno: If the return value is inf, it is set to ERANGE.
  • If x < y, the return value is 0.
  • If xy, the return value is x - y.
  • If x or y is NaN, the return value is NaN.

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    printf("fdim(1.0, 2.0) = %.15f\n", fdim(1.0, 2.0));
    printf("fdim(3.0, 2.0) = %.15f\n", fdim(3.0, 2.0));
    // special handing
    printf("fdim(INFINITY, INFINITY) = %.15f\n", fdim(INFINITY, INFINITY));
    printf("fdim(INFINITY, -INFINITY) = %.15f\n", fdim(INFINITY, -INFINITY));
    printf("fdim(-INFINITY, INFINITY) = %.15f\n", fdim(-INFINITY, INFINITY));
    printf("fdim(-INFINITY, -INFINITY) = %.15f\n", fdim(-INFINITY, -INFINITY));
    printf("fdim(NAN, -INFINITY) = %.15f\n", fdim(NAN, -INFINITY));

 result
   /* 
    * fdim(1.0, 2.0) = 0.000000000000000
    * fdim(3.0, 2.0) = 1.000000000000000
    * fdim(INFINITY, INFINITY) = 0.000000000000000
    * fdim(INFINITY, -INFINITY) = inf
    * fdim(-INFINITY, INFINITY) = 0.000000000000000
    * fdim(-INFINITY, -INFINITY) = 0.000000000000000
    * fdim(NAN, -INFINITY) = nan
    * */