copysign, copysignf, copysignl
Header: <math.h>
1-3) Composes a floating-point value with the magnitude of x and the sign of y.
# Declarations
float copysignf( float x, float y );
(since C99)
double copysign( double x, double y );
(since C99)
long double copysignl( long double x, long double y );
(since C99)
#define copysign(x, y)
(since C99)
# Parameters
x, y: floating-point values
# Return value
If no errors occur, the floating-point value with the magnitude of x and the sign of y is returned.
# Notes
copysign is the only portable way to manipulate the sign of a NaN value (to examine the sign of a NaN, signbit may also be used).
# Example
#include <math.h>
#include <stdio.h>
int main(void)
{
printf("copysign(1.0,+2.0) = %+.1f\n", copysign(1.0,+2.0));
printf("copysign(1.0,-2.0) = %+.1f\n", copysign(1.0,-2.0));
printf("copysign(INFINITY,-2.0) = %f\n", copysign(INFINITY,-2.0));
printf("copysign(NAN,-2.0) = %f\n", copysign(NAN,-2.0));
}