Tcl_CreateMathFunc, Tcl_GetMathFuncInfo, Tcl_ListMathFuncs − Define, query and enumerate math functions for expressions


#include <tcl.h>

(interp, name, numArgs, argTypes, proc, clientData)

(interp, name, numArgsPtr, argTypesPtr, procPtr,

Tcl_Obj *
(interp, pattern)


Tcl_Interp *interp (in)

Interpreter in which new function will be defined.

const char *name (in)

Name for new function.

int numArgs (in)

Number of arguments to new function; also gives size of argTypes array.

Tcl_ValueType *argTypes (in)

Points to an array giving the permissible types for each argument to function.

Tcl_MathProc *proc (in)

Procedure that implements the function.

ClientData clientData (in)

Arbitrary one-word value to pass to proc when it is invoked.

int *numArgsPtr (out)

Points to a variable that will be set to contain the number of arguments to the function.

Tcl_ValueType **argTypesPtr (out)

Points to a variable that will be set to contain a pointer to an array giving the permissible types for each argument to the function which will need to be freed up using Tcl_Free.

Tcl_MathProc **procPtr (out)

Points to a variable that will be set to contain a pointer to the implementation code for the function (or NULL if the function is implemented directly in bytecode).

ClientData *clientDataPtr (out)

Points to a variable that will be set to contain the clientData argument passed to Tcl_CreateMathFunc when the function was created if the function is not implemented directly in bytecode.

const char *pattern (in)

Pattern to match against function names so as to filter them (by passing to Tcl_StringMatch), or NULL to not apply any filter.



Tcl allows a number of mathematical functions to be used in expressions, such as sin, cos, and hypot. These functions are represented by commands in the namespace, tcl::mathfunc. The Tcl_CreateMathFunc function is an obsolete way for applications to add additional functions to those already provided by Tcl or to replace existing functions. It should not be used by new applications, which should create math functions using Tcl_CreateObjCommand to create a command in the tcl::mathfunc namespace.

In the Tcl_CreateMathFunc interface, Name is the name of the function as it will appear in expressions. If name does not already exist in the ::tcl::mathfunc namespace, then a new command is created in that namespace. If name does exist, then the existing function is replaced. NumArgs and argTypes describe the arguments to the function. Each entry in the argTypes array must be one of TCL_INT, TCL_DOUBLE, TCL_WIDE_INT, or TCL_EITHER to indicate whether the corresponding argument must be an integer, a double-precision floating value, a wide (64-bit) integer, or any, respectively.

Whenever the function is invoked in an expression Tcl will invoke proc. Proc should have arguments and result that match the type Tcl_MathProc:

typedef int Tcl_MathProc(
ClientData clientData,
Tcl_Interp *interp,
Tcl_Value *args,
Tcl_Value *resultPtr);

When proc is invoked the clientData and interp arguments will be the same as those passed to Tcl_CreateMathFunc. Args will point to an array of numArgs Tcl_Value structures, which describe the actual arguments to the function:

typedef struct Tcl_Value {
Tcl_ValueType type;
long intValue;
double doubleValue;
Tcl_WideInt wideValue;
} Tcl_Value;

The type field indicates the type of the argument and is one of TCL_INT, TCL_DOUBLE or TCL_WIDE_INT. It will match the argTypes value specified for the function unless the argTypes value was TCL_EITHER. Tcl converts the argument supplied in the expression to the type requested in argTypes, if that is necessary. Depending on the value of the type field, the intValue, doubleValue or wideValue field will contain the actual value of the argument.

Proc should compute its result and store it either as an integer in resultPtr->intValue or as a floating value in resultPtr->doubleValue. It should set also resultPtr->type to one of TCL_INT, TCL_DOUBLE or TCL_WIDE_INT to indicate which value was set. Under normal circumstances proc should return TCL_OK. If an error occurs while executing the function, proc should return TCL_ERROR and leave an error message in the interpreter’s result.

Tcl_GetMathFuncInfo retrieves the values associated with function name that were passed to a preceding Tcl_CreateMathFunc call. Normally, the return code is TCL_OK but if the named function does not exist, TCL_ERROR is returned and an error message is placed in the interpreter’s result.

If an error did not occur, the array reference placed in the variable pointed to by argTypesPtr is newly allocated, and should be released by passing it to Tcl_Free. Some functions (the standard set implemented in the core, and those defined by placing commands in the tcl::mathfunc namespace) do not have argument type information; attempting to retrieve values for them causes a NULL to be stored in the variable pointed to by procPtr and the variable pointed to by clientDataPtr will not be modified. The variable pointed to by numArgsPointer will contain -1, and no argument types will be stored in the variable pointed to by argTypesPointer.

Tcl_ListMathFuncs returns a Tcl object containing a list of all the math functions defined in the interpreter whose name matches pattern. The returned object has a reference count of zero.


expr(n), info(n), Tcl_CreateObjCommand(3), Tcl_Free(3), Tcl_NewListObj(3)


expression, mathematical function

More Linux Commands

XtSetValues(3) - obtain and set widget resources (Man Page)
The XtSetValues function starts with the resources specified for the Core widget fields and proceeds down the subclass chain to the widget. At each stage, it wr

gnutls_compression_get(3) - API function - Linux man page...
Get currently used compression algorithm. RETURNS the currently used compression method, a gnutls_compression_method_t value. REPORTING BUGS Report bugs to &lt;bug

Tk_DeleteBinding(3) - invoke scripts in response to X events
These procedures provide a general-purpose mechanism for creating and invoking bindings. Bindings are organized in terms of binding tables. A binding table cons

post_form(3form) - write or erase forms from associated subw
The function post_form displays a form to its associated subwindow. To trigger physical display of the subwindow, use refresh or some equivalent curses routine

cerfc(3) - complex error function - Linux manual page.......
The (unimplemented) function cerf() is the complex version of the error function. erf(z) = 2/sqrt(pi) * integral from 0 to z of exp(-t*t) dt. The function cerfc

iso-8859-6(7) - ISO 8859-6 character set encoded in octal, d
The ISO 8859 standard includes several 8-bit extensions to the ASCII character set (also known as ISO 646-IRV). ISO 8859-6 encodes the characters used in the Ar

argz_create_sep(3) - functions to handle an argz list.......
These functions are glibc-specific. An argz vector is a pointer to a character buffer together with a length. The intended interpretation of the character buffe

openvpn(8) - secure IP tunnel daemon. - Linux manual page...
OpenVPN is a robust and highly flexible VPN daemon. OpenVPN supports SSL/TLS security, ethernet bridging, TCP or UDP tunnel transport through proxies or NAT, su

postlock(1) - lock mail folder and execute command (ManPage)
The postlock(1) command locks file for exclusive access, and executes command. The locking method is compatible with the Postfix UNIX-style local delivery agent

ldap_matchingrule2name(3) - Schema definition handling routi
These routines are used to parse schema definitions in the syntax defined in RFC 4512 into structs and handle these structs. These routines handle four kinds of

getcpu(2) - determine CPU and NUMA node on which the calling
The getcpu() system call identifies the processor and node on which the calling thread or process is currently running and writes them into the integers pointed

send-uucp(8) - Send Usenet articles via UUCP (Man Page).....
The send-uucp program processes batch files written by innd(8) to send Usenet articles to UUCP sites. It reads a configuration file to control how it behaves wi

We can't live, work or learn in freedom unless the software we use is free.