22#ifndef jkqtpmathtools_H_INCLUDED
23#define jkqtpmathtools_H_INCLUDED
24#include "jkqtcommon/jkqtcommon_imexport.h"
25#include "jkqtcommon/jkqtpstringtools.h"
36#include <QHashFunctions>
50# define JKQTPSTATISTICS_PI M_PI
52# define JKQTPSTATISTICS_PI 3.14159265358979323846
60#define JKQTPSTATISTICS_SQRT_2PI 2.50662827463
68# define JKQTPSTATISTICS_LN10 M_LN10
70# define JKQTPSTATISTICS_LN10 2.30258509299404568402
77#define JKQTP_DOUBLE_NAN (std::numeric_limits<double>::signaling_NaN())
82#define JKQTP_FLOAT_NAN (std::numeric_limits<float>::signaling_NaN())
87#define JKQTP_NAN JKQTP_DOUBLE_NAN
92#define JKQTP_DOUBLE_EPSILON (std::numeric_limits<double>::epsilon())
97#define JKQTP_FLOAT_EPSILON (std::numeric_limits<float>::epsilon())
102#define JKQTP_EPSILON JKQTP_DOUBLE_EPSILON
114 return static_cast<double>(d);
127 return static_cast<double>((d)?1.0:0.0);
146 return static_cast<T
>(round(v));
163 const double fac=pow(10.0,(
double)decDigits);
164 return round(v * fac) / fac;
182 return static_cast<T
>(ceil(v));
200 return static_cast<T
>(trunc(v));
218 return static_cast<T
>(floor(v));
238 return qBound(min,
static_cast<T
>(round(v)), max);
255 return jkqtp_boundedRoundTo<T>(std::numeric_limits<T>::min(), v, std::numeric_limits<T>::max());
268 return (v<min) ? min : ((v>max)? max : v);
280template<
typename T,
typename TIn>
282 if (std::is_integral<T>::value && std::is_integral<TIn>::value && (std::is_signed<TIn>::value!=std::is_signed<T>::value)) {
283 return (v<TIn(0)) ? T(0) : ((v>std::numeric_limits<T>::max())? std::numeric_limits<T>::max() :
static_cast<T
>(v));
285 return (v<std::numeric_limits<T>::min()) ? std::numeric_limits<T>::min() : ((v>std::numeric_limits<T>::max())? std::numeric_limits<T>::max() :
static_cast<T
>(v));
293 return fabsf(a - b) <= epsilon;
300 return fabs(a - b) <= epsilon;
307 return fabsf(a - b) > epsilon;
314 return fabs(a - b) > epsilon;
383 if (fabs(vv)<absMinV) vv=
jkqtp_sign(v)*absMinV;
391 return jkqtp_inversePropSave<T>(v, std::numeric_limits<T>::epsilon()*100.0);
394#if defined(JKQtPlotter_HAS_j0) || defined(JKQtPlotter_HAS__j0) || defined(DOXYGEN)
401 #ifdef JKQtPlotter_HAS__j0
403 #elif defined(JKQtPlotter_HAS_j0)
413 #ifdef JKQtPlotter_HAS__j0
415 #elif defined(JKQtPlotter_HAS_j0)
421#if defined(JKQtPlotter_HAS_jn) || defined(JKQtPlotter_HAS__jn) || defined(DOXYGEN)
427 #ifdef JKQtPlotter_HAS__jn
429 #elif defined(JKQtPlotter_HAS_jn)
436#if defined(JKQtPlotter_HAS_y0) || defined(JKQtPlotter_HAS__y0) || defined(DOXYGEN)
442 #ifdef JKQtPlotter_HAS__y0
444 #elif defined(JKQtPlotter_HAS_y0)
454 #ifdef JKQtPlotter_HAS__y0
456 #elif defined(JKQtPlotter_HAS_y0)
461#if defined(JKQtPlotter_HAS_yn) || defined(JKQtPlotter_HAS__yn) || defined(DOXYGEN)
467 #ifdef JKQtPlotter_HAS__yn
469 #elif defined(JKQtPlotter_HAS_yn)
481 return sqrt(jkqtp_sqr<double>(p1.x()-p2.x())+jkqtp_sqr<double>(p1.y()-p2.y()));
489 return sqrt(jkqtp_sqr<double>(p1.x()-p2.x())+jkqtp_sqr<double>(p1.y()-p2.y()));
497 return std::isfinite(v)&&(!std::isinf(v))&&(!std::isnan(v));
501 return JKQTPIsOKFloat<qreal>(v.x()) && JKQTPIsOKFloat<qreal>(v.y());
505 return JKQTPIsOKFloat<qreal>(v.x1()) && JKQTPIsOKFloat<qreal>(v.x2()) && JKQTPIsOKFloat<qreal>(v.y1()) && JKQTPIsOKFloat<qreal>(v.y2());
509 return JKQTPIsOKFloat<qreal>(v.x()) && JKQTPIsOKFloat<qreal>(v.x()) && JKQTPIsOKFloat<qreal>(v.width()) && JKQTPIsOKFloat<qreal>(v.height());
531template <
class PolyItP>
535 for (
auto itP=firstP; itP!=lastP; ++itP) {
547 std::vector<double>
P;
548 template <
class PolyItP>
550 for (
auto itP=firstP; itP!=lastP; ++itP) {
565template <
class PolyItP>
577template <
class PolyItP>
581 for (
auto itP=firstP; itP!=lastP; ++itP) {
584 if (*itP>=0) str+=
"+";
598template <
class T=
int>
601 for (T i =1; i <= n; i++){
612template <
class T=
int>
628 if (n==0 && i==0)
return [=](T t) {
return 1; };
629 if (n==1 && i==0)
return [=](T t) {
return (1.0-t); };
630 if (n==1 && i==1)
return [=](T t) {
return t; };
631 if (n==2 && i==0)
return [=](T t) {
return jkqtp_sqr(1.0-t); };
632 if (n==2 && i==1)
return [=](T t) {
return T(2.0)*t*(1.0-t); };
633 if (n==2 && i==2)
return [=](T t) {
return jkqtp_sqr(t); };
634 if (n==3 && i==0)
return [=](T t) {
return T(1)*
jkqtp_cube(1.0-t); };
635 if (n==3 && i==1)
return [=](T t) {
return T(3)*t*
jkqtp_sqr(1.0-t); };
636 if (n==3 && i==2)
return [=](T t) {
return T(3)*
jkqtp_sqr(t)*(1.0-t); };
637 if (n==3 && i==3)
return [=](T t) {
return T(1)*
jkqtp_cube(t); };
638 if (n==4 && i==0)
return [=](T t) {
return T(1)*
jkqtp_pow4(1.0-t); };
639 if (n==4 && i==1)
return [=](T t) {
return T(4)*t*
jkqtp_cube(1.0-t); };
641 if (n==4 && i==3)
return [=](T t) {
return T(4)*
jkqtp_cube(t)*(1.0-t); };
642 if (n==4 && i==4)
return [=](T t) {
return T(1)*
jkqtp_pow4(t); };
643 const T fac=jkqtp_combination<int64_t>(n,i);
644 return [=](T t) {
return fac*pow(t,i)*pow(1.0-t,n-i); };
668 reversed_l.reserve(l.size());
669 std::reverse_copy(l.begin(), l.end(), std::back_inserter(reversed_l));
689 seed ^= hsh + 0x9e3779b9 + (seed<<6) + (seed>>2);
706 seed ^= hsh + 0x9e3779b9 + (seed<<6) + (seed>>2);
size_t qHash(const JKQTBasePlotter::textSizeKey &data, size_t)
qHash()-specialization
Definition jkqtpbaseplotter.h:2828
a C++-functor, which evaluates a polynomial
Definition jkqtpmathtools.h:546
JKQTPPolynomialFunctor(PolyItP firstP, PolyItP lastP)
Definition jkqtpmathtools.h:549
double operator()(double x) const
Definition jkqtpmathtools.h:554
std::vector< double > P
Definition jkqtpmathtools.h:547