Name

fdim

Synopsis

Obtains the positive difference between two numbers

#include <math.h>
doublefdim( double x, double y );
float fdimf( float x, float y );
long double fdiml( long double x, long double y );

The fdim() function return xy or 0, whichever is greater. If the implementation has signed zero values, the zero returned by fdim() is positive.

Example

/* Make sure an argument is within the domain of asin() */

double sign, argument, result;
/* ... */

sign = copysign( 1.0, argument );      // Save the sign ...
argument = copysign( argument, 1.0 );  // ... then use only positive values
argument = 1.0 −fdim( 1.0, argument );     // Trim excess beyond 1.0
result = asin( copysign(argument, sign) );  // Restore sign and call asin()

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.