File: real.h

package info (click to toggle)
xjig 2.4-14.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 892 kB
  • sloc: cpp: 10,177; makefile: 1,142; perl: 23
file content (192 lines) | stat: -rw-r--r-- 6,068 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef _real_h
#define _real_h

// copied from math.h
// #ifndef M_PI
// #	define M_PI    3.14159265358979323846
// #endif

#if (!REAL_IS_CLASS)
#	if (REAL_IS_FLOAT)
		typedef float Real;
#	else
		typedef double Real;
#	endif
#	define	_RealZero		0.0
#else

class Real {
	public:
		Real(const Real &r)           { d=r.d; }
		Real(int l_val)              { d = (double)l_val; }
		Real(double d_val)            { d = d_val; }
		Real()                        { }
		operator double() const       { return (double)d; }
//		operator int() const          { return (int)d; }

	const Real& operator=(const Real &z);

	inline const Real& operator+=(const Real &z);
	inline const Real& operator+=(double d);
	inline Real Real::operator+(const Real&) const;
	friend inline Real operator+(double, const Real&);
	friend inline Real operator+(const Real&, double);

	inline const Real& operator-=(const Real &z);
	inline const Real& operator-=(double d);
	inline Real Real::operator-(const Real&) const;
	friend inline Real operator-(double, const Real&);
	friend inline Real operator-(const Real&, double);

	inline const Real& operator*=(const Real &z);
	inline const Real& operator*=(double d);
	inline Real Real::operator*(const Real&) const;
	friend inline Real operator*(double, const Real&);
	friend inline Real operator*(const Real&, double);

	inline const Real& operator/=(const Real &z);
	inline const Real& operator/=(double d);
	inline Real Real::operator/(const Real&) const;
	friend inline Real operator/(double, const Real&);
	friend inline Real operator/(const Real&, double);

	friend inline int operator==(const Real&, const Real&);
	friend inline int operator!=(const Real&, const Real&);
	friend inline int operator<=(const Real&, const Real&);
	friend inline int operator>=(const Real&, const Real&);
	friend inline int operator< (const Real&, const Real&);
	friend inline int operator> (const Real&, const Real&);

	friend inline int operator==(const Real&, double d);
	friend inline int operator!=(const Real&, double d);
	friend inline int operator<=(const Real&, double d);
	friend inline int operator>=(const Real&, double d);
	friend inline int operator< (const Real&, double d);
	friend inline int operator> (const Real&, double d);

	inline int  operator!() const	{ return (d)?0:1; }
	inline Real operator+() const  { return *this; }
	inline Real operator-() const  { return Real(-d); }

	private:
//		Real(	long )		{}
//		Real( int )		{}

#if (REAL_IS_FLOAT)
		float		d;
#else
		double	d;
#endif
};

//--------------------------------------------------------------------------

inline const Real& Real::operator=(const Real &z)
{
			d = z.d;
			return *this;
}

inline const Real& Real::operator+=(const Real &z)
{
			d += z.d;
			return *this;
}
inline const Real& Real::operator-=(const Real &z)
{
			d -= z.d;
			return *this;
}
inline const Real& Real::operator*=(const Real &z)
{
			d *= z.d;
			return *this;
}
inline const Real& Real::operator/=(const Real &z)
{
			d /= z.d;
			return *this;
}

//--------------------------------------------------------------------------

inline int operator==(const Real& z1, const Real& z2)
{       return z1.d == z2.d;     }
inline int operator!=(const Real& z1, const Real& z2)
{       return z1.d != z2.d;     }
inline int operator<(const Real& z1, const Real& z2)
{       return z1.d < z2.d;      }
inline int operator>(const Real& z1, const Real& z2)
{       return z1.d > z2.d;      }
inline int operator<=(const Real& z1, const Real& z2)
{       return z1.d <= z2.d;     }
inline int operator>=(const Real& z1, const Real& z2)
{       return z1.d >= z2.d;     }

inline int operator==(const Real& z1, double d)
{       return z1.d == d;     }
inline int operator!=(const Real& z1, double d)
{       return z1.d != d;     }
inline int operator<(const Real& z1, double d)
{       return z1.d < d;      }
inline int operator>(const Real& z1, double d)
{       return z1.d > d;      }
inline int operator<=(const Real& z1, double d)
{       return z1.d <= d;     }
inline int operator>=(const Real& z1, double d)
{       return z1.d >= d;     }

//--------------------------------------------------------------------------
inline Real Real::operator+( const Real &z ) const	{ Real erg(*this); erg+=z; return erg; }
inline const Real& Real::operator+=(double d)      { return *this+=Real(d); }
inline Real operator+( double d, const Real &z2 )  { return Real(d)+z2; }
inline Real operator+( const Real &z1, double d )  { return z1+Real(d); }

inline Real Real::operator-( const Real &z ) const	{ Real erg(*this); erg-=z; return erg; }
inline const Real& Real::operator-=(double d)      { return *this-=Real(d); }
inline Real operator-( double d, const Real &z2 )  { return Real(d)-z2; }
inline Real operator-( const Real &z1, double d )  { return z1-Real(d); }

inline Real Real::operator*( const Real &z ) const	{ Real erg(*this); erg*=z; return erg; }
inline const Real& Real::operator*=(double d)      { return *this*=Real(d); }
inline Real operator*( double d, const Real &z2 )  { return Real(d)*z2; }
inline Real operator*( const Real &z1, double d )  { return z1*Real(d); }

inline Real Real::operator/( const Real &z ) const	{ Real erg(*this); erg/=z; return erg; }
inline const Real& Real::operator/=(double d)      { return *this/=Real(d); }
inline Real operator/( double d, const Real &z2 )  { return Real(d)/z2; }
inline Real operator/( const Real &z1, double d )  { return z1/Real(d); }
//--------------------------------------------------------------------------



#endif

#ifndef RealZero
	extern const Real RealZero;	// Null als Konstante der Klasse
#endif


class FunTab {
	public:
		FunTab( double (*fkt)(double), double from=0.0, double to=360.0, int step=360 );
		~FunTab();

		const Real &GetVal( const Real &in ) const;
		Real GetRezVal( const Real &in ) const;

	private:
		Real *val;

		Real 		from;
		Real		to;
		int		step;
		Real		interval;
};

extern "C" {
double floor( double x );			// aus math.h
}
inline int rtoi(const Real &r) 	{ return (int)floor((double)r+0.5); }

#endif