[4271] | 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 <qpoint.h>
|
---|
| 27 | #include <qmath.h>
|
---|
| 28 | #include "qwt_global.h"
|
---|
| 29 |
|
---|
| 30 | #ifndef LOG10_2
|
---|
| 31 | #define LOG10_2 0.30102999566398119802 /* log10(2) */
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | #ifndef LOG10_3
|
---|
| 35 | #define LOG10_3 0.47712125471966243540 /* log10(3) */
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 | #ifndef LOG10_5
|
---|
| 39 | #define LOG10_5 0.69897000433601885749 /* log10(5) */
|
---|
| 40 | #endif
|
---|
| 41 |
|
---|
| 42 | #ifndef M_2PI
|
---|
| 43 | #define M_2PI 6.28318530717958623200 /* 2 pi */
|
---|
| 44 | #endif
|
---|
| 45 |
|
---|
| 46 | #ifndef LOG_MIN
|
---|
| 47 | //! Mininum value for logarithmic scales
|
---|
| 48 | #define LOG_MIN 1.0e-100
|
---|
| 49 | #endif
|
---|
| 50 |
|
---|
| 51 | #ifndef LOG_MAX
|
---|
| 52 | //! Maximum value for logarithmic scales
|
---|
| 53 | #define LOG_MAX 1.0e100
|
---|
| 54 | #endif
|
---|
| 55 |
|
---|
| 56 | #ifndef M_E
|
---|
| 57 | #define M_E 2.7182818284590452354 /* e */
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
| 60 | #ifndef M_LOG2E
|
---|
| 61 | #define M_LOG2E 1.4426950408889634074 /* log_2 e */
|
---|
| 62 | #endif
|
---|
| 63 |
|
---|
| 64 | #ifndef M_LOG10E
|
---|
| 65 | #define M_LOG10E 0.43429448190325182765 /* log_10 e */
|
---|
| 66 | #endif
|
---|
| 67 |
|
---|
| 68 | #ifndef M_LN2
|
---|
| 69 | #define M_LN2 0.69314718055994530942 /* log_e 2 */
|
---|
| 70 | #endif
|
---|
| 71 |
|
---|
| 72 | #ifndef M_LN10
|
---|
| 73 | #define M_LN10 2.30258509299404568402 /* log_e 10 */
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | #ifndef M_PI
|
---|
| 77 | #define M_PI 3.14159265358979323846 /* pi */
|
---|
| 78 | #endif
|
---|
| 79 |
|
---|
| 80 | #ifndef M_PI_2
|
---|
| 81 | #define M_PI_2 1.57079632679489661923 /* pi/2 */
|
---|
| 82 | #endif
|
---|
| 83 |
|
---|
| 84 | #ifndef M_PI_4
|
---|
| 85 | #define M_PI_4 0.78539816339744830962 /* pi/4 */
|
---|
| 86 | #endif
|
---|
| 87 |
|
---|
| 88 | #ifndef M_1_PI
|
---|
| 89 | #define M_1_PI 0.31830988618379067154 /* 1/pi */
|
---|
| 90 | #endif
|
---|
| 91 |
|
---|
| 92 | #ifndef M_2_PI
|
---|
| 93 | #define M_2_PI 0.63661977236758134308 /* 2/pi */
|
---|
| 94 | #endif
|
---|
| 95 |
|
---|
| 96 | #ifndef M_2_SQRTPI
|
---|
| 97 | #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
|
---|
| 98 | #endif
|
---|
| 99 |
|
---|
| 100 | #ifndef M_SQRT2
|
---|
| 101 | #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
---|
| 102 | #endif
|
---|
| 103 |
|
---|
| 104 | #ifndef M_SQRT1_2
|
---|
| 105 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
---|
| 106 | #endif
|
---|
| 107 |
|
---|
| 108 | QWT_EXPORT double qwtGetMin( const double *array, int size );
|
---|
| 109 | QWT_EXPORT double qwtGetMax( const double *array, int size );
|
---|
| 110 |
|
---|
| 111 | /*!
|
---|
| 112 | \brief Compare 2 values, relative to an interval
|
---|
| 113 |
|
---|
| 114 | Values are "equal", when :
|
---|
| 115 | \f$\cdot value2 - value1 <= abs(intervalSize * 10e^{-6})\f$
|
---|
| 116 |
|
---|
| 117 | \param value1 First value to compare
|
---|
| 118 | \param value2 Second value to compare
|
---|
| 119 | \param intervalSize interval size
|
---|
| 120 |
|
---|
| 121 | \return 0: if equal, -1: if value2 > value1, 1: if value1 > value2
|
---|
| 122 | */
|
---|
| 123 | inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
|
---|
| 124 | {
|
---|
| 125 | const double eps = qAbs( 1.0e-6 * intervalSize );
|
---|
| 126 |
|
---|
| 127 | if ( value2 - value1 > eps )
|
---|
| 128 | return -1;
|
---|
| 129 |
|
---|
| 130 | if ( value1 - value2 > eps )
|
---|
| 131 | return 1;
|
---|
| 132 |
|
---|
| 133 | return 0;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
|
---|
| 138 | {
|
---|
| 139 | return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | inline bool qwtFuzzyLessOrEqual( double d1, double d2 )
|
---|
| 143 | {
|
---|
| 144 | return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | //! Return the sign
|
---|
| 148 | inline int qwtSign( double x )
|
---|
| 149 | {
|
---|
| 150 | if ( x > 0.0 )
|
---|
| 151 | return 1;
|
---|
| 152 | else if ( x < 0.0 )
|
---|
| 153 | return ( -1 );
|
---|
| 154 | else
|
---|
| 155 | return 0;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | //! Return the square of a number
|
---|
| 159 | inline double qwtSqr( double x )
|
---|
| 160 | {
|
---|
| 161 | return x * x;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | //! Like qRound, but without converting the result to an int
|
---|
| 165 | inline double qwtRoundF(double d)
|
---|
| 166 | {
|
---|
| 167 | return ::floor( d + 0.5 );
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | //! Like qFloor, but without converting the result to an int
|
---|
| 171 | inline double qwtFloorF(double d)
|
---|
| 172 | {
|
---|
| 173 | return ::floor( d );
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | //! Like qCeil, but without converting the result to an int
|
---|
| 177 | inline double qwtCeilF(double d)
|
---|
| 178 | {
|
---|
| 179 | return ::ceil( d );
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | #endif
|
---|