6#ifndef THEORETICA_ERROR_H
7#define THEORETICA_ERROR_H
11#ifndef THEORETICA_NO_PRINT
46 default:
return 0;
break;
57 return "An argument was out of the domain of the called function";
break;
59 return "A mathematically impossible operation was requested";
break;
62 default:
return "Unknown error";
break;
75 return std::numeric_limits<real>::quiet_NaN();
97 return std::numeric_limits<real>::infinity();
103 return (x ==
inf()) || (x == -
inf());
113 std::string func_name;
114 std::string file_name;
115 unsigned int code_line;
164#ifndef THEORETICA_NO_PRINT
171 err_str << file_name <<
"(" << code_line <<
"):";
172 err_str << func_name <<
"(" << val <<
"): ";
180 inline operator std::string() {
188 return out <<
obj.to_string();
204#ifdef THEORETICA_ONLY_EXCEPTIONS
206#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
207 { throw theoretica::math_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, VALUE); }
210#elif defined(THEORETICA_THROW_EXCEPTIONS)
212#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
213 { errno = theoretica::to_errno(EXCEPTION); \
214 throw math_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, VALUE); }
219#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
220 { errno = theoretica::to_errno(EXCEPTION); }
227#define TH_DEBUG(VARIABLE) { \
228 std::cout << __FILE__ << ":" << __LINE__ << ": " \
229 << #VARIABLE << " = " << VARIABLE << std::endl; }
A class for representing mathematical errors.
Definition error.h:109
friend std::ostream & operator<<(std::ostream &out, const math_exception &obj)
Stream the exception in string representation to an output stream (std::ostream)
Definition error.h:187
real get_value() const
Get a real value associated with the exception.
Definition error.h:159
unsigned int get_line_number() const
Get the line number at which the exception was thrown.
Definition error.h:153
std::string to_string() const
Get a string representation of the exception.
Definition error.h:167
std::string get_file_name() const
Get the name of the file in which the exception was thrown.
Definition error.h:147
MathError err_code() const
Get the error code associated with the exception.
Definition error.h:135
std::string get_function_name() const
Get the name of the throwing function.
Definition error.h:141
const char * what() const noexcept
Return a string describing the exception.
Definition error.h:129
Mathematical constants and default algorithm parameters.
#define TH_CONSTEXPR
Enable constexpr in function declarations if C++14 is supported.
Definition constants.h:170
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:207
bool is_nan(const T &x)
Check whether a generic variable is (equivalent to) a NaN number.
Definition error.h:90
Vector make_error()
Create a vector representing an error state, with all NaN values.
Definition algebra.h:103
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:74
int to_errno(MathError err)
Convert an MathError class enum to conventional errno codes.
Definition error.h:37
std::string to_string(MathError err)
Convert a MathError class enum to a string description.
Definition error.h:68
MathError
Math error enumeration.
Definition error.h:25
@ InvalidArgument
Invalid argument.
@ OutOfDomain
Argument out of domain.
@ OutOfRange
Result out of range.
@ ImpossibleOperation
Mathematically impossible operation.
@ NoConvergence
Algorithm did not converge.
@ DivByZero
Division by zero.
bool is_inf(real x)
Check whether a real number is infinite.
Definition error.h:102
TH_CONSTEXPR real inf()
Get positive infinity in floating point representation.
Definition error.h:96
const char * to_cstring(MathError err)
Convert a MathError class enum to a string description.
Definition error.h:52