# FreeBSD Manual Pages

mathfunc(n) Tcl Mathematical Functions mathfunc(n) ______________________________________________________________________________NAMEmathfunc - Mathematical functions for Tcl expressionsSYNOPSISpackage 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______________________________________________________________________________DESCRIPTIONTheexprcommand handles mathematical functions of the formsin($x)oratan2($y,$x)by converting them to calls of the form[tcl::math-func::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 ad- ditional functions by usingproc(or any other method, such asinterpaliasorTcl_CreateObjCommand) to define new commands in thetcl::math-funcnamespace. In addition, an obsolete interface namedTcl_Cre-ateMathFunc() 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] radi- ans.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-nu- meric 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, unlikeintandwidewhich truncate their range to fit in particular storage widths.expargReturns the exponential ofarg, defined ase**arg. If the re- sult 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 trian- gle, approximately "sqrt[expr{x*x+y*y}]" except for being more numerically stable when the two arguments have substantially different magnitudes.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 in thewordSizeelement of thetcl_platformarray.isqrtargComputes the integer part of the square root ofarg.Argmust be a positive value, either an integer or a floating point num- ber. Unlikesqrt, which is limited to the precision of a float- ing point number,isqrtwill return a result of arbitrary preci- sion.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 nega- tive,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 genera- tor 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 ALSOexpr(n), mathop(n), namespace(n)COPYRIGHTCopyright (C) 1993 The Regents of the University of California. Copyright (C) 1994-2000 Sun Microsystems Incorporated. Copyright (C) 2005, 2006 Kevin B. Kenny <kennykb@acm.org>. Tcl 8.5 mathfunc(n)

NAME | SYNOPSIS | DESCRIPTION | SEE ALSO | COPYRIGHT

Want to link to this manual page? Use this URL:

<https://www.freebsd.org/cgi/man.cgi?query=mathfunc.tcl86&manpath=FreeBSD+13.0-RELEASE+and+Ports>