1 #ifndef FUNCTIONS_NUMERIC_H
2 #define FUNCTIONS_NUMERIC_H
6 #include "functions_type.h"
11 namespace functions_numeric {
23 inline tBoolean areEquals(
const T& e1,
const T& e2 )
34 inline tBoolean areEquals(
const tReal& e1,
const tReal& e2 ) {
35 return abs(e1-e2)<std::numeric_limits<tReal>::epsilon();
45 inline tBoolean areEquals(
const tComplex& e1,
const tComplex &e2 ) {
46 return abs(e1-e2)<std::numeric_limits<tReal>::epsilon();
57 inline tBoolean areEquals(
const tString& e1,
const tString & e2 ) {
58 return (e1.compare(e2)==0);
70 requires functions_type::isRealType<T>
71 inline tBoolean isNAN(
const T& s) {
79 inline tBoolean isInteger(
const tString& s) {
81 strtol(s.c_str(), &p, 10);
95 inline tBoolean isNumeric(
const tString& s) {
97 strtod(s.c_str(), &p);
111 inline tBoolean isString(
const tString& s) {
112 return ( (!isInteger(s)) && (!isNumeric(s)));
128 requires functions_type::isArithmeticType<T>
129 inline static T getEpsilon() {
130 return std::numeric_limits<T>::epsilon();
136 requires functions_type::isArithmeticType<T>
137 inline static T getInfinity() {
138 return std::numeric_limits<T>::infinity();
144 requires functions_type::isArithmeticType<T>
145 inline static T getEpsilonValue() {
146 return std::numeric_limits<T>::epsilon();
152 requires functions_type::isArithmeticType<T>
153 inline static T getInfinityValue() {
154 return std::numeric_limits<T>::infinity();
160 requires functions_type::isIntegerType<T>
161 inline static T getMax() {
162 return std::numeric_limits<T>::max();
168 requires functions_type::isIntegerType<T>
169 inline static T getMin() {
170 return std::numeric_limits<T>::min();
176 requires functions_type::isIntegerType<T>
177 inline static T getMaxValue() {
178 return std::numeric_limits<T>::max();
184 requires functions_type::isIntegerType<T>
185 inline static T getMinValue() {
186 return std::numeric_limits<T>::min();
200 requires functions_type::isArithmeticType<T>
201 inline const T& min(
const T& a,
const T&b) {
210 requires functions_type::isArithmeticType<T>
211 inline const T& max(
const T& a,
const T&b) {
218 template<
typename Q,tUCInt N,tUCInt i> requires (i==N)
219 inline Q levelPow(
const Q& x) {
225 template<
typename Q,tUCInt N,tUCInt i> requires (i<N)
226 inline Q levelPow(
const Q& x) {
227 return x*levelPow<Q,N,i+1>(x);
233 template<
typename Q,tUCInt N>
234 inline Q pow(
const Q& x) {
235 return levelPow<Q,N,1>(x);
243 template<
typename T,std::enable_if_t<std::is_
integral_v<T>> * =
nullptr>
244 inline tString toString(
const T& v,
const tUCInt& d) {
245 tString ret=std::to_string(v);
246 for (tUCInt k=ret.length();k<d;k++) {
254 template<
typename T,std::enable_if_t<std::is_arithmetic_v<T>> * =
nullptr>
255 inline tString toString(
const T& v) {
256 std::stringstream sv;
265 inline tString booleanToString(
const tBoolean& v) {
266 return (v)?
"true":
"false";
274 inline void parse(
const tString& s,T& v) {
275 std::stringstream ss;
284 inline void parse(
const tString& s,tBoolean& v) {
307 template<
typename Q> requires functions_type::isArithmeticType<Q>
308 tIndex quickSearch(
const Q& v,
336 currentValue=values[k];
338 if (v<currentValue) {
343 if (v==currentValue) {
350 currentValue=values[k];
352 if (v>currentValue) {
357 if (v==currentValue) {
367 currentValue=values[k];
368 if (v==currentValue) {
372 if (v<currentValue) k1=k;