Version 4 of atan

Updated 2003-04-12 20:02:44

Purpose: Explain the math function atan.


The call,

    [expr { atan( $x ) }]

returns the inverse tangent of the number, $x. The resulting angle is measured in radians.


Most uses of atan are perilous. The problem is that there is always uncertainty about the quadrant of the angle:

 % set PI 3.1415926535897932
 3.1415926535897932
 % puts [expr {tan ( 0.25 * $PI ) }]
 0.99999999999999989
 % puts [expr { tan ( 1.25 * $PI ) }]
 0.99999999999999967

In other words, when you say,

    [expr { atan( 1.0 ) }]

it is hard to know whether you mean

 0.25 * $PI

or

 1.25 * $PI

For this reason, atan should generally be avoided in favor of atan2, which does not suffer from this problem.


atan provides a handy way to ask Tcl for the value of pi:

 % expr {atan(1) * 4}
 3.1415926535897931

Actually, using acos() is more efficient:

 % set tcl_precision 17
 17
 % expr {acos(-1)}
 3.1415926535897931

atan is also available in Tclx.


Math function help - Arts and Crafts of Tcl-Tk Programming - Category Mathematics