1/* err/gsl_errno.h
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#ifndef __GSL_ERRNO_H__
21#define __GSL_ERRNO_H__
22
23#include <stdio.h>
24#include <errno.h>
25#include <gsl/gsl_types.h>
26
27#undef __BEGIN_DECLS
28#undef __END_DECLS
29#ifdef __cplusplus
30# define __BEGIN_DECLS extern "C" {
31# define __END_DECLS }
32#else
33# define __BEGIN_DECLS /* empty */
34# define __END_DECLS /* empty */
35#endif
36
37__BEGIN_DECLS
38
39enum {
40 GSL_SUCCESS = 0,
41 GSL_FAILURE = -1,
42 GSL_CONTINUE = -2, /* iteration has not converged */
43 GSL_EDOM = 1, /* input domain error, e.g sqrt(-1) */
44 GSL_ERANGE = 2, /* output range error, e.g. exp(1e100) */
45 GSL_EFAULT = 3, /* invalid pointer */
46 GSL_EINVAL = 4, /* invalid argument supplied by user */
47 GSL_EFAILED = 5, /* generic failure */
48 GSL_EFACTOR = 6, /* factorization failed */
49 GSL_ESANITY = 7, /* sanity check failed - shouldn't happen */
50 GSL_ENOMEM = 8, /* malloc failed */
51 GSL_EBADFUNC = 9, /* problem with user-supplied function */
52 GSL_ERUNAWAY = 10, /* iterative process is out of control */
53 GSL_EMAXITER = 11, /* exceeded max number of iterations */
54 GSL_EZERODIV = 12, /* tried to divide by zero */
55 GSL_EBADTOL = 13, /* user specified an invalid tolerance */
56 GSL_ETOL = 14, /* failed to reach the specified tolerance */
57 GSL_EUNDRFLW = 15, /* underflow */
58 GSL_EOVRFLW = 16, /* overflow */
59 GSL_ELOSS = 17, /* loss of accuracy */
60 GSL_EROUND = 18, /* failed because of roundoff error */
61 GSL_EBADLEN = 19, /* matrix, vector lengths are not conformant */
62 GSL_ENOTSQR = 20, /* matrix not square */
63 GSL_ESING = 21, /* apparent singularity detected */
64 GSL_EDIVERGE = 22, /* integral or series is divergent */
65 GSL_EUNSUP = 23, /* requested feature is not supported by the hardware */
66 GSL_EUNIMPL = 24, /* requested feature not (yet) implemented */
67 GSL_ECACHE = 25, /* cache limit exceeded */
68 GSL_ETABLE = 26, /* table limit exceeded */
69 GSL_ENOPROG = 27, /* iteration is not making progress towards solution */
70 GSL_ENOPROGJ = 28, /* jacobian evaluations are not improving the solution */
71 GSL_ETOLF = 29, /* cannot reach the specified tolerance in F */
72 GSL_ETOLX = 30, /* cannot reach the specified tolerance in X */
73 GSL_ETOLG = 31, /* cannot reach the specified tolerance in gradient */
74 GSL_EOF = 32 /* end of file */
75} ;
76
77void gsl_error (const char * reason, const char * file, int line,
78 int gsl_errno);
79
80void gsl_stream_printf (const char *label, const char *file,
81 int line, const char *reason);
82
83const char * gsl_strerror (const int gsl_errno);
84
85typedef void gsl_error_handler_t (const char * reason, const char * file,
86 int line, int gsl_errno);
87
88typedef void gsl_stream_handler_t (const char * label, const char * file,
89 int line, const char * reason);
90
91gsl_error_handler_t *
92gsl_set_error_handler (gsl_error_handler_t * new_handler);
93
94gsl_error_handler_t *
95gsl_set_error_handler_off (void);
96
97gsl_stream_handler_t *
98gsl_set_stream_handler (gsl_stream_handler_t * new_handler);
99
100FILE * gsl_set_stream (FILE * new_stream);
101
102/* GSL_ERROR: call the error handler, and return the error code */
103
104#define GSL_ERROR(reason, gsl_errno) \
105 do { \
106 gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
107 return gsl_errno ; \
108 } while (0)
109
110/* GSL_ERROR_VAL: call the error handler, and return the given value */
111
112#define GSL_ERROR_VAL(reason, gsl_errno, value) \
113 do { \
114 gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
115 return value ; \
116 } while (0)
117
118/* GSL_ERROR_VOID: call the error handler, and then return
119 (for void functions which still need to generate an error) */
120
121#define GSL_ERROR_VOID(reason, gsl_errno) \
122 do { \
123 gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
124 return ; \
125 } while (0)
126
127/* GSL_ERROR_NULL suitable for out-of-memory conditions */
128
129#define GSL_ERROR_NULL(reason, gsl_errno) GSL_ERROR_VAL(reason, gsl_errno, 0)
130
131/* Sometimes you have several status results returned from
132 * function calls and you want to combine them in some sensible
133 * way. You cannot produce a "total" status condition, but you can
134 * pick one from a set of conditions based on an implied hierarchy.
135 *
136 * In other words:
137 * you have: status_a, status_b, ...
138 * you want: status = (status_a if it is bad, or status_b if it is bad,...)
139 *
140 * In this example you consider status_a to be more important and
141 * it is checked first, followed by the others in the order specified.
142 *
143 * Here are some dumb macros to do this.
144 */
145#define GSL_ERROR_SELECT_2(a,b) ((a) != GSL_SUCCESS ? (a) : ((b) != GSL_SUCCESS ? (b) : GSL_SUCCESS))
146#define GSL_ERROR_SELECT_3(a,b,c) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_2(b,c))
147#define GSL_ERROR_SELECT_4(a,b,c,d) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_3(b,c,d))
148#define GSL_ERROR_SELECT_5(a,b,c,d,e) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_4(b,c,d,e))
149
150#define GSL_STATUS_UPDATE(sp, s) do { if ((s) != GSL_SUCCESS) *(sp) = (s);} while(0)
151
152__END_DECLS
153
154#endif /* __GSL_ERRNO_H__ */
155