qwt_math.h
Go to the documentation of this file.
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 <qmath.h>
00027 #include "qwt_global.h"
00028 
00029 #ifndef M_PI_2
00030 // For Qt <= 4.8.4 M_PI_2 is not known by MinGW-w64 
00031 // when compiling with -std=c++11
00032 #define M_PI_2 (1.57079632679489661923)
00033 #endif
00034 
00035 #ifndef LOG_MIN
00036 
00037 #define LOG_MIN 1.0e-100
00038 #endif
00039 
00040 #ifndef LOG_MAX
00041 
00042 #define LOG_MAX 1.0e100
00043 #endif
00044 
00045 QWT_EXPORT double qwtGetMin( const double *array, int size );
00046 QWT_EXPORT double qwtGetMax( const double *array, int size );
00047 
00048 QWT_EXPORT double qwtNormalizeRadians( double radians );
00049 QWT_EXPORT double qwtNormalizeDegrees( double degrees );
00050 
00063 inline int qwtFuzzyCompare( double value1, double value2, double intervalSize )
00064 {
00065     const double eps = qAbs( 1.0e-6 * intervalSize );
00066 
00067     if ( value2 - value1 > eps )
00068         return -1;
00069 
00070     if ( value1 - value2 > eps )
00071         return 1;
00072 
00073     return 0;
00074 }
00075 
00077 inline int qwtSign( double x )
00078 {
00079     if ( x > 0.0 )
00080         return 1;
00081     else if ( x < 0.0 )
00082         return ( -1 );
00083     else
00084         return 0;
00085 }
00086 
00088 inline double qwtSqr( double x )
00089 {
00090     return x * x;
00091 }
00092 
00094 inline double qwtFastAtan( double x )
00095 {
00096     if ( x < -1.0 )
00097         return -M_PI_2 - x / ( x * x + 0.28 );
00098 
00099     if ( x > 1.0 )
00100         return M_PI_2 - x / ( x * x + 0.28 );
00101 
00102     return x / ( 1.0 + x * x * 0.28 );
00103 }
00104 
00106 inline double qwtFastAtan2( double y, double x )
00107 {
00108     if ( x > 0 )
00109         return qwtFastAtan( y / x );
00110 
00111     if ( x < 0 )
00112     {
00113         const double d = qwtFastAtan( y / x );
00114         return ( y >= 0 ) ? d + M_PI : d - M_PI;
00115     }
00116 
00117     if ( y < 0.0 )
00118         return -M_PI_2;
00119 
00120     if ( y > 0.0 )
00121         return M_PI_2;
00122 
00123     return 0.0;
00124 }
00125 
00126 /* !
00127    \brief Calculate a value of a cubic polynom 
00128 
00129    \param x Value
00130    \param a Cubic coefficient
00131    \param b Quadratic coefficient
00132    \param c Linear coefficient
00133    \param d Connstant offset
00134 
00135    \return Value of the polyonom for x
00136 */
00137 inline double qwtCubicPolynom( double x, 
00138     double a, double b, double c, double d )
00139 {
00140     return ( ( ( a * x ) + b ) * x + c ) * x + d;
00141 }
00142 
00144 inline double qwtRadians( double degrees )
00145 {
00146     return degrees * M_PI / 180.0;
00147 }
00148 
00150 inline double qwtDegrees( double degrees )
00151 {
00152     return degrees * 180.0 / M_PI;
00153 }
00154 
00155 #endif


plotjuggler
Author(s): Davide Faconti
autogenerated on Fri Sep 1 2017 02:41:56