copysign()

Copies the sign of a number.

  #include <math.h>
  
  double copysign (double x, double y);    
Parameter

x

Magnitude.

y

Sign.

Remarks

This function produces a value with the magnitude of x and the sign of y. It regards the sign of zero to be positive. This function returns a signed NaN value if x is NaN.

This facility may not be available on configurations of the EWL that run on platforms that do not have floating-point math capabilities.

Listing: Example of copysign() usage

#include <math.h>

#include <stdio.h>

int main(void)

{

double e = +10.0;

double f = -3.0;

printf("Copysign(%f, %f) = %f.\n", e, f, copysign(e,f));

return 0;

}

Output:

Copysign(10.000000, -3.000000) = -10.000000.