Edit

Share via


copysign, copysignf, copysignl, _copysign, _copysignf, _copysignl

Returns a value that has the magnitude of one argument and the sign of another.

Syntax

double copysign(
   double x,
   double y
);
float copysign(
   float x,
   float y
); // C++ only
long double copysign(
   long double x,
   long double y
); // C++ only
float copysignf(
   float x,
   float y
); // C++ only
long double copysignl(
   long double x,
   long double y
); // C++ only
double _copysign(
   double x,
   double y
);
long double _copysignl(
   long double x,
   long double y
);
#define copysign(X, Y) // Requires C11 or higher

Parameters

x
The floating-point value that's returned as the magnitude of the result.

y
The floating-point value that's returned as the sign of the result.

Math and floating-point support

Return value

The copysign functions return a floating-point value that combines the magnitude of x and the sign of y. There's no error return.

Remarks

Because C++ allows overloading, you can call overloads of copysign that take and return float or long double values. In a C program, unless you're using the <tgmath.h> macro to call this function, copysign always takes and returns a double.

If you use the <tgmath.h> copysign() macro, the type of the argument determines which version of the function is selected. See Type-generic math for details.

Requirements

Routine Required header
_copysign <float.h>
copysign, copysignf, copysignl, _copysignf, _copysignl <math.h>
copysign macro <tgmath.h>

For more compatibility information, see Compatibility.

See also

fabs, fabsf, fabsl
_chgsign, _chgsignf, _chgsignl