
copysign(+X, +Y, -Result)
-Result is copysign(+X, +Y)

   Compose a number from magnitude and sign

Arguments
   X                   A number
   Y                   A number
   Result              Output: number

Type
   Arithmetic

Description

    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.

   This predicate can be used as a function in arithmetic expressions.
   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
