Version 1 of hypot

Updated 2001-12-15 11:31:47

Purpose: Discuss the math function hypot.


The call,

    [expr { hypot( $x, $y ) }]

returns the length of the hypotenuse of a right triangle when the length of the legs are $x and $y. It is equivalent to

    [expr { sqrt( $x * $x + $y * $y ) }]

except that it can handle cases where $x or $y are extremely large or extremely small without getting overflow or underflow.

In cases where there are no problems with being very close to the limits of the underlying double representation and you don't actually need the distance itself (e.g. in circle intersection testing and checking to see if one point is close enough to another) it is often quicker to work with the square of the length of the hypotenuse and avoid the expensive square root operation. I do not know how this ranks up with the additional overheads of math in Tcl though. DKF


The most common use of hypot is in Converting between rectangular and polar co-ordinates.


Math function help - Arts and crafts of Tcl-Tk programming - Category Mathematics