Important: The information in this document is obsolete and should not be used for new development.
copysign
You can use thecopysign
function to assign to some real number the sign of a second value.
double_t copysign (double_t x, double_t y); long double copysignl (long double x, long double y);
x
- Any floating-point number.
y
- Any floating-point number.
DESCRIPTION
Thecopysign
function copies the sign of they
parameter into thex
parameter and returns the resulting number.
copysign(x,
1.0)
is always the absolute value ofx
. Thecopysign
function simply manipulates sign bits and hence raises no exception flags.EXCEPTIONS
When x and y are finite and nonzero, the result of is exact.SPECIAL CASES
Table 10-5 shows the results when one of the arguments to thecopysign
function is a zero, a NaN, or an Infinity. In this table, x and y are finite, nonzero floating-point numbers.
Special cases for the copysign
functionOperation Result Exceptions raised 0 with sign of y None |x| None 0 with sign of y None -|x| None NaN with sign of y None[26] x with sign of NaN None[26] with sign of y None |x| None with sign of y None -|x| None EXAMPLES
z = copysign(-1234.567, 1.0);/* z = 1234.567 */ z = copysign(1.0, -1234.567);/* z = -1.0 */
[26] If the NaN is a signaling NaN, the invalid exception is raised.