6#ifndef THEORETICA_ERROR_H
7#define THEORETICA_ERROR_H
9#if defined(THEORETICA_THROW_EXCEPTIONS) || defined(THEORETICA_ONLY_EXCEPTIONS)
13#ifndef THEORETICA_NO_PRINT
32 IMPOSSIBLE_OPERATION = 0x08,
33 NO_ALGO_CONVERGENCE = 0x10,
34 INVALID_ARGUMENT = 0x20
41 case NO_ERROR:
return 0;
break;
42 case DIV_BY_ZERO:
return ERANGE;
break;
43 case OUT_OF_DOMAIN:
return EDOM;
break;
44 case OUT_OF_RANGE:
return ERANGE;
break;
45 case IMPOSSIBLE_OPERATION:
return EDOM;
break;
46 case NO_ALGO_CONVERGENCE:
return ERANGE;
break;
47 case INVALID_ARGUMENT:
return EINVAL;
break;
48 default:
return 0;
break;
55 return std::numeric_limits<real>::quiet_NaN();
77 return std::numeric_limits<real>::infinity();
83 return (x ==
inf()) || (x == -
inf());
87#if defined(THEORETICA_THROW_EXCEPTIONS) || defined(THEORETICA_ONLY_EXCEPTIONS)
111 case NO_ERROR:
return "No error";
break;
112 case DIV_BY_ZERO:
return "Division by zero";
break;
114 return "An argument was out of the domain of the called function";
break;
115 case IMPOSSIBLE_OPERATION:
116 return "A mathematically impossible operation was requested";
break;
117 case NO_ALGO_CONVERGENCE:
return "The algorithm did not converge";
break;
118 case INVALID_ARGUMENT:
return "Invalid argument size or value";
break;
119 default:
return "Unknown error";
break;
154#ifndef THEORETICA_NO_PRINT
157 inline std::string to_string()
const {
165 case NO_ERROR:
err_str <<
"No error";
break;
166 case DIV_BY_ZERO:
err_str <<
"Division by zero";
break;
168 err_str <<
"An argument was out of the domain of the called function";
break;
169 case IMPOSSIBLE_OPERATION:
170 err_str <<
"A mathematically impossible operation was requested";
break;
171 case NO_ALGO_CONVERGENCE:
err_str <<
"The algorithm did not converge";
break;
172 case INVALID_ARGUMENT:
err_str <<
"Invalid argument size or value";
break;
173 default:
err_str <<
"Unknown error";
break;
181 inline operator std::string() {
189 return out <<
obj.to_string();
207#ifdef THEORETICA_ONLY_EXCEPTIONS
209#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
210 { throw math_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, VALUE); }
212#define TH_MATH_ERROR_R(F_NAME, VALUE, EXCEPTION) \
213 TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
216#elif defined(THEORETICA_THROW_EXCEPTIONS)
218#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
219 { errno = th_errcode_to_errno(EXCEPTION); \
220 throw math_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, VALUE); }
225#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
226 { errno = th_errcode_to_errno(EXCEPTION); }
233#define TH_DEBUG(VARIABLE) { \
234 std::cout << __FILE__ << ":" << __LINE__ << ": " \
235 << #VARIABLE << " = " << VARIABLE << std::endl; }
Mathematical constants and default algorithm parameters.
#define TH_CONSTEXPR
Enable constexpr in function declarations if C++14 is supported.
Definition constants.h:161
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
double real
A real number, defined as a floating point type.
Definition constants.h:198
bool is_nan(const T &x)
Check whether a generic variable is (equivalent to) a NaN number.
Definition error.h:70
std::remove_reference_t< decltype(std::declval< Structure >()[0])> vector_element_t
Extract the type of a vector (or any indexable container) from its operator[].
Definition core_traits.h:134
MATH_ERRCODE
Math error enumeration.
Definition error.h:27
int th_errcode_to_errno(MATH_ERRCODE err)
Convert a MATH_ERRCODE to errno error codes.
Definition error.h:39
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:54
bool is_inf(real x)
Check whether a real number is infinite.
Definition error.h:82
TH_CONSTEXPR real inf()
Get positive infinity in floating point representation.
Definition error.h:76