C++ fdim()

Last Updated On Friday 15th Apr 2022

The C++ fdim() function returns the positive difference between first and second argument and it takes a two arguments.

Syntax

	fdim(double x, double y)



Parameters

The fdim() function take two parameters of either floating-point or integral type.

• x – first argument
• y – second argument

Return value

Returns,

• x-y if x > y
•  0 if x ≤ y

fdim() prototype [As of C++ 11 standard]

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



Example : C++ fdim()

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

int main () {
printf ("fdim (4.0, 2.0) = %f\n", fdim(4.0,2.0));
printf ("fdim (2.0, 4.0) = %f\n", fdim(2.0,4.0));
printf ("fdim (-4.0, -2.0) = %f\n", fdim(-4.0,-2.0));
printf ("fdim (-2.0, -4.0) = %f\n", fdim(-2.0,-4.0));
return 0;
}



Output

	fdim (4.0, 2.0) = 2.000000
fdim (2.0, 4.0) = 0.000000
fdim (-4.0, -2.0) = 0.000000
fdim (-2.0, -4.0) = 2.000000