Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 10 - Transcendental Functions / Sign Manipulation Functions


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 copysign(x,y) 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
OperationResultExceptions raised
copysign(+0,y) 0 with sign of yNone
copysign(x,+0) |x|None
copysign(-0,y) 0 with sign of yNone
copysign(x,-0) -|x|None
copysign(NaN,y) NaN with sign of yNone[26]
copysign(x,NaN) x with sign of NaNNone[26]
copysign(+ ,y) with sign of yNone
copysign(x,+ ) |x|None
copysign(- ,y) with sign of yNone
copysign(x,- ) -|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.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996