copysign Function

Returns the value of x but with the sign of y.

Include

<math.h>

Prototype

double copysign(double x, double y);

Arguments

x
a double precision floating-point value
y
value whose sign will apply to the result

Return Value

Returns the value of x but with the sign of y.

Example

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

int main(void)
{
  double x,y,z;

  x = 10.0;
  y = -3.0;
  z = copysign(x, y);
  printf("The value %f but with %f's sign is %f\n\n", x, y, z);
}

Example Output

The value 10.000000 but with -3.000000's sign is -10.000000