gsl_errno.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #ifndef __GSL_ERRNO_H__
  20. #define __GSL_ERRNO_H__
  21. #include <stdio.h>
  22. #include <errno.h>
  23. #include "gsl_types.h"
  24. #undef __BEGIN_DECLS
  25. #undef __END_DECLS
  26. #ifdef __cplusplus
  27. # define __BEGIN_DECLS extern "C" {
  28. # define __END_DECLS }
  29. #else
  30. # define __BEGIN_DECLS /* empty */
  31. # define __END_DECLS /* empty */
  32. #endif
  33. __BEGIN_DECLS
  34. enum {
  35. GSL_SUCCESS = 0,
  36. GSL_FAILURE = -1,
  37. GSL_CONTINUE = -2, /* iteration has not converged */
  38. GSL_EDOM = 1, /* input domain error, e.g sqrt(-1) */
  39. GSL_ERANGE = 2, /* output range error, e.g. exp(1e100) */
  40. GSL_EFAULT = 3, /* invalid pointer */
  41. GSL_EINVAL = 4, /* invalid argument supplied by user */
  42. GSL_EFAILED = 5, /* generic failure */
  43. GSL_EFACTOR = 6, /* factorization failed */
  44. GSL_ESANITY = 7, /* sanity check failed - shouldn't happen */
  45. GSL_ENOMEM = 8, /* malloc failed */
  46. GSL_EBADFUNC = 9, /* problem with user-supplied function */
  47. GSL_ERUNAWAY = 10, /* iterative process is out of control */
  48. GSL_EMAXITER = 11, /* exceeded max number of iterations */
  49. GSL_EZERODIV = 12, /* tried to divide by zero */
  50. GSL_EBADTOL = 13, /* user specified an invalid tolerance */
  51. GSL_ETOL = 14, /* failed to reach the specified tolerance */
  52. GSL_EUNDRFLW = 15, /* underflow */
  53. GSL_EOVRFLW = 16, /* overflow */
  54. GSL_ELOSS = 17, /* loss of accuracy */
  55. GSL_EROUND = 18, /* failed because of roundoff error */
  56. GSL_EBADLEN = 19, /* matrix, vector lengths are not conformant */
  57. GSL_ENOTSQR = 20, /* matrix not square */
  58. GSL_ESING = 21, /* apparent singularity detected */
  59. GSL_EDIVERGE = 22, /* integral or series is divergent */
  60. GSL_EUNSUP = 23, /* requested feature is not supported by the hardware */
  61. GSL_EUNIMPL = 24, /* requested feature not (yet) implemented */
  62. GSL_ECACHE = 25, /* cache limit exceeded */
  63. GSL_ETABLE = 26, /* table limit exceeded */
  64. GSL_ENOPROG = 27, /* iteration is not making progress towards solution */
  65. GSL_ENOPROGJ = 28, /* jacobian evaluations are not improving the solution */
  66. GSL_ETOLF = 29, /* cannot reach the specified tolerance in F */
  67. GSL_ETOLX = 30, /* cannot reach the specified tolerance in X */
  68. GSL_ETOLG = 31, /* cannot reach the specified tolerance in gradient */
  69. GSL_EOF = 32 /* end of file */
  70. } ;
  71. void gsl_error (const char * reason, const char * file, int line,
  72. int gsl_errno);
  73. void gsl_stream_printf (const char *label, const char *file,
  74. int line, const char *reason);
  75. const char * gsl_strerror (const int gsl_errno);
  76. typedef void gsl_error_handler_t (const char * reason, const char * file,
  77. int line, int gsl_errno);
  78. typedef void gsl_stream_handler_t (const char * label, const char * file,
  79. int line, const char * reason);
  80. gsl_error_handler_t *
  81. gsl_set_error_handler (gsl_error_handler_t * new_handler);
  82. gsl_error_handler_t *
  83. gsl_set_error_handler_off (void);
  84. gsl_stream_handler_t *
  85. gsl_set_stream_handler (gsl_stream_handler_t * new_handler);
  86. FILE * gsl_set_stream (FILE * new_stream);
  87. /* GSL_ERROR: call the error handler, and return the error code */
  88. #define GSL_ERROR(reason, gsl_errno) \
  89. do { \
  90. gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
  91. return gsl_errno ; \
  92. } while (0)
  93. /* GSL_ERROR_VAL: call the error handler, and return the given value */
  94. #define GSL_ERROR_VAL(reason, gsl_errno, value) \
  95. do { \
  96. gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
  97. return value ; \
  98. } while (0)
  99. /* GSL_ERROR_VOID: call the error handler, and then return
  100. (for void functions which still need to generate an error) */
  101. #define GSL_ERROR_VOID(reason, gsl_errno) \
  102. do { \
  103. gsl_error (reason, __FILE__, __LINE__, gsl_errno) ; \
  104. return ; \
  105. } while (0)
  106. /* GSL_ERROR_NULL suitable for out-of-memory conditions */
  107. #define GSL_ERROR_NULL(reason, gsl_errno) GSL_ERROR_VAL(reason, gsl_errno, 0)
  108. /* Sometimes you have several status results returned from
  109. * function calls and you want to combine them in some sensible
  110. * way. You cannot produce a "total" status condition, but you can
  111. * pick one from a set of conditions based on an implied hierarchy.
  112. *
  113. * In other words:
  114. * you have: status_a, status_b, ...
  115. * you want: status = (status_a if it is bad, or status_b if it is bad,...)
  116. *
  117. * In this example you consider status_a to be more important and
  118. * it is checked first, followed by the others in the order specified.
  119. *
  120. * Here are some dumb macros to do this.
  121. */
  122. #define GSL_ERROR_SELECT_2(a,b) ((a) != GSL_SUCCESS ? (a) : ((b) != GSL_SUCCESS ? (b) : GSL_SUCCESS))
  123. #define GSL_ERROR_SELECT_3(a,b,c) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_2(b,c))
  124. #define GSL_ERROR_SELECT_4(a,b,c,d) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_3(b,c,d))
  125. #define GSL_ERROR_SELECT_5(a,b,c,d,e) ((a) != GSL_SUCCESS ? (a) : GSL_ERROR_SELECT_4(b,c,d,e))
  126. #define GSL_STATUS_UPDATE(sp, s) do { if ((s) != GSL_SUCCESS) *(sp) = (s);} while(0)
  127. __END_DECLS
  128. #endif /* __GSL_ERRNO_H__ */