qwt_math.h
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #ifndef QWT_MATH_H
11 #define QWT_MATH_H
12 
13 #include "qwt_global.h"
14 
15 /*
16  Microsoft says:
17 
18  Define _USE_MATH_DEFINES before including math.h to expose these macro
19  definitions for common math constants. These are placed under an #ifdef
20  since these commonly-defined names are not part of the C/C++ standards.
21 */
22 
23 #ifndef _USE_MATH_DEFINES
24 #define _USE_MATH_DEFINES
25 #define undef_USE_MATH_DEFINES
26 #endif
27 
28 #include <cmath>
29 
30 #ifdef undef_USE_MATH_DEFINES
31 #undef _USE_MATH_DEFINES
32 #undef undef_USE_MATH_DEFINES
33 #endif
34 
35 #ifndef M_E
36 #define M_E (2.7182818284590452354)
37 #endif
38 
39 #ifndef M_LOG2E
40 #define M_LOG2E (1.4426950408889634074)
41 #endif
42 
43 #ifndef M_LOG10E
44 #define M_LOG10E (0.43429448190325182765)
45 #endif
46 
47 #ifndef M_LN2
48 #define M_LN2 (0.69314718055994530942)
49 #endif
50 
51 #ifndef M_LN10
52 #define M_LN10 (2.30258509299404568402)
53 #endif
54 
55 #ifndef M_PI
56 #define M_PI (3.14159265358979323846)
57 #endif
58 
59 #ifndef M_PI_2
60 #define M_PI_2 (1.57079632679489661923)
61 #endif
62 
63 #ifndef M_PI_4
64 #define M_PI_4 (0.78539816339744830962)
65 #endif
66 
67 #ifndef M_1_PI
68 #define M_1_PI (0.31830988618379067154)
69 #endif
70 
71 #ifndef M_2_PI
72 #define M_2_PI (0.63661977236758134308)
73 #endif
74 
75 #ifndef M_2_SQRTPI
76 #define M_2_SQRTPI (1.12837916709551257390)
77 #endif
78 
79 #ifndef M_SQRT2
80 #define M_SQRT2 (1.41421356237309504880)
81 #endif
82 
83 #ifndef M_SQRT1_2
84 #define M_SQRT1_2 (0.70710678118654752440)
85 #endif
86 
87 #if defined( QT_WARNING_PUSH )
88 // on earlier Qt versions you will be flooded with warnings anyway
89 QT_WARNING_DISABLE_CLANG("-Wdouble-promotion")
90 QT_WARNING_DISABLE_GCC("-Wdouble-promotion")
91 #endif
92 
93 /*
94  On systems, where qreal is a float you often run into
95  compiler issues with qMin/qMax.
96  */
97 
99 QWT_CONSTEXPR inline float qwtMinF( float a, float b )
100 {
101  return ( a < b ) ? a : b;
102 }
103 
105 QWT_CONSTEXPR inline double qwtMinF( double a, double b )
106 {
107  return ( a < b ) ? a : b;
108 }
109 
111 QWT_CONSTEXPR inline qreal qwtMinF( float a, double b )
112 {
113  return ( a < b ) ? a : b;
114 }
115 
117 QWT_CONSTEXPR inline qreal qwtMinF( double a, float b )
118 {
119  return ( a < b ) ? a : b;
120 }
121 
123 QWT_CONSTEXPR inline float qwtMaxF( float a, float b )
124 {
125  return ( a < b ) ? b : a;
126 }
127 
129 QWT_CONSTEXPR inline double qwtMaxF( double a, double b )
130 {
131  return ( a < b ) ? b : a;
132 }
133 
135 QWT_CONSTEXPR inline qreal qwtMaxF( float a, double b )
136 {
137  return ( a < b ) ? b : a;
138 }
139 
141 QWT_CONSTEXPR inline qreal qwtMaxF( double a, float b )
142 {
143  return ( a < b ) ? b : a;
144 }
145 
146 #if defined( QT_WARNING_PUSH )
147 QT_WARNING_POP
148 #endif
149 
150 QWT_EXPORT double qwtNormalizeRadians( double radians );
151 QWT_EXPORT double qwtNormalizeDegrees( double degrees );
152 QWT_EXPORT quint32 qwtRand();
153 
166 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
167 {
168  const double eps = qAbs( 1.0e-6 * intervalSize );
169 
170  if ( value2 - value1 > eps )
171  return -1;
172 
173  if ( value1 - value2 > eps )
174  return 1;
175 
176  return 0;
177 }
178 
180 inline int qwtSign( double x )
181 {
182  if ( x > 0.0 )
183  return 1;
184  else if ( x < 0.0 )
185  return ( -1 );
186  else
187  return 0;
188 }
189 
191 inline double qwtSqr( double x )
192 {
193  return x * x;
194 }
195 
197 inline double qwtFastAtan( double x )
198 {
199  if ( x < -1.0 )
200  return -M_PI_2 - x / ( x * x + 0.28 );
201 
202  if ( x > 1.0 )
203  return M_PI_2 - x / ( x * x + 0.28 );
204 
205  return x / ( 1.0 + x * x * 0.28 );
206 }
207 
209 inline double qwtFastAtan2( double y, double x )
210 {
211  if ( x > 0 )
212  return qwtFastAtan( y / x );
213 
214  if ( x < 0 )
215  {
216  const double d = qwtFastAtan( y / x );
217  return ( y >= 0 ) ? d + M_PI : d - M_PI;
218  }
219 
220  if ( y < 0.0 )
221  return -M_PI_2;
222 
223  if ( y > 0.0 )
224  return M_PI_2;
225 
226  return 0.0;
227 }
228 
229 /* !
230  \brief Calculate a value of a cubic polynom
231 
232  \param x Value
233  \param a Cubic coefficient
234  \param b Quadratic coefficient
235  \param c Linear coefficient
236  \param d Connstant offset
237 
238  \return Value of the polyonom for x
239 */
240 inline double qwtCubicPolynom( double x,
241  double a, double b, double c, double d )
242 {
243  return ( ( ( a * x ) + b ) * x + c ) * x + d;
244 }
245 
247 inline double qwtRadians( double degrees )
248 {
249  return degrees * M_PI / 180.0;
250 }
251 
253 inline double qwtDegrees( double degrees )
254 {
255  return degrees * 180.0 / M_PI;
256 }
257 
262 inline int qwtCeil( qreal value )
263 {
264  using std::ceil;
265  return int( ceil( value ) );
266 }
271 inline int qwtFloor( qreal value )
272 {
273  using std::floor;
274  return int( floor( value ) );
275 }
276 
277 #endif
enum MQTTPropertyCodes value
int qwtFuzzyCompare(double value1, double value2, double intervalSize)
Compare 2 values, relative to an interval.
Definition: qwt_math.h:166
#define QWT_EXPORT
Definition: qwt_global.h:38
MQTTClient d
Definition: test10.c:1656
QWT_CONSTEXPR float qwtMaxF(float a, float b)
Definition: qwt_math.h:123
double qwtDegrees(double degrees)
Translate radians into degrees.
Definition: qwt_math.h:253
#define M_PI_2
Definition: qwt_math.h:60
QWT_CONSTEXPR float qwtMinF(float a, float b)
Definition: qwt_math.h:99
int qwtFloor(qreal value)
Definition: qwt_math.h:271
double qwtRadians(double degrees)
Translate degrees into radians.
Definition: qwt_math.h:247
QWT_EXPORT quint32 qwtRand()
Uses QRandomGenerator for Qt >= 5.10 and qRand() otherwise.
Definition: qwt_math.cpp:48
#define QWT_CONSTEXPR
Definition: qwt_global.h:41
QWT_EXPORT double qwtNormalizeDegrees(double degrees)
Normalize an angle to be int the range [0.0, 360.0[.
Definition: qwt_math.cpp:35
double qwtCubicPolynom(double x, double a, double b, double c, double d)
Definition: qwt_math.h:240
int qwtSign(double x)
Return the sign.
Definition: qwt_math.h:180
#define M_PI
Definition: qwt_math.h:56
MQTTClient c
Definition: test10.c:1656
double qwtFastAtan(double x)
Approximation of arc tangent ( error below 0,005 radians )
Definition: qwt_math.h:197
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:191
double qwtFastAtan2(double y, double x)
Approximation of arc tangent ( error below 0,005 radians )
Definition: qwt_math.h:209
QWT_EXPORT double qwtNormalizeRadians(double radians)
Normalize an angle to be int the range [0.0, 2 * PI[.
Definition: qwt_math.cpp:20
int qwtCeil(qreal value)
Definition: qwt_math.h:262


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10