Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/CrtMathFnc.3 @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 6.6 KB
Line 
1'\"
2'\" Copyright (c) 1989-1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: CrtMathFnc.3,v 1.17 2007/12/13 15:22:30 dgp Exp $
9'\"
10.so man.macros
11.TH Tcl_CreateMathFunc 3 8.4 Tcl "Tcl Library Procedures"
12.BS
13.SH NAME
14Tcl_CreateMathFunc, Tcl_GetMathFuncInfo, Tcl_ListMathFuncs \- Define, query and enumerate math functions for expressions
15.SH SYNOPSIS
16.nf
17\fB#include <tcl.h>\fR
18.sp
19void
20\fBTcl_CreateMathFunc\fR(\fIinterp, name, numArgs, argTypes, proc, clientData\fR)
21.sp
22int
23\fBTcl_GetMathFuncInfo\fR(\fIinterp, name, numArgsPtr, argTypesPtr, procPtr,
24                    clientDataPtr\fR)
25.sp
26Tcl_Obj *
27\fBTcl_ListMathFuncs\fR(\fIinterp, pattern\fR)
28.SH ARGUMENTS
29.AS Tcl_ValueType *clientDataPtr out
30.AP Tcl_Interp *interp in
31Interpreter in which new function will be defined.
32.AP "const char" *name in
33Name for new function.
34.AP int numArgs in
35Number of arguments to new function;  also gives size of \fIargTypes\fR array.
36.AP Tcl_ValueType *argTypes in
37Points to an array giving the permissible types for each argument to
38function.
39.AP Tcl_MathProc *proc in
40Procedure that implements the function.
41.AP ClientData clientData in
42Arbitrary one-word value to pass to \fIproc\fR when it is invoked.
43.AP int *numArgsPtr out
44Points to a variable that will be set to contain the number of
45arguments to the function.
46.AP Tcl_ValueType **argTypesPtr out
47Points to a variable that will be set to contain a pointer to an array
48giving the permissible types for each argument to the function which
49will need to be freed up using \fITcl_Free\fR.
50.AP Tcl_MathProc **procPtr out
51Points to a variable that will be set to contain a pointer to the
52implementation code for the function (or NULL if the function is
53implemented directly in bytecode).
54.AP ClientData *clientDataPtr out
55Points to a variable that will be set to contain the clientData
56argument passed to \fITcl_CreateMathFunc\fR when the function was
57created if the function is not implemented directly in bytecode.
58.AP "const char" *pattern in
59Pattern to match against function names so as to filter them (by
60passing to \fITcl_StringMatch\fR), or NULL to not apply any filter.
61.BE
62
63.SH DESCRIPTION
64.PP
65Tcl allows a number of mathematical functions to be used in
66expressions, such as \fBsin\fR, \fBcos\fR, and \fBhypot\fR.
67These functions are represented by commands in the namespace,
68\fBtcl::mathfunc\fR.  The \fBTcl_CreateMathFunc\fR function is
69an obsolete way for applications to add additional functions
70to those already provided by Tcl or to replace existing functions.
71It should not be used by new applications, which should create
72math functions using \fBTcl_CreateObjCommand\fR to create a command
73in the \fBtcl::mathfunc\fR namespace.
74.PP
75In the \fBTcl_CreateMathFunc\fR interface,
76\fIName\fR is the name of the function as it will appear in expressions.
77If \fIname\fR does not already exist in the \fB::tcl::mathfunc\fR
78namespace, then a new command is created in that namespace.
79If \fIname\fR does exist, then the existing function is replaced.
80\fINumArgs\fR and \fIargTypes\fR describe the arguments to the function.
81Each entry in the \fIargTypes\fR array must be
82one of \fBTCL_INT\fR, \fBTCL_DOUBLE\fR, \fBTCL_WIDE_INT\fR,
83or \fBTCL_EITHER\fR to indicate whether the corresponding argument must be an
84integer, a double-precision floating value, a wide (64-bit) integer,
85or any, respectively.
86.PP
87Whenever the function is invoked in an expression Tcl will invoke
88\fIproc\fR.  \fIProc\fR should have arguments and result that match
89the type \fBTcl_MathProc\fR:
90.CS
91typedef int Tcl_MathProc(
92        ClientData \fIclientData\fR,
93        Tcl_Interp *\fIinterp\fR,
94        Tcl_Value *\fIargs\fR,
95        Tcl_Value *\fIresultPtr\fR);
96.CE
97.PP
98When \fIproc\fR is invoked the \fIclientData\fR and \fIinterp\fR
99arguments will be the same as those passed to \fBTcl_CreateMathFunc\fR.
100\fIArgs\fR will point to an array of \fInumArgs\fR Tcl_Value structures,
101which describe the actual arguments to the function:
102.CS
103typedef struct Tcl_Value {
104        Tcl_ValueType \fItype\fR;
105        long \fIintValue\fR;
106        double \fIdoubleValue\fR;
107        Tcl_WideInt \fIwideValue\fR;
108} Tcl_Value;
109.CE
110.PP
111The \fItype\fR field indicates the type of the argument and is
112one of \fBTCL_INT\fR, \fBTCL_DOUBLE\fR or \fBTCL_WIDE_INT\fR.
113It will match the \fIargTypes\fR value specified for the function unless
114the \fIargTypes\fR value was \fBTCL_EITHER\fR. Tcl converts
115the argument supplied in the expression to the type requested in
116\fIargTypes\fR, if that is necessary.
117Depending on the value of the \fItype\fR field, the \fIintValue\fR,
118\fIdoubleValue\fR or \fIwideValue\fR
119field will contain the actual value of the argument.
120.PP
121\fIProc\fR should compute its result and store it either as an integer
122in \fIresultPtr->intValue\fR or as a floating value in
123\fIresultPtr->doubleValue\fR.
124It should set also \fIresultPtr->type\fR to one of
125\fBTCL_INT\fR, \fBTCL_DOUBLE\fR or \fBTCL_WIDE_INT\fR
126to indicate which value was set.
127Under normal circumstances \fIproc\fR should return \fBTCL_OK\fR.
128If an error occurs while executing the function, \fIproc\fR should
129return \fBTCL_ERROR\fR and leave an error message in the interpreter's result.
130.PP
131\fBTcl_GetMathFuncInfo\fR retrieves the values associated with
132function \fIname\fR that were passed to a preceding
133\fBTcl_CreateMathFunc\fR call.  Normally, the return code is
134\fBTCL_OK\fR but if the named function does not exist, \fBTCL_ERROR\fR
135is returned and an error message is placed in the interpreter's
136result.
137.PP
138If an error did not occur, the array reference placed in the variable
139pointed to by \fIargTypesPtr\fR is newly allocated, and should be
140released by passing it to \fBTcl_Free\fR.  Some functions (the
141standard set implemented in the core, and those defined by placing
142commands in the \fBtcl::mathfunc\fR namespace) do not have
143argument type information; attempting to retrieve values for
144them causes a NULL to be stored in the variable pointed to by
145\fIprocPtr\fR and the variable pointed to by \fIclientDataPtr\fR
146will not be modified.  The variable pointed to by \fInumArgsPointer\fR
147will contain -1, and no argument types will be stored in the variable
148pointed to by \fIargTypesPointer\fR.
149.PP
150\fBTcl_ListMathFuncs\fR returns a Tcl object containing a list of all
151the math functions defined in the interpreter whose name matches
152\fIpattern\fR.  The returned object has a reference count of zero.
153
154.SH "SEE ALSO"
155expr(n), info(n), Tcl_CreateObjCommand(3), Tcl_Free(3), Tcl_NewListObj(3)
156
157.SH KEYWORDS
158expression, mathematical function
Note: See TracBrowser for help on using the repository browser.