1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //    $Id: mmath.h,v 1.1.1.1 2003/10/27 18:54:47 wschweer Exp $
5 //
6 //  (C) Copyright 2000 Werner Schweer (ws@seh.de)
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; version 2 of
11 //  the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 //
22 //=========================================================
23 
24 #ifndef __MATH_H__
25 #define __MATH_H__
26 
27 #define LOG_MIN 1.0e-100
28 #define LOG_MAX 1.0e100
29 
30 namespace MusECore {
31 
32 double qwtCeil125(double x);
33 double qwtFloor125(double x);
34 void qwtTwistArray(double *array, int size);
35 int qwtChkMono(double *array, int size);
36 void qwtLinSpace(double *array, int size, double xmin, double xmax);
37 void qwtLogSpace(double *array, int size, double xmin, double xmax);
38 
39 template <class T>
qwtSign(const T & x)40 inline int qwtSign(const T& x)
41 {
42     if (x > T(0))
43        return 1;
44     else if (x < T(0))
45        return (-1);
46     else
47        return 0;
48 }
49 
qwtInt(double x)50 inline int qwtInt(double x)
51 {
52     return int(rint(x));
53 }
54 
55 template <class T>
qwtAbs(const T & x)56 inline T qwtAbs (const T& x)
57 {
58     return( x > T(0) ? x : -x );
59 }
60 
61 template <class T>
qwtMax(const T & x,const T & y)62 inline const T& qwtMax (const T& x, const T& y)
63 {
64     return ( x > y ? x : y );
65 }
66 
67 template <class T>
qwtMin(const T & x,const T & y)68 inline const T& qwtMin ( const T& x, const T& y)
69 {
70     return ( x < y ? x : y );
71 }
72 
73 
74 template <class T>
qwtLim(const T & x,const T & x1,const T & x2)75 T qwtLim(const T& x, const T& x1, const T& x2)
76 {
77     T rv;
78     T xmin, xmax;
79 
80     xmin = qwtMin(x1, x2);
81     xmax = qwtMax(x1, x2);
82 
83     if ( x < xmin )
84        rv = xmin;
85     else if ( x > xmax )
86        rv = xmax;
87     else
88        rv = x;
89 
90     return rv;
91 }
92 
93 }
94 
95 #endif
96 
97