OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / man / mann / mathfunc.n
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-2000 Sun Microsystems, Inc.
4 '\" Copyright (c) 2005 by Kevin B. Kenny <kennykb@acm.org>. All rights reserved
5 '\"
6 '\" See the file "license.terms" for information on usage and redistribution
7 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 '\" 
9 .TH mathfunc n 8.5 Tcl "Tcl Mathematical Functions"
10 .\" The -*- nroff -*- definitions below are for supplemental macros used
11 .\" in Tcl/Tk manual entries.
12 .\"
13 .\" .AP type name in/out ?indent?
14 .\"     Start paragraph describing an argument to a library procedure.
15 .\"     type is type of argument (int, etc.), in/out is either "in", "out",
16 .\"     or "in/out" to describe whether procedure reads or modifies arg,
17 .\"     and indent is equivalent to second arg of .IP (shouldn't ever be
18 .\"     needed;  use .AS below instead)
19 .\"
20 .\" .AS ?type? ?name?
21 .\"     Give maximum sizes of arguments for setting tab stops.  Type and
22 .\"     name are examples of largest possible arguments that will be passed
23 .\"     to .AP later.  If args are omitted, default tab stops are used.
24 .\"
25 .\" .BS
26 .\"     Start box enclosure.  From here until next .BE, everything will be
27 .\"     enclosed in one large box.
28 .\"
29 .\" .BE
30 .\"     End of box enclosure.
31 .\"
32 .\" .CS
33 .\"     Begin code excerpt.
34 .\"
35 .\" .CE
36 .\"     End code excerpt.
37 .\"
38 .\" .VS ?version? ?br?
39 .\"     Begin vertical sidebar, for use in marking newly-changed parts
40 .\"     of man pages.  The first argument is ignored and used for recording
41 .\"     the version when the .VS was added, so that the sidebars can be
42 .\"     found and removed when they reach a certain age.  If another argument
43 .\"     is present, then a line break is forced before starting the sidebar.
44 .\"
45 .\" .VE
46 .\"     End of vertical sidebar.
47 .\"
48 .\" .DS
49 .\"     Begin an indented unfilled display.
50 .\"
51 .\" .DE
52 .\"     End of indented unfilled display.
53 .\"
54 .\" .SO ?manpage?
55 .\"     Start of list of standard options for a Tk widget. The manpage
56 .\"     argument defines where to look up the standard options; if
57 .\"     omitted, defaults to "options". The options follow on successive
58 .\"     lines, in three columns separated by tabs.
59 .\"
60 .\" .SE
61 .\"     End of list of standard options for a Tk widget.
62 .\"
63 .\" .OP cmdName dbName dbClass
64 .\"     Start of description of a specific option.  cmdName gives the
65 .\"     option's name as specified in the class command, dbName gives
66 .\"     the option's name in the option database, and dbClass gives
67 .\"     the option's class in the option database.
68 .\"
69 .\" .UL arg1 arg2
70 .\"     Print arg1 underlined, then print arg2 normally.
71 .\"
72 .\" .QW arg1 ?arg2?
73 .\"     Print arg1 in quotes, then arg2 normally (for trailing punctuation).
74 .\"
75 .\" .PQ arg1 ?arg2?
76 .\"     Print an open parenthesis, arg1 in quotes, then arg2 normally
77 .\"     (for trailing punctuation) and then a closing parenthesis.
78 .\"
79 .\"     # Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
80 .if t .wh -1.3i ^B
81 .nr ^l \n(.l
82 .ad b
83 .\"     # Start an argument description
84 .de AP
85 .ie !"\\$4"" .TP \\$4
86 .el \{\
87 .   ie !"\\$2"" .TP \\n()Cu
88 .   el          .TP 15
89 .\}
90 .ta \\n()Au \\n()Bu
91 .ie !"\\$3"" \{\
92 \&\\$1 \\fI\\$2\\fP (\\$3)
93 .\".b
94 .\}
95 .el \{\
96 .br
97 .ie !"\\$2"" \{\
98 \&\\$1  \\fI\\$2\\fP
99 .\}
100 .el \{\
101 \&\\fI\\$1\\fP
102 .\}
103 .\}
104 ..
105 .\"     # define tabbing values for .AP
106 .de AS
107 .nr )A 10n
108 .if !"\\$1"" .nr )A \\w'\\$1'u+3n
109 .nr )B \\n()Au+15n
110 .\"
111 .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
112 .nr )C \\n()Bu+\\w'(in/out)'u+2n
113 ..
114 .AS Tcl_Interp Tcl_CreateInterp in/out
115 .\"     # BS - start boxed text
116 .\"     # ^y = starting y location
117 .\"     # ^b = 1
118 .de BS
119 .br
120 .mk ^y
121 .nr ^b 1u
122 .if n .nf
123 .if n .ti 0
124 .if n \l'\\n(.lu\(ul'
125 .if n .fi
126 ..
127 .\"     # BE - end boxed text (draw box now)
128 .de BE
129 .nf
130 .ti 0
131 .mk ^t
132 .ie n \l'\\n(^lu\(ul'
133 .el \{\
134 .\"     Draw four-sided box normally, but don't draw top of
135 .\"     box if the box started on an earlier page.
136 .ie !\\n(^b-1 \{\
137 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
138 .\}
139 .el \}\
140 \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
141 .\}
142 .\}
143 .fi
144 .br
145 .nr ^b 0
146 ..
147 .\"     # VS - start vertical sidebar
148 .\"     # ^Y = starting y location
149 .\"     # ^v = 1 (for troff;  for nroff this doesn't matter)
150 .de VS
151 .if !"\\$2"" .br
152 .mk ^Y
153 .ie n 'mc \s12\(br\s0
154 .el .nr ^v 1u
155 ..
156 .\"     # VE - end of vertical sidebar
157 .de VE
158 .ie n 'mc
159 .el \{\
160 .ev 2
161 .nf
162 .ti 0
163 .mk ^t
164 \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
165 .sp -1
166 .fi
167 .ev
168 .\}
169 .nr ^v 0
170 ..
171 .\"     # Special macro to handle page bottom:  finish off current
172 .\"     # box/sidebar if in box/sidebar mode, then invoked standard
173 .\"     # page bottom macro.
174 .de ^B
175 .ev 2
176 'ti 0
177 'nf
178 .mk ^t
179 .if \\n(^b \{\
180 .\"     Draw three-sided box if this is the box's first page,
181 .\"     draw two sides but no top otherwise.
182 .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
183 .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
184 .\}
185 .if \\n(^v \{\
186 .nr ^x \\n(^tu+1v-\\n(^Yu
187 \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
188 .\}
189 .bp
190 'fi
191 .ev
192 .if \\n(^b \{\
193 .mk ^y
194 .nr ^b 2
195 .\}
196 .if \\n(^v \{\
197 .mk ^Y
198 .\}
199 ..
200 .\"     # DS - begin display
201 .de DS
202 .RS
203 .nf
204 .sp
205 ..
206 .\"     # DE - end display
207 .de DE
208 .fi
209 .RE
210 .sp
211 ..
212 .\"     # SO - start of list of standard options
213 .de SO
214 'ie '\\$1'' .ds So \\fBoptions\\fR
215 'el .ds So \\fB\\$1\\fR
216 .SH "STANDARD OPTIONS"
217 .LP
218 .nf
219 .ta 5.5c 11c
220 .ft B
221 ..
222 .\"     # SE - end of list of standard options
223 .de SE
224 .fi
225 .ft R
226 .LP
227 See the \\*(So manual entry for details on the standard options.
228 ..
229 .\"     # OP - start of full description for a single option
230 .de OP
231 .LP
232 .nf
233 .ta 4c
234 Command-Line Name:      \\fB\\$1\\fR
235 Database Name:  \\fB\\$2\\fR
236 Database Class: \\fB\\$3\\fR
237 .fi
238 .IP
239 ..
240 .\"     # CS - begin code excerpt
241 .de CS
242 .RS
243 .nf
244 .ta .25i .5i .75i 1i
245 ..
246 .\"     # CE - end code excerpt
247 .de CE
248 .fi
249 .RE
250 ..
251 .\"     # UL - underline word
252 .de UL
253 \\$1\l'|0\(ul'\\$2
254 ..
255 .\"     # QW - apply quotation marks to word
256 .de QW
257 .ie '\\*(lq'"' ``\\$1''\\$2
258 .\"" fix emacs highlighting
259 .el \\*(lq\\$1\\*(rq\\$2
260 ..
261 .\"     # PQ - apply parens and quotation marks to word
262 .de PQ
263 .ie '\\*(lq'"' (``\\$1''\\$2)\\$3
264 .\"" fix emacs highlighting
265 .el (\\*(lq\\$1\\*(rq\\$2)\\$3
266 ..
267 .\"     # QR - quoted range
268 .de QR
269 .ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
270 .\"" fix emacs highlighting
271 .el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
272 ..
273 .\"     # MT - "empty" string
274 .de MT
275 .QW ""
276 ..
277 .BS
278 '\" Note:  do not modify the .SH NAME line immediately below!
279 .SH NAME
280 mathfunc \- Mathematical functions for Tcl expressions
281 .SH SYNOPSIS
282 package require \fBTcl 8.5\fR
283 .sp
284 \fB::tcl::mathfunc::abs\fR \fIarg\fR
285 .br
286 \fB::tcl::mathfunc::acos\fR \fIarg\fR
287 .br
288 \fB::tcl::mathfunc::asin\fR \fIarg\fR
289 .br
290 \fB::tcl::mathfunc::atan\fR \fIarg\fR
291 .br
292 \fB::tcl::mathfunc::atan2\fR \fIy\fR \fIx\fR
293 .br
294 \fB::tcl::mathfunc::bool\fR \fIarg\fR
295 .br
296 \fB::tcl::mathfunc::ceil\fR \fIarg\fR
297 .br
298 \fB::tcl::mathfunc::cos\fR \fIarg\fR
299 .br
300 \fB::tcl::mathfunc::cosh\fR \fIarg\fR
301 .br
302 \fB::tcl::mathfunc::double\fR \fIarg\fR
303 .br
304 \fB::tcl::mathfunc::entier\fR \fIarg\fR
305 .br
306 \fB::tcl::mathfunc::exp\fR \fIarg\fR
307 .br
308 \fB::tcl::mathfunc::floor\fR \fIarg\fR
309 .br
310 \fB::tcl::mathfunc::fmod\fR \fIx\fR \fIy\fR
311 .br
312 \fB::tcl::mathfunc::hypot\fR \fIx\fR \fIy\fR
313 .br
314 \fB::tcl::mathfunc::int\fR \fIarg\fR
315 .br
316 \fB::tcl::mathfunc::isqrt\fR \fIarg\fR
317 .br
318 \fB::tcl::mathfunc::log\fR \fIarg\fR
319 .br
320 \fB::tcl::mathfunc::log10\fR \fIarg\fR
321 .br
322 \fB::tcl::mathfunc::max\fR \fIarg\fR ?\fIarg\fR ...?
323 .br
324 \fB::tcl::mathfunc::min\fR \fIarg\fR ?\fIarg\fR ...?
325 .br
326 \fB::tcl::mathfunc::pow\fR \fIx\fR \fIy\fR
327 .br
328 \fB::tcl::mathfunc::rand\fR
329 .br
330 \fB::tcl::mathfunc::round\fR \fIarg\fR
331 .br
332 \fB::tcl::mathfunc::sin\fR \fIarg\fR
333 .br
334 \fB::tcl::mathfunc::sinh\fR \fIarg\fR
335 .br
336 \fB::tcl::mathfunc::sqrt\fR \fIarg\fR
337 .br
338 \fB::tcl::mathfunc::srand\fR \fIarg\fR
339 .br
340 \fB::tcl::mathfunc::tan\fR \fIarg\fR
341 .br
342 \fB::tcl::mathfunc::tanh\fR \fIarg\fR
343 .br
344 \fB::tcl::mathfunc::wide\fR \fIarg\fR
345 .sp
346 .BE
347 .SH "DESCRIPTION"
348 .PP
349 The \fBexpr\fR command handles mathematical functions of the form
350 \fBsin($x)\fR or \fBatan2($y,$x)\fR by converting them to calls of the
351 form \fB[tcl::mathfunc::sin [expr {$x}]]\fR or
352 \fB[tcl::mathfunc::atan2 [expr {$y}] [expr {$x}]]\fR.
353 A number of math functions are available by default within the
354 namespace \fB::tcl::mathfunc\fR; these functions are also available
355 for code apart from \fBexpr\fR, by invoking the given commands
356 directly.
357 .PP
358 Tcl supports the following mathematical functions in expressions, all
359 of which work solely with floating-point numbers unless otherwise noted:
360 .DS
361 .ta 3c 6c 9c
362 \fBabs\fR       \fBacos\fR      \fBasin\fR      \fBatan\fR
363 \fBatan2\fR     \fBbool\fR      \fBceil\fR      \fBcos\fR
364 \fBcosh\fR      \fBdouble\fR    \fBentier\fR    \fBexp\fR
365 \fBfloor\fR     \fBfmod\fR      \fBhypot\fR     \fBint\fR
366 \fBisqrt\fR     \fBlog\fR       \fBlog10\fR     \fBmax\fR
367 \fBmin\fR       \fBpow\fR       \fBrand\fR      \fBround\fR
368 \fBsin\fR       \fBsinh\fR      \fBsqrt\fR      \fBsrand\fR
369 \fBtan\fR       \fBtanh\fR      \fBwide\fR
370 .DE
371 .PP
372 In addition to these predefined functions, applications may
373 define additional functions by using \fBproc\fR (or any other method,
374 such as \fBinterp alias\fR or \fBTcl_CreateObjCommand\fR) to define
375 new commands in the \fBtcl::mathfunc\fR namespace.  In addition, an
376 obsolete interface named \fBTcl_CreateMathFunc\fR() is available to
377 extensions that are written in C. The latter interface is not recommended
378 for new implementations.
379 .SS "DETAILED DEFINITIONS"
380 .TP
381 \fBabs \fIarg\fR
382 .
383 Returns the absolute value of \fIarg\fR.  \fIArg\fR may be either
384 integer or floating-point, and the result is returned in the same form.
385 .TP
386 \fBacos \fIarg\fR
387 .
388 Returns the arc cosine of \fIarg\fR, in the range [\fI0\fR,\fIpi\fR]
389 radians. \fIArg\fR should be in the range [\fI\-1\fR,\fI1\fR].
390 .TP
391 \fBasin \fIarg\fR
392 .
393 Returns the arc sine of \fIarg\fR, in the range [\fI\-pi/2\fR,\fIpi/2\fR]
394 radians.  \fIArg\fR should be in the range [\fI\-1\fR,\fI1\fR].
395 .TP
396 \fBatan \fIarg\fR
397 .
398 Returns the arc tangent of \fIarg\fR, in the range [\fI\-pi/2\fR,\fIpi/2\fR]
399 radians.
400 .TP
401 \fBatan2 \fIy x\fR
402 .
403 Returns the arc tangent of \fIy\fR/\fIx\fR, in the range [\fI\-pi\fR,\fIpi\fR]
404 radians.  \fIx\fR and \fIy\fR cannot both be 0.  If \fIx\fR is greater
405 than \fI0\fR, this is equivalent to
406 .QW "\fBatan \fR[\fBexpr\fR {\fIy\fB/\fIx\fR}]" .
407 .TP
408 \fBbool \fIarg\fR
409 .
410 Accepts any numeric value, or any string acceptable to
411 \fBstring is boolean\fR, and returns the corresponding 
412 boolean value \fB0\fR or \fB1\fR.  Non-zero numbers are true.
413 Other numbers are false.  Non-numeric strings produce boolean value in
414 agreement with \fBstring is true\fR and \fBstring is false\fR.
415 .TP
416 \fBceil \fIarg\fR
417 .
418 Returns the smallest integral floating-point value (i.e. with a zero
419 fractional part) not less than \fIarg\fR.  The argument may be any
420 numeric value.
421 .TP
422 \fBcos \fIarg\fR
423 .
424 Returns the cosine of \fIarg\fR, measured in radians.
425 .TP
426 \fBcosh \fIarg\fR
427 .
428 Returns the hyperbolic cosine of \fIarg\fR.  If the result would cause
429 an overflow, an error is returned.
430 .TP
431 \fBdouble \fIarg\fR
432 .
433 The argument may be any numeric value,
434 If \fIarg\fR is a floating-point value, returns \fIarg\fR, otherwise converts
435 \fIarg\fR to floating-point and returns the converted value.  May return
436 \fBInf\fR or \fB\-Inf\fR when the argument is a numeric value that exceeds
437 the floating-point range.
438 .TP
439 \fBentier \fIarg\fR
440 .
441 The argument may be any numeric value.  The integer part of \fIarg\fR
442 is determined and returned.  The integer range returned by this function
443 is unlimited, unlike \fBint\fR and \fBwide\fR which
444 truncate their range to fit in particular storage widths.
445 .TP
446 \fBexp \fIarg\fR
447 .
448 Returns the exponential of \fIarg\fR, defined as \fIe\fR**\fIarg\fR.
449 If the result would cause an overflow, an error is returned.
450 .TP
451 \fBfloor \fIarg\fR
452 .
453 Returns the largest integral floating-point value (i.e. with a zero
454 fractional part) not greater than \fIarg\fR.  The argument may be
455 any numeric value.
456 .TP
457 \fBfmod \fIx y\fR
458 .
459 Returns the floating-point remainder of the division of \fIx\fR by
460 \fIy\fR.  If \fIy\fR is 0, an error is returned.
461 .TP
462 \fBhypot \fIx y\fR
463 .
464 Computes the length of the hypotenuse of a right-angled triangle,
465 approximately
466 .QW "\fBsqrt\fR [\fBexpr\fR {\fIx\fB*\fIx\fB+\fIy\fB*\fIy\fR}]"
467 except for being more numerically stable when the two arguments have
468 substantially different magnitudes.
469 .TP
470 \fBint \fIarg\fR
471 .
472 The argument may be any numeric value.  The integer part of \fIarg\fR
473 is determined, and then the low order bits of that integer value up
474 to the machine word size are returned as an integer value.  For reference,
475 the number of bytes in the machine word are stored in the \fBwordSize\fR
476 element of the \fBtcl_platform\fR array.
477 .TP
478 \fBisqrt \fIarg\fR
479 .
480 Computes the integer part of the square root of \fIarg\fR.  \fIArg\fR must be
481 a positive value, either an integer or a floating point number.
482 Unlike \fBsqrt\fR, which is limited to the precision of a floating point
483 number, \fIisqrt\fR will return a result of arbitrary precision.
484 .TP
485 \fBlog \fIarg\fR
486 .
487 Returns the natural logarithm of \fIarg\fR.  \fIArg\fR must be a
488 positive value.
489 .TP
490 \fBlog10 \fIarg\fR
491 .
492 Returns the base 10 logarithm of \fIarg\fR.  \fIArg\fR must be a
493 positive value.
494 .TP
495 \fBmax \fIarg\fB \fI...\fR
496 .
497 Accepts one or more numeric arguments.  Returns the one argument
498 with the greatest value.
499 .TP
500 \fBmin \fIarg\fB \fI...\fR
501 .
502 Accepts one or more numeric arguments.  Returns the one argument
503 with the least value.
504 .TP
505 \fBpow \fIx y\fR
506 .
507 Computes the value of \fIx\fR raised to the power \fIy\fR.  If \fIx\fR
508 is negative, \fIy\fR must be an integer value.
509 .TP
510 \fBrand\fR
511 .
512 Returns a pseudo-random floating-point value in the range (\fI0\fR,\fI1\fR).  
513 The generator algorithm is a simple linear congruential generator that
514 is not cryptographically secure.  Each result from \fBrand\fR completely
515 determines all future results from subsequent calls to \fBrand\fR, so
516 \fBrand\fR should not be used to generate a sequence of secrets, such as
517 one-time passwords.  The seed of the generator is initialized from the
518 internal clock of the machine or may be set with the \fBsrand\fR function.
519 .TP
520 \fBround \fIarg\fR
521 .
522 If \fIarg\fR is an integer value, returns \fIarg\fR, otherwise converts
523 \fIarg\fR to integer by rounding and returns the converted value.
524 .TP
525 \fBsin \fIarg\fR
526 .
527 Returns the sine of \fIarg\fR, measured in radians.
528 .TP
529 \fBsinh \fIarg\fR
530 .
531 Returns the hyperbolic sine of \fIarg\fR.  If the result would cause
532 an overflow, an error is returned.
533 .TP
534 \fBsqrt \fIarg\fR
535 .
536 The argument may be any non-negative numeric value.  Returns a floating-point
537 value that is the square root of \fIarg\fR.  May return \fBInf\fR when the
538 argument is a numeric value that exceeds the square of the maximum value of
539 the floating-point range.
540 .TP
541 \fBsrand \fIarg\fR
542 .
543 The \fIarg\fR, which must be an integer, is used to reset the seed for
544 the random number generator of \fBrand\fR.  Returns the first random
545 number (see \fBrand\fR) from that seed.  Each interpreter has its own seed.
546 .TP
547 \fBtan \fIarg\fR
548 .
549 Returns the tangent of \fIarg\fR, measured in radians.
550 .TP
551 \fBtanh \fIarg\fR
552 .
553 Returns the hyperbolic tangent of \fIarg\fR.
554 .TP
555 \fBwide \fIarg\fR
556 .
557 The argument may be any numeric value.  The integer part of \fIarg\fR
558 is determined, and then the low order 64 bits of that integer value
559 are returned as an integer value.  
560 .SH "SEE ALSO"
561 expr(n), mathop(n), namespace(n)
562 .SH "COPYRIGHT"
563 .nf
564 Copyright (c) 1993 The Regents of the University of California.
565 Copyright (c) 1994-2000 Sun Microsystems Incorporated.
566 Copyright (c) 2005, 2006 by Kevin B. Kenny <kennykb@acm.org>.
567 .fi
568 '\" Local Variables:
569 '\" mode: nroff
570 '\" fill-column: 78
571 '\" End: