home *** CD-ROM | disk | FTP | other *** search
- /*
- * tclMatherr.c --
- *
- * This function provides a default implementation of the
- * "matherr" function, for SYS-V systems where it's needed.
- *
- * Copyright (c) 1993 The Regents of the University of California.
- * All rights reserved.
- *
- * Permission is hereby granted, without written agreement and without
- * license or royalty fees, to use, copy, modify, and distribute this
- * software and its documentation for any purpose, provided that the
- * above copyright notice and the following two paragraphs appear in
- * all copies of this software.
- *
- * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
- * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
- * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
- * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
- * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
- * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /user6/ouster/tcl/RCS/tclMtherr.c,v 1.3 93/06/03 10:36:22 ouster Exp $ SPRITE (Berkeley)";
- #endif /* not lint */
-
- #include "tclInt.h"
- #ifndef TCL_NO_MATH
- #include <math.h>
- #endif
-
- /*
- * The stuff below is a bit of a hack so that this file can be used
- * in environments that include no UNIX, i.e. no errno. Just define
- * errno here.
- */
-
- #ifndef TCL_GENERIC_ONLY
- #include "tclUnix.h"
- #else
- int errno;
- #define EDOM 33
- #define ERANGE 34
- #endif
-
- /*
- * The following variable is secretly shared with Tcl so we can
- * tell if expression evaluation is in progress. If not, matherr
- * just emulates the default behavior, which includes printing
- * a message.
- */
-
- extern int tcl_MathInProgress;
-
- /*
- * Define a dummy "struct exception" structure if none already exists.
- * The "OVERFLOW" #define is tested to see whether matherr stuff has
- * been defined in math.h (struct exception is only defined if the
- * matherr stuff is defined).
- */
-
- #ifndef OVERFLOW
- struct exception {
- int type;
- };
- #define DOMAIN 0
- #define SING 1
- #endif
-
- /*
- *----------------------------------------------------------------------
- *
- * matherr --
- *
- * This procedure is invoked on Sys-V systems when certain
- * errors occur in mathematical functions. Type "man matherr"
- * for more information on how this function works.
- *
- * Results:
- * Returns 1 to indicate that we've handled the error
- * locally.
- *
- * Side effects:
- * Sets errno based on what's in xPtr.
- *
- *----------------------------------------------------------------------
- */
-
- int
- matherr(xPtr)
- struct exception *xPtr; /* Describes error that occurred. */
- {
- if (!tcl_MathInProgress) {
- return 0;
- }
- if ((xPtr->type == DOMAIN) || (xPtr->type == SING)) {
- errno = EDOM;
- } else {
- errno = ERANGE;
- }
- return 1;
- }
-