fdim - C math.h

C examples for math.h:fdim

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the positive difference between x and y. The function returns x-y if x>y, and zero otherwise.

Prototype

long double fdiml (long double x, long double y);
long double fdim (long double x, long double y);
     double fdim  (double x     , double y);
      float fdimf (float x      , float y);
      float fdim (float x      , float y);
     double fdim (Type1 x      , Type2 y);       

Parameters

Parameter Description
x Values whose difference is calculated.
y Values whose difference is calculated.

Return Value

The positive difference between x and y.

Example

Demo Code


#include <stdio.h>
#include <math.h> /* fdim */

int main ()//from  w  w w. j  av  a2 s .  c  o m
{
  printf ("%f\n", fdim(2.0,1.0));
  printf ("%f\n", fdim(1.0,1.0));  
  printf ("%f\n", fdim(1.0,2.0));
  printf ("%f\n", fdim(-2.0,-1.0));
  printf ("%f\n", fdim(-1.0,-2.0));
  return 0;
}

Related Tutorials