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 #if defined(_MSC_VER)
16 /*
17  Microsoft says:
18 
19  Define _USE_MATH_DEFINES before including math.h to expose these macro
20  definitions for common math constants. These are placed under an #ifdef
21  since these commonly-defined names are not part of the C/C++ standards.
22 */
23 #define _USE_MATH_DEFINES 1
24 #endif
25 
26 #include <qmath.h>
27 #include "qwt_global.h"
28 
29 #ifndef M_PI_2
30 // For Qt <= 4.8.4 M_PI_2 is not known by MinGW-w64
31 // when compiling with -std=c++11
32 #define M_PI_2 (1.57079632679489661923)
33 #endif
34 
35 #ifndef LOG_MIN
36 #define LOG_MIN 1.0e-100
38 #endif
39 
40 #ifndef LOG_MAX
41 #define LOG_MAX 1.0e100
43 #endif
44 
45 QWT_EXPORT double qwtGetMin( const double *array, int size );
46 QWT_EXPORT double qwtGetMax( const double *array, int size );
47 
48 QWT_EXPORT double qwtNormalizeRadians( double radians );
49 QWT_EXPORT double qwtNormalizeDegrees( double degrees );
50 
63 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
64 {
65  const double eps = qAbs( 1.0e-6 * intervalSize );
66 
67  if ( value2 - value1 > eps )
68  return -1;
69 
70  if ( value1 - value2 > eps )
71  return 1;
72 
73  return 0;
74 }
75 
77 inline int qwtSign( double x )
78 {
79  if ( x > 0.0 )
80  return 1;
81  else if ( x < 0.0 )
82  return ( -1 );
83  else
84  return 0;
85 }
86 
88 inline double qwtSqr( double x )
89 {
90  return x * x;
91 }
92 
94 inline double qwtFastAtan( double x )
95 {
96  if ( x < -1.0 )
97  return -M_PI_2 - x / ( x * x + 0.28 );
98 
99  if ( x > 1.0 )
100  return M_PI_2 - x / ( x * x + 0.28 );
101 
102  return x / ( 1.0 + x * x * 0.28 );
103 }
104 
106 inline double qwtFastAtan2( double y, double x )
107 {
108  if ( x > 0 )
109  return qwtFastAtan( y / x );
110 
111  if ( x < 0 )
112  {
113  const double d = qwtFastAtan( y / x );
114  return ( y >= 0 ) ? d + M_PI : d - M_PI;
115  }
116 
117  if ( y < 0.0 )
118  return -M_PI_2;
119 
120  if ( y > 0.0 )
121  return M_PI_2;
122 
123  return 0.0;
124 }
125 
126 /* !
127  \brief Calculate a value of a cubic polynom
128 
129  \param x Value
130  \param a Cubic coefficient
131  \param b Quadratic coefficient
132  \param c Linear coefficient
133  \param d Connstant offset
134 
135  \return Value of the polyonom for x
136 */
137 inline double qwtCubicPolynom( double x,
138  double a, double b, double c, double d )
139 {
140  return ( ( ( a * x ) + b ) * x + c ) * x + d;
141 }
142 
144 inline double qwtRadians( double degrees )
145 {
146  return degrees * M_PI / 180.0;
147 }
148 
150 inline double qwtDegrees( double degrees )
151 {
152  return degrees * 180.0 / M_PI;
153 }
154 
155 #endif
d
QWT_EXPORT double qwtGetMin(const double *array, int size)
Find the smallest value in an array.
Definition: qwt_math.cpp:17
int qwtFuzzyCompare(double value1, double value2, double intervalSize)
Compare 2 values, relative to an interval.
Definition: qwt_math.h:63
#define QWT_EXPORT
Definition: qwt_global.h:38
double qwtDegrees(double degrees)
Translate radians into degrees.
Definition: qwt_math.h:150
#define M_PI_2
Definition: qwt_math.h:32
double qwtRadians(double degrees)
Translate degrees into radians.
Definition: qwt_math.h:144
QWT_EXPORT double qwtNormalizeDegrees(double degrees)
Normalize an angle to be int the range [0.0, 360.0[.
Definition: qwt_math.cpp:67
double qwtCubicPolynom(double x, double a, double b, double c, double d)
Definition: qwt_math.h:137
int qwtSign(double x)
Return the sign.
Definition: qwt_math.h:77
double qwtFastAtan(double x)
Approximation of arc tangent ( error below 0,005 radians )
Definition: qwt_math.h:94
double qwtSqr(double x)
Return the square of a number.
Definition: qwt_math.h:88
QWT_EXPORT double qwtGetMax(const double *array, int size)
Find the largest value in an array.
Definition: qwt_math.cpp:35
double qwtFastAtan2(double y, double x)
Approximation of arc tangent ( error below 0,005 radians )
Definition: qwt_math.h:106
QWT_EXPORT double qwtNormalizeRadians(double radians)
Normalize an angle to be int the range [0.0, 2 * PI[.
Definition: qwt_math.cpp:52


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17