- 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::exp arg
- ::tcl::mathfunc::floor arg
- ::tcl::mathfunc::fmod x y
- ::tcl::mathfunc::hypot x y
- ::tcl::mathfunc::int arg
- ::tcl::mathfunc::log arg
- ::tcl::mathfunc::log10 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
- abs(arg)
- acos(arg)
- asin(arg)
- atan(arg)
- atan2(y, x)
- bool(arg)
- ceil(arg)
- cos(arg)
- cosh(arg)
- double(arg)
- exp(arg)
- floor(arg)
- fmod(x, y)
- hypot(x, y)
- int(arg)
- log(arg)
- log10(arg)
- pow(x, y)
- rand()
- round(arg)
- sin(arg)
- sinh(arg)
- sqrt(arg)
- srand(arg)
- tan(arg)
- tanh(arg)
- wide(arg)
- SEE ALSO
- COPYRIGHT
mathfunc - Mathematical functions for Tcl expressions
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::exp arg
::tcl::mathfunc::floor arg
::tcl::mathfunc::fmod x y
::tcl::mathfunc::hypot x y
::tcl::mathfunc::int arg
::tcl::mathfunc::log arg
::tcl::mathfunc::log10 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
The expr command handles mathematical functions of the form
sin($x) or atan2($y,$x) by converting them to calls of the
form [tcl::math::sin [expr {$x}]] or
[tcl::math::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 from expr, 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:
abs cos int sinh
acos cosh log sqrt
asin double log10 srand
atan exp pow tan
atan2 floor rand tanh
bool fmod round wide
ceil hypot sin
- 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.
- acos(arg)
-
Returns the arc cosine of arg, in the range [0,pi]
radians. Arg should be in the range [-1,1].
- 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. If x is greater
than 0, this is equivalent to atan(y/x).
- bool(arg)
-
Accepts any numerical 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 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.
- 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)
-
If arg is a floating-point value, returns arg, otherwise converts
arg to floating-point and returns the converted value.
- 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.
- fmod(x, y)
-
Returns the floating-point remainder of the division of x by
y. If y is 0, an error is returned.
- hypot(x, y)
-
Computes the length of the hypotenuse of a right-angled triangle
sqrt(x*x+y*y).
- int(arg)
-
If arg is an integer value of the same width as the machine
word, returns arg, otherwise
converts arg to an integer (of the same size as a machine word,
i.e. 32-bits on 32-bit systems, and 64-bits on 64-bit systems) by
truncation and returns the converted 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.
- 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).
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)
-
Returns the square root of arg. Arg must be non-negative.
- 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.
- tan(arg)
-
Returns the tangent of arg, measured in radians.
- tanh(arg)
-
Returns the hyperbolic tangent of arg.
- wide(arg)
-
Converts arg to an integer value at least 64-bits wide (by sign-extension
if arg is a 32-bit number) if it is not one already.
In addition to these predefined functions, applications may
define additional functions by using proc (or any other method,
such as interp alias or Tcl_CreateObjCommand) to define
new commands in the tcl::mathfunc namespace. In addition, an
obsolete interface named Tcl_CreateMathFunc() is available to
extensions that are written in C. The latter interface is not recommended
for new implementations..
expr, namespace
Copyright (c) 1993 The Regents of the University of California.
Copyright (c) 1994-2000 Sun Microsystems Incorporated.
Copyright (c) 2005 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved.
Copyright © 1993 The Regents of the University of California.
Copyright © 1994-2000 Sun Microsystems, Inc.
Copyright © 2005 by Kevin B. Kenny . All rights reserved
Copyright © 1995-1997 Roger E. Critchlow Jr.