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
50 default:
return 0;
break;
61 return "An argument was out of the domain of the called function";
break;
63 return "A mathematically impossible operation was requested";
break;
66 default:
return "Unknown error";
break;
79 return std::numeric_limits<real>::quiet_NaN();
101 return std::numeric_limits<real>::infinity();
107 return (x ==
inf()) || (x == -
inf());
111#if defined(THEORETICA_THROW_EXCEPTIONS) || defined(THEORETICA_ONLY_EXCEPTIONS)
168#ifndef THEORETICA_NO_PRINT
184 inline operator std::string() {
192 return out <<
obj.to_string();
210#ifdef THEORETICA_ONLY_EXCEPTIONS
212#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
213 { throw theoretica::math_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, VALUE); }
216#elif defined(THEORETICA_THROW_EXCEPTIONS)
218#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
219 { errno = theoretica::to_errno(EXCEPTION); \
220 throw math_exception(EXCEPTION, F_NAME, __FILE__, __LINE__, VALUE); }
225#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION) \
226 { errno = theoretica::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:170
std::ostream & operator<<(std::ostream &os, const hdf5_node &node)
Prints the HDF5 file tree to a stream.
Definition hdf5.h:460
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:94
TH_CONSTEXPR Type make_error()
Create a number representing an error state, constructed from a NaN value.
Definition real_analysis.h:1322
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:78
int to_errno(MathError err)
Convert an MathError class enum to conventional errno codes.
Definition error.h:41
std::string to_string(MathError err)
Convert a MathError class enum to a string description.
Definition error.h:72
MathError
Math error enumeration.
Definition error.h:29
@ 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:106
TH_CONSTEXPR real inf()
Get positive infinity in floating point representation.
Definition error.h:100
const char * to_cstring(MathError err)
Convert a MathError class enum to a string description.
Definition error.h:56