[ Arithmetic | Reference Manual | Alphabetic Index ]
# copysign(+X, +Y, -Result)

Compose a number from magnitude and sign
*X*
- A number
*Y*
- A number
*Result*
- Output: number

## Description

This predicate is used by the ECLiPSe compiler to expand evaluable
arithmetic expressions. So the call to copysign(X, Y, Result) is
equivalent to
Result is copysign(X, Y)

which should be preferred for portability.
Result is a number of the same type and absolute value as X, but with
the sign of Y. Result is therefore either identical to X or to -X.

This function correctly considers the sign bits of special floating
point values, such as -0.0, infinities and NaNs.

In coroutining mode, if X or Y is uninstantiated, the predicate delays.

### Modes and Determinism

### Exceptions

*(4) instantiation fault *
- X or Y is not instantiated (non-coroutining mode only).
*(20) arithmetic exception *
- Sign of Y is not known
*(24) number expected *
- Number is not of a numeric type.

## Examples

Success:
Result is copysign( 3.0, 2.0). % gives Result = 3.0
Result is copysign( 3.0,-2.0). % gives Result = -3.0
Result is copysign(-3.0, 2.0). % gives Result = 3.0
Result is copysign(-3.0,-2.0). % gives Result = -3.0
Result is copysign( 3.0,-0.0). % gives Result = -3.0
Result is copysign( 3.0, 0.0). % gives Result = 3.0
Result is copysign( 3.0, 0). % gives Result = 3.0
Result is copysign( 3, -1.0). % gives Result = -3
Result is copysign( 1, -0.0). % gives Result = -1
Result is copysign( 3.0, -1). % gives Result = -3.0
Result is copysign(-3.0, 1). % gives Result = 3.0
Error:
Result is copysign(3.0, -0.1__0.1). % arithmetic exception

## See Also

is / 2, abs / 2, sgn / 2