1#ifndef SXEVAL_UTILS_HPP
2#define SXEVAL_UTILS_HPP
10#define SXEVAL_PI 3.14159265358979323846
47inline typename std::enable_if<std::is_integral<T>::value,
bool>
::type
60inline typename std::enable_if<std::is_floating_point<T>::value,
bool>
::type
62 return std::abs(
a -
b) <= std::numeric_limits<T>::epsilon();
122inline typename std::enable_if<std::is_integral<T>::value,
bool>
::type
136inline typename std::enable_if<std::is_floating_point<T>::value,
bool>
::type
138 return std::abs(
val) > std::numeric_limits<T>::epsilon();
233inline typename std::enable_if<std::is_integral<T>::value,
T>
::type
247inline typename std::enable_if<std::is_floating_point<T>::value,
T>
::type
249 return std::fmod(
a,
b);
261inline typename std::enable_if<std::is_unsigned<T>::value,
T>
::type
275inline typename std::enable_if<
276 std::is_integral<T>::value && !std::is_unsigned<T>::value,
T>
::type
290inline typename std::enable_if<
291 std::is_floating_point<T>::value && !std::is_unsigned<T>::value,
T>
::type
304 if (sscanf(s.c_str(),
"%d", &res) != 1) {
305 throw std::invalid_argument(
"Invalid int string");
313 if (sscanf(s.c_str(),
"%hhd", &res) != 1) {
314 throw std::invalid_argument(
"Invalid signed char string");
322 if (sscanf(s.c_str(),
"%hd", &res) != 1) {
323 throw std::invalid_argument(
"Invalid short int string");
331 if (sscanf(s.c_str(),
"%ld", &res) != 1) {
332 throw std::invalid_argument(
"Invalid long int string");
340 if (sscanf(s.c_str(),
"%u", &res) != 1) {
341 throw std::invalid_argument(
"Invalid unsigned int string");
349 if (sscanf(s.c_str(),
"%hhu", &res) != 1) {
350 throw std::invalid_argument(
"Invalid unsigned char string");
357 const std::string& s)
359 unsigned long int res;
360 if (sscanf(s.c_str(),
"%lu", &res) != 1) {
361 throw std::invalid_argument(
"Invalid unsigned long int string");
369 if (sscanf(s.c_str(),
"%f", &res) != 1) {
370 throw std::invalid_argument(
"Invalid float string");
378 if (sscanf(s.c_str(),
"%lf", &res) != 1) {
379 throw std::invalid_argument(
"Invalid double string");
388 if (sscanf(s.c_str(),
"%Lf", &res) != 1) {
389 throw std::invalid_argument(
"Invalid long double string");
Definition AOperation.hpp:8
std::enable_if< std::is_integral< T >::value, T >::type Modulo(const T &a, const T &b)
Perform a modulo operation on types T.
Definition utils.hpp:234
bool LogicalXnor(const T &a, const T &b)
Perform a logical xnor operation on types T.
Definition utils.hpp:220
bool Less(const T &a, const T &b)
Check if a is less than b.
Definition utils.hpp:97
std::enable_if< std::is_integral< T >::value, bool >::type Equal(const T &a, const T &b)
Check if a is equal to b.
Definition utils.hpp:48
bool LogicalNot(const T &a)
Perform a logical not operation on type T.
Definition utils.hpp:172
bool LogicalXor(const T &a, const T &b)
Perform a logical xor operation on types T.
Definition utils.hpp:184
bool Greater(const T &a, const T &b)
Check if a is greater than b.
Definition utils.hpp:35
bool LogicalOr(const T &a, const T &b)
Perform a logical or operation on types T.
Definition utils.hpp:161
bool LogicalAnd(const T &a, const T &b)
Perform a logical and operations on types T.
Definition utils.hpp:149
bool LogicalNand(const T &a, const T &b)
Perform a logical nand operation on types T.
Definition utils.hpp:196
bool GreaterOrEqual(const T &a, const T &b)
Check if a is greater than or equal to b.
Definition utils.hpp:85
bool NotEqual(const T &a, const T &b)
Check if a is not equal to b.
Definition utils.hpp:73
std::enable_if< std::is_unsigned< T >::value, T >::type Absolute(const T &a)
Perform an absolute value operation on types T.
Definition utils.hpp:262
bool LessOrEqual(const T &a, const T &b)
Check if a is less than or equal to b.
Definition utils.hpp:109
T StringToType(const std::string &s)
Convert a string to a type T.
std::enable_if< std::is_integral< T >::value, bool >::type TypeToBool(const T &val)
Convert a type T to a boolean value.
Definition utils.hpp:123
bool LogicalNor(const T &a, const T &b)
Perform a logical nor operation on types T.
Definition utils.hpp:208