beetlebug▾
/

tcl::mathfunc cos

Gives the cosine of an angle in radians.

tcl::mathfunc::cos RADIANS
expr {cos(RADIANS)}

Description

Gives the cosine of RADIANS. An infinite angle is a domain error.

Arguments

ArgumentTypeDefaultDescription
RADIANSnumberrequiredThe angle, in radians.

Returns

A float from -1 to 1.

Examples

% expr {cos(0)}
1.0

% expr {cos(3.141592653589793)}
-1.0

% expr {cos(1)}
0.5403023058681398

Errors

% expr {cos(Inf)}
domain error: argument not in valid range
-errorcode ARITH DOMAIN {domain error: argument not in valid range}

# Tcl 9.1 only
% expr {cos("x")}
cannot use non-numeric string "x" as operand of "cos"
-errorcode ARITH DOMAIN {non-numeric string}

# Tcl 8.6 only
% expr {cos("x")}
can't use non-numeric string as operand of "cos"
-errorcode ARITH DOMAIN {non-numeric string}

Facts

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

See also