copysign
You can use the copysign 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
The copysign function copies the sign of the y parameter into the x parameter and returns the resulting number.
copysign(x, 1.0) is always the absolute value of x. The copysign 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 the copysign 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 function
Operation | 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.