mathfunc(n)

πŸ’– mathfunc(n) πŸ’– β€” Tcl Mathematical Functions πŸŽ€

okay bestie, welcome to mathfunc(n), the page all about Tcl's mathematical functions. this is manual section n, and it's giving ✨math class but make it cute✨. lowkey essential if you've ever typed sin($x) in an expression and wondered who's actually doing the math. spoiler: it's this. πŸ‘‘


✨ NAME ✨

mathfunc β€” Mathematical functions for Tcl expressions 🌸


🌸 SYNOPSIS 🌸

first things first, you need the right version, no cap:

package require Tcl 8.5-

and here's the whole roster of commands, exactly as they live in the ::tcl::mathfunc:: namespace:

::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 πŸ¦‹

so here's the tea. when you write something like sin($x) or atan2($y,$x) inside an expression, the expr command doesn't just wing it β€” it quietly rewrites those into calls that look like this:

[tcl::mathfunc::sin [expr {$x}]]

and for the two-argument ones:

[tcl::mathfunc::atan2 [expr {$y}] [expr {$x}]]

a whole bunch of math functions come free by default inside the ::tcl::mathfunc namespace. and here's the slay part β€” you don't even need expr. you can just invoke those commands directly from your own code, bestie. main character energy fr. πŸ’…

Tcl supports the following mathematical functions in expressions. heads up: all of them work solely with floating-point numbers unless otherwise noted:

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 because the predefined ones are never enough for a girl with ambitions β€” applications can define additional functions by using proc (or literally any other method, like interp alias or Tcl_CreateObjCommand) to define new commands in the tcl::mathfunc namespace. build your own, periodt. 🌈


🧚 DETAILED DEFINITIONS 🧚

the moment you've all been waiting for. every single one, in order, no skips. 🫢

abs arg

Returns the absolute value of arg. arg may be either integer or floating-point, and the result is returned in the same form. same energy in, same energy out. ✨

acos arg

Returns the arc cosine of arg, in the range [0,pi] radians. arg should be in the range [-1,1]. step outside that and it's giving chaos, not math. πŸ™ˆ

asin arg

Returns the arc sine of arg, in the range [-pi/2,pi/2] radians. arg should be in the range [-1,1].

atan arg

Returns the arc tangent of arg, in the range [-pi/2,pi/2] radians.

atan2 y x

Returns the arc tangent of y/x, in the range [-pi,pi] radians. x and y cannot both be 0 β€” that combo is a no. if x is greater than 0, this is equivalent to atan [expr {y/x}].

bool arg

Accepts any numeric value, or any string acceptable to string is boolean, and returns the corresponding boolean value 0 or 1. Non-zero numbers are true. Other numbers are false. Non-numeric strings produce a boolean value in agreement with string is true and string is false.

ceil arg

Returns the smallest integral floating-point value (i.e. with a zero fractional part) not less than arg. The argument may be any numeric value. it rounds up, basically, and it does it in float form. πŸ‘‘

cos arg

Returns the cosine of arg, measured in radians.

cosh arg

Returns the hyperbolic cosine of arg. If the result would cause an overflow, an error is returned.

double arg

The argument may be any numeric value. If arg is a floating-point value, returns arg; otherwise converts arg to floating-point and returns the converted value. May return Inf or -Inf when the argument is a numeric value that exceeds the floating-point range.

entier arg

The argument may be any numeric value. The integer part of arg is determined and returned. The integer range returned by this function is unlimited, unlike int and wide which truncate their range to fit in particular storage widths. no ceiling on this one, literally.

exp arg

Returns the exponential of arg, defined as e**arg. If the result would cause an overflow, an error is returned.

floor arg

Returns the largest integral floating-point value (i.e. with a zero fractional part) not greater than arg. The argument may be any numeric value.

fmod x y

Returns the floating-point remainder of the division of x by y. If y is 0, an error is returned. do not divide by zero, bestie, it's not the vibe. πŸ’€

hypot x y

Computes the length of the hypotenuse of a right-angled triangle, approximately sqrt [expr {x*x+y*y}] except for being more numerically stable when the two arguments have substantially different magnitudes. so like, the same answer but with better manners. 🌸

int arg

The argument may be any numeric value. The integer part of arg is 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 the wordSize element of the tcl_platform array. iykyk. 🧠

isfinite arg

Returns 1 if the floating-point number arg is finite. That is, if it is zero, subnormal, or normal. Returns 0 if the number is infinite or NaN. Throws an error if arg cannot be promoted to a floating-point value.

isinf arg

Returns 1 if the floating-point number arg is infinite. Returns 0 if the number is finite or NaN. Throws an error if arg cannot be promoted to a floating-point value.

isnan arg

Returns 1 if the floating-point number arg is Not-a-Number. Returns 0 if the number is finite or infinite. Throws an error if arg cannot be promoted to a floating-point value. it's literally in the name. πŸ™ˆ

isnormal arg

Returns 1 if the floating-point number arg is normal. Returns 0 if the number is zero, subnormal, infinite or NaN. Throws an error if arg cannot be promoted to a floating-point value.

isqrt arg

Computes the integer part of the square root of arg. arg must be a positive value, either an integer or a floating point number. Unlike sqrt, which is limited to the precision of a floating point number, isqrt will return a result of arbitrary precision. unlimited precision?? we love to see it. πŸ”₯

issubnormal arg

Returns 1 if the floating-point number arg is subnormal, i.e., the result of gradual underflow. Returns 0 if the number is zero, normal, infinite or NaN. Throws an error if arg cannot be promoted to a floating-point value.

isunordered x y

Returns 1 if x and y cannot be compared for ordering, that is, if either one is NaN. Returns 0 if 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 either x or y cannot be promoted to a floating-point value.

log arg

Returns the natural logarithm of arg. arg must be a positive value.

log10 arg

Returns the base 10 logarithm of arg. arg must be a positive value.

max arg ...

Accepts one or more numeric arguments. Returns the one argument with the greatest value. pick the winner, babes. πŸ‘‘

min arg ...

Accepts one or more numeric arguments. Returns the one argument with the least value.

pow x y

Computes the value of x raised to the power y. If x is negative, y must be an integer value.

rand

Returns a pseudo-random floating-point value in the range (0,1).

🚨 okay listen, this one matters. The generator algorithm is a simple linear congruential generator that is not cryptographically secure. Each result from rand completely determines all future results from subsequent calls to rand, so rand should 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 the srand function.

round arg

If arg is an integer value, returns arg, otherwise converts arg to integer by rounding and returns the converted value.

sin arg

Returns the sine of arg, measured in radians.

sinh arg

Returns the hyperbolic sine of arg. 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 of arg. May return Inf when the argument is a numeric value that exceeds the square of the maximum value of the floating-point range.

srand arg

The arg, which must be an integer, is used to reset the seed for the random number generator of rand. Returns the first random number (see rand) from that seed. Each interpreter has its own seed. yes, your seed is yours, it's personal. πŸ’…

tan arg

Returns the tangent of arg, measured in radians.

tanh arg

Returns the hyperbolic tangent of arg.

wide arg

The argument may be any numeric value. The integer part of arg is determined, and then the low order 64 bits of that integer value are returned as an integer value.


πŸ‘€ SEE ALSO πŸ‘€

go read these too, they're the friend group:


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 was Tcl 8.5's mathfunc(n), straight from the Tcl Mathematical Functions corner of the manual. no date on this one, she's timeless. now go forth and compute, you absolute icon. πŸ¦‹βœ¨πŸ’–

πŸ“¦ where this page comes from