home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcl2-73c.zip / tcl7.3 / doc / CrtMathFnc.3 < prev    next >
Text File  |  1993-04-14  |  4KB  |  115 lines

  1. '\"
  2. '\" Copyright (c) 1989-1993 The Regents of the University of California.
  3. '\" All rights reserved.
  4. '\"
  5. '\" Permission is hereby granted, without written agreement and without
  6. '\" license or royalty fees, to use, copy, modify, and distribute this
  7. '\" documentation for any purpose, provided that the above copyright
  8. '\" notice and the following two paragraphs appear in all copies.
  9. '\"
  10. '\" IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
  11. '\" FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  12. '\" ARISING OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13. '\" CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. '\"
  15. '\" THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16. '\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17. '\" AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18. '\" ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19. '\" PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20. '\" 
  21. '\" $Header: /user6/ouster/tcl/man/RCS/CrtMathFnc.3,v 1.1 93/04/14 16:35:59 ouster Exp $ SPRITE (Berkeley)
  22. '\" 
  23. .so man.macros
  24. .HS Tcl_CreateMathFunc tclc 7.0
  25. .BS
  26. .SH NAME
  27. Tcl_CreateMathFunc \- Define a new math function for expressions
  28. .SH SYNOPSIS
  29. .nf
  30. \fB#include <tcl.h>\fR
  31. .sp
  32. \fBTcl_CreateMathFunc\fR(\fIinterp, name, numArgs, argTypes, proc, clientData\fR)
  33. .SH ARGUMENTS
  34. .AS Tcl_ValueType clientData
  35. .AP Tcl_Interp *interp in
  36. Interpreter in which new function will be defined.
  37. .AP 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. .BE
  49.  
  50. .SH DESCRIPTION
  51. .PP
  52. Tcl allows a number of mathematical functions to be used in
  53. expressions, such as \fBsin\fR, \fBcos\fR, and \fBhypot\fR.
  54. \fBTcl_CreateMathFunc\fR allows applications to add additional functions
  55. to those already provided by Tcl or to replace existing functions.
  56. \fIName\fR is the name of the function as it will appear in expressions.
  57. If \fIname\fR doesn't already exist as a function then a new function
  58. is created.  If it does exist, then the existing function is replaced.
  59. \fINumArgs\fR and \fIargTypes\fR describe the arguments to the function.
  60. Each entry in the \fIargTypes\fR array must be either TCL_INT, TCL_DOUBLE,
  61. or TCL_EITHER to indicate whether the corresponding argument must be an
  62. integer, a double-precision floating value, or either, respectively.
  63. .PP
  64. Whenever the function is invoked in an expression Tcl will invoke
  65. \fIproc\fR.  \fIProc\fR should have arguments and result that match
  66. the type \fBTcl_MathProc\fR:
  67. .nf
  68. .RS
  69. typedef int Tcl_MathProc(
  70. .RS
  71. ClientData \fIclientData\fR,
  72. Tcl_Interp *\fIinterp\fR,
  73. Tcl_Value *\fIargs\fR,
  74. Tcl_Value *resultPtr\fR);
  75. .RE
  76. .RE
  77. .fi
  78. .PP
  79. When \fIproc\fR is invoked the \fIclientData\fR and \fIinterp\fR
  80. arguments will be the same as those passed to \fBTcl_CreateMathFunc\fR.
  81. \fIArgs\fR will point to an array of \fInumArgs\fR Tcl_Value structures,
  82. which describe the actual arguments to the function:
  83. .nf
  84. .RS
  85. typedef struct Tcl_Value {
  86. .RS
  87. Tcl_ValueType \fItype\fR;
  88. int \fIintValue\fR;
  89. double \fIdoubleValue\fR;
  90. .RE
  91. } Tcl_Value;
  92. .RE
  93. .fi
  94. .PP
  95. The \fItype\fR field indicates the type of the argument and is
  96. either TCL_INT or TCL_DOUBLE.
  97. It will match the \fIargTypes\fR value specified for the function unless
  98. the \fIargTypes\fR value was TCL_EITHER. Tcl converts
  99. the argument supplied in the expression to the type requested in
  100. \fIargTypes\fR, if that is necessary.
  101. Depending on the value of the \fItype\fR field, the \fIintValue\fR
  102. or \fIdoubleValue\fR field will contain the actual value of the argument.
  103. .PP
  104. \fIProc\fR should compute its result and store it either as an integer
  105. in \fIresultPtr->intValue\fR or as a floating value in
  106. \fIresultPtr->doubleValue\fR.
  107. It should set also \fIresultPtr->type\fR to either TCL_INT or TCL_DOUBLE
  108. to indicate which value was set.
  109. Under normal circumstances \fIproc\fR should return TCL_OK.
  110. If an error occurs while executing the function, \fIproc\fR should
  111. return TCL_ERROR and leave an error message in \fIinterp->result\fR.
  112.  
  113. .SH KEYWORDS
  114. expression, mathematical function
  115.