Qwt User's Guide 6.1.1

- Main Page
- Related Pages
- Classes

All Classes Functions Variables Typedefs Enumerations Enumerator Pages
qwt_math.h
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
76
77 inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
78 {
79 return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
80 }
81
82 inline bool qwtFuzzyLessOrEqual( double d1, double d2 )
83 {
84 return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );
85 }
86
88 inline int qwtSign( double x )
89 {
90 if ( x > 0.0 )
91 return 1;
92 else if ( x < 0.0 )
93 return ( -1 );
94 else
95 return 0;
96 }
97
99 inline double qwtSqr( double x )
100 {
101 return x * x;
102 }
103
105 inline double qwtFastAtan( double x )
106 {
107 if ( x < -1.0 )
108 return -M_PI_2 - x / ( x * x + 0.28 );
109
110 if ( x > 1.0 )
111 return M_PI_2 - x / ( x * x + 0.28 );
112
113 return x / ( 1.0 + x * x * 0.28 );
114 }
115
117 inline double qwtFastAtan2( double y, double x )
118 {
119 if ( x > 0 )
120 return qwtFastAtan( y / x );
121
122 if ( x < 0 )
123 {
124 const double d = qwtFastAtan( y / x );
125 return ( y >= 0 ) ? d + M_PI : d - M_PI;
126 }
127
128 if ( y < 0.0 )
129 return -M_PI_2;
130
131 if ( y > 0.0 )
132 return M_PI_2;
133
134 return 0.0;
135 }
136
137 // Translate degrees into radians
138 inline double qwtRadians( double degrees )
139 {
140 return degrees * M_PI / 180.0;
141 }
142
143 // Translate radians into degrees
144 inline double qwtDegrees( double degrees )
145 {
146 return degrees * 180.0 / M_PI;
147 }
148
149 #endif