1mathfunc(n)               Tcl Mathematical Functions               mathfunc(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       mathfunc - Mathematical functions for Tcl expressions
9

SYNOPSIS

11       package require Tcl 8.5
12
13       ::tcl::mathfunc::abs arg
14       ::tcl::mathfunc::acos arg
15       ::tcl::mathfunc::asin arg
16       ::tcl::mathfunc::atan arg
17       ::tcl::mathfunc::atan2 y x
18       ::tcl::mathfunc::bool arg
19       ::tcl::mathfunc::ceil arg
20       ::tcl::mathfunc::cos arg
21       ::tcl::mathfunc::cosh arg
22       ::tcl::mathfunc::double arg
23       ::tcl::mathfunc::entier arg                                             │
24       ::tcl::mathfunc::exp arg
25       ::tcl::mathfunc::floor arg
26       ::tcl::mathfunc::fmod x y
27       ::tcl::mathfunc::hypot x y
28       ::tcl::mathfunc::int arg
29       ::tcl::mathfunc::isqrt arg
30       ::tcl::mathfunc::log arg
31       ::tcl::mathfunc::log10 arg
32       ::tcl::mathfunc::max arg ?arg ...?
33       ::tcl::mathfunc::min arg ?arg ...?
34       ::tcl::mathfunc::pow x y
35       ::tcl::mathfunc::rand
36       ::tcl::mathfunc::round arg
37       ::tcl::mathfunc::sin arg
38       ::tcl::mathfunc::sinh arg
39       ::tcl::mathfunc::sqrt arg
40       ::tcl::mathfunc::srand arg
41       ::tcl::mathfunc::tan arg
42       ::tcl::mathfunc::tanh arg
43       ::tcl::mathfunc::wide arg
44
45_________________________________________________________________
46

DESCRIPTION

48       The  expr command handles mathematical functions of the form sin($x) or
49       atan2($y,$x) by converting  them  to  calls  of  the  form  [tcl::math‐
50       func::sin  [expr  {$x}]]  or  [tcl::mathfunc::atan2  [expr  {$y}] [expr
51       {$x}]].  A number of math functions are available by default within the
52       namespace  ::tcl::mathfunc; these functions are also available for code
53       apart from expr, by invoking the given commands directly.
54
55       Tcl supports the following mathematical functions in  expressions,  all
56       of  which  work  solely  with  floating-point  numbers unless otherwise
57       noted:                          abs         acos        asin       atan
58       atan2       bool        ceil       cos                 cosh        dou‐
59       ble      entier     exp          floor       fmod        hypot      int
60       isqrt       log         log10      max
61       min         pow         rand       round
62       sin         sinh        sqrt       srand tan         tanh        wide
63
64       In  addition  to  these  predefined  functions, applications may define
65       additional functions by using proc (or any other method, such as interp
66       alias or Tcl_CreateObjCommand) to define new commands in the tcl::math‐
67       func namespace.  In addition,  an  obsolete  interface  named  Tcl_Cre‐
68       ateMathFunc()  is  available  to  extensions that are written in C. The
69       latter interface is not recommended for new implementations.
70
71   DETAILED DEFINITIONS
72       abs arg
73              Returns the absolute value of arg.  Arg may be either integer or
74              floating-point, and the result is returned in the same form.
75
76       acos arg
77              Returns  the arc cosine of arg, in the range [0,pi] radians. Arg
78              should be in the range [-1,1].
79
80       asin arg
81              Returns the arc sine of arg, in the range [-pi/2,pi/2]  radians.
82              Arg should be in the range [-1,1].
83
84       atan arg
85              Returns  the arc tangent of arg, in the range [-pi/2,pi/2] radi‐
86              ans.
87
88       atan2 y x
89              Returns the arc tangent of y/x, in the range  [-pi,pi]  radians.
90              x  and  y  cannot  both  be  0.  If x is greater than 0, this is
91              equivalent to “atan [expr {y/x}]”.
92
93       bool arg
94              Accepts any numeric value, or any string acceptable to string is
95              boolean,  and  returns  the  corresponding boolean value 0 or 1.
96              Non-zero numbers are  true.   Other  numbers  are  false.   Non-
97              numeric  strings  produce boolean value in agreement with string
98              is true and string is false.
99
100       ceil arg
101              Returns the smallest integral floating-point value (i.e. with  a
102              zero  fractional  part)  not less than arg.  The argument may be
103              any numeric value.
104
105       cos arg
106              Returns the cosine of arg, measured in radians.
107
108       cosh arg
109              Returns the hyperbolic cosine of arg.  If the result would cause
110              an overflow, an error is returned.
111
112       double arg
113              The  argument  may  be  any numeric value, If arg is a floating-
114              point value, returns arg, otherwise converts  arg  to  floating-
115              point  and  returns the converted value.  May return Inf or -Inf
116              when the argument is a numeric value that exceeds the  floating-
117              point range.
118
119       entier arg
120              The  argument may be any numeric value.  The integer part of arg
121              is determined and returned.  The integer range returned by  this │
122              function  is unlimited, unlike int and wide which truncate their │
123              range to fit in particular storage widths.
124
125       exp arg
126              Returns the exponential of  arg,  defined  as  e**arg.   If  the
127              result would cause an overflow, an error is returned.
128
129       floor arg
130              Returns  the  largest integral floating-point value (i.e. with a
131              zero fractional part) not greater than arg.  The argument may be
132              any numeric value.
133
134       fmod x y
135              Returns  the floating-point remainder of the division of x by y.
136              If y is 0, an error is returned.
137
138       hypot x y
139              Computes the length of the hypotenuse of a right-angled triangle
140sqrt [expr {x*x+y*y}]”.
141
142       int arg
143              The  argument may be any numeric value.  The integer part of arg
144              is determined, and then the low order bits of that integer value
145              up  to  the  machine word size are returned as an integer value.
146              For reference, the number of  bytes  in  the  machine  word  are
147              stored in tcl_platform(wordSize).
148
149       isqrt arg
150              Computes  the  integer part of the square root of arg.  Arg must
151              be a positive value, either an integer or a floating point  num‐
152              ber.  Unlike sqrt, which is limited to the precision of a float‐
153              ing point number, isqrt will return a result of arbitrary preci‐
154              sion.
155
156       log arg
157              Returns  the  natural  logarithm of arg.  Arg must be a positive
158              value.
159
160       log10 arg
161              Returns the base 10 logarithm of arg.  Arg must  be  a  positive
162              value.
163
164       max arg ...
165              Accepts one or more numeric arguments.  Returns the one argument
166              with the greatest value.
167
168       min arg ...
169              Accepts one or more numeric arguments.  Returns the one argument
170              with the least value.
171
172       pow x y
173              Computes  the  value  of x raised to the power y.  If x is nega‐
174              tive, y must be an integer value.
175
176       rand   Returns a pseudo-random floating-point value in the range (0,1).
177              The  generator algorithm is a simple linear congruential genera‐
178              tor that is not cryptographically secure.  Each result from rand
179              completely  determines  all future results from subsequent calls
180              to rand, so rand should not be used to generate  a  sequence  of
181              secrets,  such as one-time passwords.  The seed of the generator
182              is initialized from the internal clock of the machine or may  be
183              set with the srand function.
184
185       round arg
186              If  arg is an integer value, returns arg, otherwise converts arg
187              to integer by rounding and returns the converted value.
188
189       sin arg
190              Returns the sine of arg, measured in radians.
191
192       sinh arg
193              Returns the hyperbolic sine of arg.  If the result  would  cause
194              an overflow, an error is returned.
195
196       sqrt arg
197              The  argument  may be any non-negative numeric value.  Returns a
198              floating-point value that is the square root of arg.  May return
199              Inf when the argument is a numeric value that exceeds the square
200              of the maximum value of the floating-point range.
201
202       srand arg
203              The arg, which must be an integer, is used to reset the seed for
204              the  random  number generator of rand.  Returns the first random
205              number (see rand) from that seed.  Each interpreter has its  own
206              seed.
207
208       tan arg
209              Returns the tangent of arg, measured in radians.
210
211       tanh arg
212              Returns the hyperbolic tangent of arg.
213
214       wide arg
215              The  argument may be any numeric value.  The integer part of arg
216              is determined, and then the low order 64 bits  of  that  integer
217              value are returned as an integer value.
218

SEE ALSO

220       expr(n), mathop(n), namespace(n)
221
223       Copyright (c) 1993 The Regents of the University of California.
224       Copyright (c) 1994-2000 Sun Microsystems Incorporated.
225       Copyright (c) 2005, 2006 by Kevin B. Kenny <kennykb@acm.org>.
226
227
228
229Tcl                                   8.5                          mathfunc(n)
Impressum