Debian Codegraph @

doc/CrtMathFnc.3

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