Qwt User's Guide svn
qwt_math.h
00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
00002  * Qwt Widget Library
00003  * Copyright (C) 1997   Josef Wilgen
00004  * Copyright (C) 2002   Uwe Rathmann
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the Qwt License, Version 1.0
00008  *****************************************************************************/
00009 
00010 #ifndef QWT_MATH_H
00011 #define QWT_MATH_H
00012 
00013 #include "qwt_global.h"
00014 
00015 #if defined(_MSC_VER)
00016 /*
00017   Microsoft says:
00018 
00019   Define _USE_MATH_DEFINES before including math.h to expose these macro
00020   definitions for common math constants.  These are placed under an #ifdef
00021   since these commonly-defined names are not part of the C/C++ standards.
00022 */
00023 #define _USE_MATH_DEFINES 1
00024 #endif
00025 
00026 #include <qpoint.h>
00027 #include <qmath.h>
00028 #include "qwt_global.h"
00029 
00030 #ifndef LOG10_2
00031 #define LOG10_2     0.30102999566398119802  /* log10(2) */
00032 #endif
00033 
00034 #ifndef LOG10_3
00035 #define LOG10_3     0.47712125471966243540  /* log10(3) */
00036 #endif
00037 
00038 #ifndef LOG10_5
00039 #define LOG10_5     0.69897000433601885749  /* log10(5) */
00040 #endif
00041 
00042 #ifndef M_2PI
00043 #define M_2PI       6.28318530717958623200  /* 2 pi */
00044 #endif
00045 
00046 #ifndef LOG_MIN
00047 
00048 #define LOG_MIN 1.0e-100
00049 #endif
00050 
00051 #ifndef LOG_MAX
00052 
00053 #define LOG_MAX 1.0e100
00054 #endif
00055 
00056 #ifndef M_E
00057 #define M_E            2.7182818284590452354   /* e */
00058 #endif
00059 
00060 #ifndef M_LOG2E
00061 #define M_LOG2E 1.4426950408889634074   /* log_2 e */
00062 #endif
00063 
00064 #ifndef M_LOG10E
00065 #define M_LOG10E    0.43429448190325182765  /* log_10 e */
00066 #endif
00067 
00068 #ifndef M_LN2
00069 #define M_LN2       0.69314718055994530942  /* log_e 2 */
00070 #endif
00071 
00072 #ifndef M_LN10
00073 #define M_LN10         2.30258509299404568402  /* log_e 10 */
00074 #endif
00075 
00076 #ifndef M_PI
00077 #define M_PI        3.14159265358979323846  /* pi */
00078 #endif
00079 
00080 #ifndef M_PI_2
00081 #define M_PI_2      1.57079632679489661923  /* pi/2 */
00082 #endif
00083 
00084 #ifndef M_PI_4
00085 #define M_PI_4      0.78539816339744830962  /* pi/4 */
00086 #endif
00087 
00088 #ifndef M_1_PI
00089 #define M_1_PI      0.31830988618379067154  /* 1/pi */
00090 #endif
00091 
00092 #ifndef M_2_PI
00093 #define M_2_PI      0.63661977236758134308  /* 2/pi */
00094 #endif
00095 
00096 #ifndef M_2_SQRTPI
00097 #define M_2_SQRTPI  1.12837916709551257390  /* 2/sqrt(pi) */
00098 #endif
00099 
00100 #ifndef M_SQRT2
00101 #define M_SQRT2 1.41421356237309504880  /* sqrt(2) */
00102 #endif
00103 
00104 #ifndef M_SQRT1_2
00105 #define M_SQRT1_2   0.70710678118654752440  /* 1/sqrt(2) */
00106 #endif
00107 
00108 QWT_EXPORT double qwtGetMin( const double *array, int size );
00109 QWT_EXPORT double qwtGetMax( const double *array, int size );
00110 
00123 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
00124 {
00125     const double eps = qAbs( 1.0e-6 * intervalSize );
00126 
00127     if ( value2 - value1 > eps )
00128         return -1;
00129 
00130     if ( value1 - value2 > eps )
00131         return 1;
00132 
00133     return 0;
00134 }
00135 
00136 
00137 inline bool qwtFuzzyGreaterOrEqual( double d1, double d2 )
00138 {
00139     return ( d1 >= d2 ) || qFuzzyCompare( d1, d2 );
00140 }
00141 
00142 inline bool qwtFuzzyLessOrEqual( double d1, double d2 )
00143 {
00144     return ( d1 <= d2 ) || qFuzzyCompare( d1, d2 );
00145 }
00146 
00148 inline int qwtSign( double x )
00149 {
00150     if ( x > 0.0 )
00151         return 1;
00152     else if ( x < 0.0 )
00153         return ( -1 );
00154     else
00155         return 0;
00156 }
00157 
00159 inline double qwtSqr( double x )
00160 {
00161     return x * x;
00162 }
00163 
00165 inline double qwtRoundF(double d)
00166 { 
00167     return ::floor( d + 0.5 );
00168 }
00169 
00171 inline double qwtFloorF(double d)
00172 { 
00173     return ::floor( d );
00174 }
00175 
00177 inline double qwtCeilF(double d)
00178 { 
00179     return ::ceil( d );
00180 }
00181 
00182 #endif
qmi style