# copysignf Function

Returns a single precision value with the magnitude of one value and the sign of another.

Include

<math.h>

Prototype

float copysignf(float x, float y);

Arguments

 x a single 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

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

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

x = 10.0;
y = -3.0;
z = copysignf(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