
copysign(+X, +Y, -Result)

   Compose a number from magnitude and sign

Arguments
   X                   A number
   Y                   A number
   Result              Output: number

Type
   Arithmetic

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
   copysign(+, +, -) is det

Exceptions
     4 --- X or Y is not instantiated (non-coroutining mode only).
    20 --- Sign of Y is not known
    24 --- 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
