beetlebug▾
/

tcl::mathfunc copysignTcl 9.1 only

Gives the magnitude of one number with the sign of another.

tcl::mathfunc::copysign X Y
expr {copysign(X, Y)}

Description

Gives the absolute value of X with the sign of Y. The sign of a zero counts: copysign(3, -0.0) is -3.0.

Arguments

ArgumentTypeDefaultDescription
XnumberrequiredThe magnitude.
YnumberrequiredThe number with the sign of the result.

Returns

A float.

Examples

% expr {copysign(3, -0.0)}
-3.0

% expr {copysign(-2, 1)}
2.0

% expr {copysign(0, -1)}
-0.0

Errors

% expr {copysign(1)}
not enough arguments for math function "copysign"
-errorcode TCL WRONGARGS

% expr {copysign(1, NaN)}
floating point value is Not a Number
-errorcode TCL VALUE DOUBLE NAN

Facts

Capability
None.
Tcl release
Tcl 9.1 only.
Since
ztcl 1.0.0-beta.1

See also