Previous Page
Next Page

copysign

Makes the sign of a number match that of another number

#include <math.h>
double copysign ( double x , double y  );
float copysignf ( float x , float y  );
long double copysignl ( long double x , long double y  );

The copysign( ) function returns a value with the magnitude of its first argument and the sign of its second argument.

Example

/* Test for signed zero values */
double x = copysign(0.0, -1.0);
double y = copysign(0.0, +1.0);

  printf( "x is %+.1f; y is %+.1f.\n", x, y);
  printf( "%+.1f is %sequal to %+.1f.\n", x, ( x == y ) ? "" : "not " , y )

This code produces the following output:

x is -0.0; y is +0.0.
-0.0 is equal to +0.0.

See Also

abs( ), fabs( ), fdim( ), fmax( ), fmin( )


Previous Page
Next Page