Provided by: tcl8.5-doc_8.5.15-2ubuntu1_all

**NAME**

mathfunc - Mathematical functions for Tcl expressions

**SYNOPSIS**

package requireTcl8.5::tcl::mathfunc::absarg::tcl::mathfunc::acosarg::tcl::mathfunc::asinarg::tcl::mathfunc::atanarg::tcl::mathfunc::atan2yx::tcl::mathfunc::boolarg::tcl::mathfunc::ceilarg::tcl::mathfunc::cosarg::tcl::mathfunc::cosharg::tcl::mathfunc::doublearg::tcl::mathfunc::entierarg│::tcl::mathfunc::exparg::tcl::mathfunc::floorarg::tcl::mathfunc::fmodxy::tcl::mathfunc::hypotxy::tcl::mathfunc::intarg::tcl::mathfunc::isqrtarg::tcl::mathfunc::logarg::tcl::mathfunc::log10arg::tcl::mathfunc::maxarg?arg...?::tcl::mathfunc::minarg?arg...?::tcl::mathfunc::powxy::tcl::mathfunc::rand::tcl::mathfunc::roundarg::tcl::mathfunc::sinarg::tcl::mathfunc::sinharg::tcl::mathfunc::sqrtarg::tcl::mathfunc::srandarg::tcl::mathfunc::tanarg::tcl::mathfunc::tanharg::tcl::mathfunc::widearg_________________________________________________________________

**DESCRIPTION**

Theexprcommand handles mathematical functions of the formsin($x)oratan2($y,$x)by converting them to calls of the form[tcl::mathfunc::sin[expr{$x}]]or[tcl::mathfunc::atan2[expr{$y}][expr{$x}]]. A number of math functions are available by default within the namespace::tcl::mathfunc; these functions are also available for code apart fromexpr, by invoking the given commands directly. Tcl supports the following mathematical functions in expressions, all of which work solely with floating-point numbers unless otherwise noted:absacosasinatanatan2boolceilcoscoshdoubleentierexpfloorfmodhypotintisqrtloglog10maxminpowrandroundsinsinhsqrtsrandtantanhwideIn addition to these predefined functions, applications may define additional functions by usingproc(or any other method, such asinterpaliasorTcl_CreateObjCommand) to define new commands in thetcl::mathfuncnamespace. In addition, an obsolete interface namedTcl_CreateMathFunc() is available to extensions that are written in C. The latter interface is not recommended for new implementations.DETAILEDDEFINITIONSabsargReturns the absolute value ofarg.Argmay be either integer or floating-point, and the result is returned in the same form.acosargReturns the arc cosine ofarg, in the range [0,pi] radians.Argshould be in the range [-1,1].asinargReturns the arc sine ofarg, in the range [-pi/2,pi/2] radians.Argshould be in the range [-1,1].atanargReturns the arc tangent ofarg, in the range [-pi/2,pi/2] radians.atan2yxReturns the arc tangent ofy/x, in the range [-pi,pi] radians.xandycannot both be 0. Ifxis greater than0, this is equivalent to “atan[expr{y/x}]”.boolargAccepts any numeric value, or any string acceptable tostringisboolean, and returns the corresponding boolean value0or1. Non-zero numbers are true. Other numbers are false. Non-numeric strings produce boolean value in agreement withstringistrueandstringisfalse.ceilargReturns the smallest integral floating-point value (i.e. with a zero fractional part) not less thanarg. The argument may be any numeric value.cosargReturns the cosine ofarg, measured in radians.coshargReturns the hyperbolic cosine ofarg. If the result would cause an overflow, an error is returned.doubleargThe argument may be any numeric value, Ifargis a floating-point value, returnsarg, otherwise convertsargto floating-point and returns the converted value. May returnInfor-Infwhen the argument is a numeric value that exceeds the floating- point range.entierargThe argument may be any numeric value. The integer part ofargis determined and │ returned. The integer range returned by this function is unlimited, unlikeintand │widewhich truncate their range to fit in particular storage widths.expargReturns the exponential ofarg, defined ase**arg. If the result would cause an overflow, an error is returned.floorargReturns the largest integral floating-point value (i.e. with a zero fractional part) not greater thanarg. The argument may be any numeric value.fmodxyReturns the floating-point remainder of the division ofxbyy. Ifyis 0, an error is returned.hypotxyComputes the length of the hypotenuse of a right-angled triangle “sqrt[expr{x*x+y*y}]”.intargThe argument may be any numeric value. The integer part ofargis determined, and then the low order bits of that integer value up to the machine word size are returned as an integer value. For reference, the number of bytes in the machine word are stored intcl_platform(wordSize).isqrtargComputes the integer part of the square root ofarg.Argmust be a positive value, either an integer or a floating point number. Unlikesqrt, which is limited to the precision of a floating point number,isqrtwill return a result of arbitrary precision.logargReturns the natural logarithm ofarg.Argmust be a positive value.log10argReturns the base 10 logarithm ofarg.Argmust be a positive value.maxarg...Accepts one or more numeric arguments. Returns the one argument with the greatest value.minarg...Accepts one or more numeric arguments. Returns the one argument with the least value.powxyComputes the value ofxraised to the powery. Ifxis negative,ymust be an integer value.randReturns a pseudo-random floating-point value in the range (0,1). The generator algorithm is a simple linear congruential generator that is not cryptographically secure. Each result fromrandcompletely determines all future results from subsequent calls torand, sorandshould not be used to generate a sequence of secrets, such as one-time passwords. The seed of the generator is initialized from the internal clock of the machine or may be set with thesrandfunction.roundargIfargis an integer value, returnsarg, otherwise convertsargto integer by rounding and returns the converted value.sinargReturns the sine ofarg, measured in radians.sinhargReturns the hyperbolic sine ofarg. If the result would cause an overflow, an error is returned.sqrtargThe argument may be any non-negative numeric value. Returns a floating-point value that is the square root ofarg. May returnInfwhen the argument is a numeric value that exceeds the square of the maximum value of the floating-point range.srandargThearg, which must be an integer, is used to reset the seed for the random number generator ofrand. Returns the first random number (seerand) from that seed. Each interpreter has its own seed.tanargReturns the tangent ofarg, measured in radians.tanhargReturns the hyperbolic tangent ofarg.wideargThe argument may be any numeric value. The integer part ofargis determined, and then the low order 64 bits of that integer value are returned as an integer value.

**SEE** **ALSO**

expr(3tcl), mathop(3tcl), namespace(3tcl)

**COPYRIGHT**

Copyright (c) 1993 The Regents of the University of California. Copyright (c) 1994-2000 Sun Microsystems Incorporated. Copyright (c) 2005, 2006 by Kevin B. Kenny <kennykb@acm.org>.