xref: /openbsd/regress/lib/libc/cephes/mtherr.c (revision b7275c88)
1 /*	$OpenBSD: mtherr.c,v 1.1 2011/07/02 18:11:01 martynas Exp $	*/
2 
3 /*
4  * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*							mtherr.c
20  *
21  *	Library common error handling routine
22  *
23  *
24  *
25  * SYNOPSIS:
26  *
27  * char *fctnam;
28  * int code;
29  * int mtherr();
30  *
31  * mtherr( fctnam, code );
32  *
33  *
34  *
35  * DESCRIPTION:
36  *
37  * This routine may be called to report one of the following
38  * error conditions (in the include file mconf.h).
39  *
40  *   Mnemonic        Value          Significance
41  *
42  *    DOMAIN            1       argument domain error
43  *    SING              2       function singularity
44  *    OVERFLOW          3       overflow range error
45  *    UNDERFLOW         4       underflow range error
46  *    TLOSS             5       total loss of precision
47  *    PLOSS             6       partial loss of precision
48  *    EDOM             33       Unix domain error code
49  *    ERANGE           34       Unix range error code
50  *
51  * The default version of the file prints the function name,
52  * passed to it by the pointer fctnam, followed by the
53  * error condition.  The display is directed to the standard
54  * output device.  The routine then returns to the calling
55  * program.  Users may wish to modify the program to abort by
56  * calling exit() under severe error conditions such as domain
57  * errors.
58  *
59  * Since all error conditions pass control to this function,
60  * the display may be easily changed, eliminated, or directed
61  * to an error logging device.
62  *
63  * SEE ALSO:
64  *
65  * mconf.h
66  *
67  */
68 
69 #include <stdio.h>
70 #include "mconf.h"
71 
72 int merror = 0;
73 
74 /* Notice: the order of appearance of the following
75  * messages is bound to the error codes defined
76  * in mconf.h.
77  */
78 static char *ermsg[7] = {
79 "unknown",      /* error code 0 */
80 "domain",       /* error code 1 */
81 "singularity",  /* et seq.      */
82 "overflow",
83 "underflow",
84 "total loss of precision",
85 "partial loss of precision"
86 };
87 
88 
mtherr(name,code)89 int mtherr( name, code )
90 char *name;
91 int code;
92 {
93 
94 /* Display string passed by calling program,
95  * which is supposed to be the name of the
96  * function in which the error occurred:
97  */
98 printf( "\n%s ", name );
99 
100 /* Set global error message word */
101 merror = code;
102 
103 /* Display error message defined
104  * by the code argument.
105  */
106 if( (code <= 0) || (code >= 7) )
107 	code = 0;
108 printf( "%s error\n", ermsg[code] );
109 
110 /* Return to calling
111  * program
112  */
113 return( 0 );
114 }
115