Tcl_CreateMathFunc(3) Tcl Library Procedures Tcl_CreateMathFunc(3) ______________________________________________________________________________ NAME Tcl_CreateMathFunc - Define a new math function for expressions SYNOPSIS#include <tcl.h>Tcl_CreateMathFunc(interp, name, numArgs, argTypes, proc, clientData) ARGUMENTS Tcl_Interp*interp(in) Interpreter in which new function will be defined. char*name(in) Name for new function. intnumArgs(in) Number of arguments to new function; also gives size ofargTypesarray. 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. ClientDataclientData(in) Arbitrary one-word value to pass toprocwhen it is invoked. _________________________________________________________________ DESCRIPTION Tcl allows a number of mathematical functions to be used in expressions, such assin,cos, andhypot.Tcl_CreateMathFuncallows applications to add additional functions to those already provided by Tcl or to replace existing functions.Nameis the name of the function as it will appear in expressions. Ifnamedoesn't already exist as a function then a new function is created. If it does exist, then the existing function is replaced.NumArgsandargTypesdescribe the arguments to the function. Each entry in theargTypesarray must be either TCL_INT, TCL_DOUBLE, or TCL_EITHER to indicate whether the corresponding argument must be an integer, a double-precision floating value, or either, respectively. Whenever the function is invoked in an expression Tcl will invokeproc.Procshould have arguments and result that match the typeTcl_MathProc: typedef int Tcl_MathProc( ClientDataclientData, Tcl_Interp *interp, Tcl_Value *args, Tcl_Value *resultPtr); Whenprocis invoked theclientDataandinterparguments will be the same as those passed toTcl_CreateMathFunc.Argswill point to an array ofnumArgsTcl_Value structures, which describe the actual arguments to the function: typedef struct Tcl_Value { Tcl_ValueTypetype; longintValue; doubledoubleValue; } Tcl_Value; Thetypefield indicates the type of the argument and is either TCL_INT or TCL_DOUBLE. It will match theargTypesvalue specified for the function unless theargTypesvalue was TCL_EITHER. Tcl converts the argument supplied in the expression to the type requested inargTypes, if that is necessary. Depending on the value of thetypefield, theintValueordoubleValuefield will contain the actual value of the argument.Procshould compute its result and store it either as an integer inresultPtr->intValueor as a floating value inresultPtr->doubleValue. It should set alsoresultPtr->typeto either TCL_INT or TCL_DOUBLE to indicate which value was set. Under normal circumstancesprocshould return TCL_OK. If an error occurs while executing the function,procshould return TCL_ERROR and leave an error message ininterp->result. KEYWORDS expression, mathematical function Tcl 7.0 Tcl_CreateMathFunc(3)