mathfunc(3tcl)
โจ NAME โจ
mathfunc โ mathematical functions for Tcl expressions ๐งฎ๐
๐ SYNOPSIS ๐
package require Tcl 8.5-
::tcl::mathfunc::abs arg
::tcl::mathfunc::acos arg
::tcl::mathfunc::asin arg
::tcl::mathfunc::atan arg
::tcl::mathfunc::atan2 y x
::tcl::mathfunc::bool arg
::tcl::mathfunc::ceil arg
::tcl::mathfunc::cos arg
::tcl::mathfunc::cosh arg
::tcl::mathfunc::double arg
::tcl::mathfunc::entier arg
::tcl::mathfunc::exp arg
::tcl::mathfunc::floor arg
::tcl::mathfunc::fmod x y
::tcl::mathfunc::hypot x y
::tcl::mathfunc::int arg
::tcl::mathfunc::isfinite arg
::tcl::mathfunc::isinf arg
::tcl::mathfunc::isnan arg
::tcl::mathfunc::isnormal arg
::tcl::mathfunc::isqrt arg
::tcl::mathfunc::issubnormal arg
::tcl::mathfunc::isunordered x y
::tcl::mathfunc::log arg
::tcl::mathfunc::log10 arg
::tcl::mathfunc::max arg ?arg ...?
::tcl::mathfunc::min arg ?arg ...?
::tcl::mathfunc::pow x y
::tcl::mathfunc::rand
::tcl::mathfunc::round arg
::tcl::mathfunc::sin arg
::tcl::mathfunc::sinh arg
::tcl::mathfunc::sqrt arg
::tcl::mathfunc::srand arg
::tcl::mathfunc::tan arg
::tcl::mathfunc::tanh arg
::tcl::mathfunc::wide arg
๐ธ DESCRIPTION ๐ธ
okay so bestie, here's the tea โ โ expr is out here doing math with functions like sin($x) or atan2($y,$x), and the way it handles that is by quietly rewriting them into calls that look like [tcl::mathfunc::sin [expr {$x}]] or [tcl::mathfunc::atan2 [expr {$y}] [expr {$x}]]. iconic behaviour, honestly.
a whole bunch of math functions just come with the namespace ::tcl::mathfunc by default, and the best part? they're not locked inside expr โ you can call these commands directly from your own code too. slay. ๐
so Tcl supports these math functions in expressions, and heads up: they all work solely with floating-point numbers unless the description says otherwise:
abs, acos, asin, atan, atan2, bool, ceil, cos, cosh, double, entier, exp, floor, fmod, hypot, int, isfinite, isinf, isnan, isnormal, isqrt, issubnormal, isunordered, log, log10, max, min, pow, rand, round, sin, sinh, sqrt, srand, tan, tanh, wide
and on top of these pre-made ones, your app can literally just define its own functions ๐ โ use proc (or any other method, like interp alias or Tcl_CreateObjCommand) to make new commands inside the tcl::mathfunc namespace. main character energy, fr fr.
๐ DETAILED DEFINITIONS ๐
abs argโ gives you the absolute value ofarg.argcan be an integer or a floating-point value, and you get the result back in the same form you put in. ๐ชacos argโ the arc cosine ofarg, landing in the range[0,pi]radians.argshould be in the range[-1,1], bestie.asin argโ arc sine ofarg, in the range[-pi/2,pi/2]radians.argshould live in[-1,1].atan argโ arc tangent ofarg, in the range[-pi/2,pi/2]radians.atan2 y xโ arc tangent ofy/x, in the range[-pi,pi]radians. โ ๏ธxandycannot both be0. ifxis greater than0, this is equivalent to โatan [expr {y/x}]โ.bool argโ takes any numeric value, or any string thatstring is booleanwould accept, and hands back the matching boolean value0or1. non-zero numbers are true. other numbers are false. non-numeric strings produce a boolean value in agreement withstring is trueandstring is false. โ โceil argโ the smallest integral floating-point value (meaning a zero fractional part, iykyk) that is not less thanarg. the argument can be any numeric value. โฌ๏ธcos argโ cosine ofarg, measured in radians.cosh argโ hyperbolic cosine ofarg. ๐จ if the result would cause an overflow, an error is returned.double argโ the argument can be any numeric value. ifargis already a floating-point value, you getargback; otherwisearggets converted to floating-point and you get the converted value. it may returnInfor-Infwhen the argument is a numeric value that exceeds the floating-point range. ๐entier argโ the argument can be any numeric value. the integer part ofargis figured out and returned. and here's the glow-up โจ: the integer range returned by this function is unlimited, unlikeintandwide, which truncate their range to fit into particular storage widths.exp argโ the exponential ofarg, defined ase**arg. ๐จ if the result would cause an overflow, an error is returned.floor argโ the largest integral floating-point value (zero fractional part, again) that is not greater thanarg. argument can be any numeric value. โฌ๏ธfmod x yโ the floating-point remainder of dividingxbyy. โ ๏ธ ifyis0, an error is returned.hypot x yโ computes the length of the hypotenuse of a right-angled triangle, approximately โsqrt [expr {x*x+y*y}]โ โ except it's more numerically stable when the two arguments have substantially different magnitudes. ๐int argโ the argument can 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 is stored in thewordSizeelement of thetcl_platformarray. ๐isfinite argโ returns1if the floating-point numberargis finite โ that means zero, subnormal, or normal. returns0if the number is infinite or NaN. throws an error ifargcannot be promoted to a floating-point value.isinf argโ returns1if the floating-point numberargis infinite. returns0if the number is finite or NaN. throws an error ifargcannot be promoted to a floating-point value.isnan argโ returns1if the floating-point numberargis Not-a-Number. returns0if the number is finite or infinite. throws an error ifargcannot be promoted to a floating-point value.isnormal argโ returns1if the floating-point numberargis normal. returns0if the number is zero, subnormal, infinite or NaN. throws an error ifargcannot be promoted to a floating-point value.isqrt argโ computes the integer part of the square root ofarg.argmust be a positive value, either an integer or a floating point number. and unlikesqrt, which is limited to the precision of a floating point number,isqrtwill return a result of arbitrary precision. ๐ฅissubnormal argโ returns1if the floating-point numberargis subnormal, i.e., the result of gradual underflow. returns0if the number is zero, normal, infinite or NaN. throws an error ifargcannot be promoted to a floating-point value.isunordered x yโ returns1ifxandycannot be compared for ordering, that is, if either one is NaN. returns0if both values can be ordered, that is, if they are both chosen from among the set of zero, subnormal, normal and infinite values. throws an error if eitherxorycannot be promoted to a floating-point value.log argโ the natural logarithm ofarg.argmust be a positive value. ๐ฒlog10 argโ the base 10 logarithm ofarg.argmust be a positive value.max arg ...โ takes one or more numeric arguments and returns the one argument with the greatest value. ๐min arg ...โ takes one or more numeric arguments and returns the one argument with the least value. ๐ฅบpow x yโ computes the value ofxraised to the powery. โ ๏ธ ifxis negative,ymust be an integer value.randโ returns a pseudo-random floating-point value in the range(0,1). ๐ฒ real talk though: 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 it may be set with thesrandfunction.round argโ ifargis an integer value, you just getargback; otherwisearggets converted to integer by rounding, and you get the converted value. ๐ฏsin argโ sine ofarg, measured in radians.sinh argโ hyperbolic sine ofarg. ๐จ if the result would cause an overflow, an error is returned.sqrt argโ the argument may be any non-negative numeric value. returns a floating-point value that is the square root ofarg. it may returnInfwhen the argument is a numeric value that exceeds the square of the maximum value of the floating-point range. ๐ฑsrand argโarg, 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. and fun fact ๐ซถ: each interpreter has its own seed.tan argโ tangent ofarg, measured in radians.tanh argโ hyperbolic tangent ofarg.wide argโ the 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), fpclassify(3tcl), mathop(3tcl), namespace(3tcl)
๐ COPYRIGHT ๐
Copyright ยฉ 1993 The Regents of the University of California.
Copyright ยฉ 1994-2000 Sun Microsystems Incorporated.
Copyright ยฉ 2005-2006 Kevin B. Kenny <kennykb@acm.org>.
and that's the whole page, bestie โ this one's from Tcl 8.5, filed under mathfunc(3tcl) ๐๐ go forth and calculate, you absolute math icon ๐โจ
๐ฆ where this page comes from
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-2000 Sun Microsystems, Inc
- Copyright (c) 2005 Kevin B. Kenny <kennykb@acm.org>. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms