Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > bd5c3d824c3db63ffd9226c15941e6ad > files > 2042

mozart-1.4.0-1mdv2010.0.i586.rpm

<HTML><HEAD><TITLE>Tcl Library Procedures - Tcl_CreateMathFunc manual page</TITLE></HEAD><BODY>
<H3><A NAME="M2">NAME</A></H3>
Tcl_CreateMathFunc - Define a new math function for expressions
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tcl.h&gt;</B><BR>
<B>Tcl_CreateMathFunc</B>(<I>interp, name, numArgs, argTypes, proc, clientData</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL>
<P><DT><A HREF="../TclLib/Interp.htm">Tcl_Interp</A> <B>*interp</B> (in)<DD>
Interpreter in which new function will be defined.
<P><DT>char <B>*name</B> (in)<DD>
Name for new function.
<P><DT>int <B>numArgs</B> (in)<DD>
Number of arguments to new function;  also gives size of <I>argTypes</I> array.
<P><DT>Tcl_ValueType <B>*argTypes</B> (in)<DD>
Points to an array giving the permissible types for each argument to
function.
<P><DT>Tcl_MathProc <B>*proc</B> (in)<DD>
Procedure that implements the function.
<P><DT>ClientData <B>clientData</B> (in)<DD>
Arbitrary one-word value to pass to <I>proc</I> when it is invoked.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
Tcl allows a number of mathematical functions to be used in
expressions, such as <B>sin</B>, <B>cos</B>, and <B>hypot</B>.
<B>Tcl_CreateMathFunc</B> allows applications to add additional functions
to those already provided by Tcl or to replace existing functions.
<I>Name</I> is the name of the function as it will appear in expressions.
If <I>name</I> doesn't already exist as a function then a new function
is created.  If it does exist, then the existing function is replaced.
<I>NumArgs</I> and <I>argTypes</I> describe the arguments to the function.
Each entry in the <I>argTypes</I> array 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.
<P>
Whenever the function is invoked in an expression Tcl will invoke
<I>proc</I>.  <I>Proc</I> should have arguments and result that match
the type <B>Tcl_MathProc</B>:
<PRE>typedef int Tcl_MathProc(
	ClientData <I>clientData</I>,
	<A HREF="../TclLib/Interp.htm">Tcl_Interp</A> *<I>interp</I>,
	Tcl_Value *<I>args</I>,
	Tcl_Value *<I>resultPtr</I>);</PRE>
<P>
When <I>proc</I> is invoked the <I>clientData</I> and <I>interp</I>
arguments will be the same as those passed to <B>Tcl_CreateMathFunc</B>.
<I>Args</I> will point to an array of <I>numArgs</I> Tcl_Value structures,
which describe the actual arguments to the function:
<PRE>typedef struct Tcl_Value {
	Tcl_ValueType <I>type</I>;
	long <I>intValue</I>;
	double <I>doubleValue</I>;
} Tcl_Value;</PRE>
<P>
The <I>type</I> field indicates the type of the argument and is
either TCL_INT or TCL_DOUBLE.
It will match the <I>argTypes</I> value specified for the function unless
the <I>argTypes</I> value was TCL_EITHER. Tcl converts
the argument supplied in the expression to the type requested in
<I>argTypes</I>, if that is necessary.
Depending on the value of the <I>type</I> field, the <I>intValue</I>
or <I>doubleValue</I> field will contain the actual value of the argument.
<P>
<I>Proc</I> should compute its result and store it either as an integer
in <I>resultPtr-&gt;intValue</I> or as a floating value in
<I>resultPtr-&gt;doubleValue</I>.
It should set also <I>resultPtr-&gt;type</I> to either TCL_INT or TCL_DOUBLE
to indicate which value was set.
Under normal circumstances <I>proc</I> should return TCL_OK.
If an error occurs while executing the function, <I>proc</I> should
return TCL_ERROR and leave an error message in <I>interp-&gt;result</I>.

<H3><A NAME="M6">KEYWORDS</A></H3>
<A href="../Keywords/E.htm#expression">expression</A>, <A href="../Keywords/M.htm#mathematical function">mathematical function</A>
<HR><PRE>
<A HREF="../copyright.htm">Copyright</A> &#169; 1989-1993 The Regents of the University of California.
<A HREF="../copyright.htm">Copyright</A> &#169; 1994-1996 Sun Microsystems, Inc.
<A HREF="../copyright.htm">Copyright</A> &#169; 1995-1997 Roger E. Critchlow Jr.</PRE>
</BODY></HTML>