1
// ---------------------------------------------------------------------------
3
// - standard object library - real class definition -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2007 amaury darsch -
15
// ---------------------------------------------------------------------------
17
#ifndef AFNIX_REAL_HPP
18
#define AFNIX_REAL_HPP
20
#ifndef AFNIX_INTEGER_HPP
21
#include "Integer.hpp"
26
/// The Real class is a the object version of the native floating point
27
/// number. The real number is implemented like the integer class and
28
/// is derived from the Literal class. The class implements also a bunch of
29
/// method for floating point operations.
30
/// @author amaury darsch
32
class Real : public Literal {
34
/// the comparision epsilon
38
/// the real representation
42
/// create a new default real
45
/// create a new real from a native value
46
/// @param value the value to create
47
Real (const t_real value);
49
/// create a new real from an integer class
50
/// @param value the value to create
51
Real (const Integer& value);
53
/// create a new real from a string
54
/// @param value the value to convert
55
Real (const String& value);
57
/// copy constructor for this real
58
/// @param that the real class to copy
59
Real (const Real& that);
61
/// @return the class name
62
String repr (void) const;
64
/// @return a literal representation of this real
65
String toliteral (void) const;
67
/// @return a string representation of this real
68
String tostring (void) const;
70
/// @return a clone of this real
71
Object* clone (void) const;
73
/// @return the real serial code
74
t_byte serialid (void) const;
76
/// serialize this real to an output stream
77
/// @param os the output stream to write
78
void wrstream (class Output& os) const;
80
/// deserialize a real from an input stream
81
/// @param is the input steam to read in
82
void rdstream (class Input& is);
84
/// @return a formated string based on the precision
85
String format (const long precision) const;
87
/// @return a native value for this real
88
t_real toreal (void) const;
90
/// @return an integer representation from this real
91
t_long tointeger (void) const;
93
/// assign an real with a native value
94
/// @param value the value to assign
95
Real& operator = (const t_real value);
97
/// assign an real with a native value
98
/// @param value the value to assign
99
Real& operator = (const Real& value);
101
/// compute the opposite of the real
102
/// @param x the real to oppose
103
/// @return a new real opposite of the argument
104
friend Real operator - (const Real& x);
106
/// add two reals together
107
/// @param x the first argument to add
108
/// @param y the second argument to add
109
/// @return a new sum of the previous one
110
friend Real operator + (const Real& x, const Real& y);
112
/// subtract two reals together
113
/// @param x the first argument to subtract
114
/// @param y the second argument to subtract
115
/// @return a new real as the difference
116
friend Real operator - (const Real& x, const Real& y);
118
/// multiply two reals together
119
/// @param x the first argument to multiply
120
/// @param y the second argument to multiply
121
/// @return a new real product
122
friend Real operator * (const Real& x, const Real& y);
124
/// divide two reals together
125
/// @param x the numerator
126
/// @param y the denumerator
127
/// @return the division of the arguments
128
friend Real operator / (const Real& x, const Real& y);
130
/// add a real to this one
131
/// @param x the argument to add
132
/// @return this added real
133
Real& operator += (const Real& x);
135
/// substract a real to this one
136
/// @param x the argument to substract
137
/// @return this added real
138
Real& operator -= (const Real& x);
140
/// multiply a real with this one
141
/// @param x the argument to multiply
142
/// @return this multiplied real
143
Real& operator *= (const Real& x);
145
/// multiply a real with this one
146
/// @param x the argument to multiply
147
/// @return this multiplied real
148
Real& operator /= (const Real& x);
150
/// prefix add one to the real
151
Real& operator ++ (void);
153
/// postfix add one to the real
154
Real operator ++ (int);
156
/// prefix sub one to the real
157
Real& operator -- (void);
159
/// postfix sub one to the real
160
Real operator -- (int);
162
/// compare this real with a native value
163
/// @param value the value to compare
164
/// @return true if they are equals
165
bool operator == (const t_long value) const;
167
/// compare this real with a native value
168
/// @param value the value to compare
169
/// @return true if they are not equals
170
bool operator != (const t_long value) const;
172
/// compare this real with a native value
173
/// @param value the value to compare
174
/// @return true if they are equals
175
bool operator == (const t_real value) const;
177
/// compare this real with a native value
178
/// @param value the value to compare
179
/// @return true if they are not equals
180
bool operator != (const t_real value) const;
182
/// compare two reals
183
/// @param value the value to compare
184
/// @return true if they are equals
185
bool operator == (const Real& value) const;
187
/// compare two reals
188
/// @param value the value to compare
189
/// @return true if they are not equals
190
bool operator != (const Real& value) const;
192
/// compare two reals
193
/// @param value the value to compare
194
/// @return true if they are less
195
bool operator < (const Real& value) const;
197
/// compare two reals
198
/// @param value the value to compare
199
/// @return true if they are less or equal
200
bool operator <= (const Real& value) const;
202
/// compare two reals
203
/// @param value the value to compare
204
/// @return true if they are greater
205
bool operator > (const Real& value) const;
207
/// compare two reals
208
/// @param value the value to compare
209
/// @return true if they are greater or equal
210
bool operator >= (const Real& value) const;
212
/// compare this real with another one upto epsilon
213
/// @param value the real value to compare
214
bool cmp (const t_real value) const;
216
/// @return true if this real is zero
217
bool iszero (void) const;
219
/// @return true if the number is nan
220
bool isnan (void) const;
222
/// @return the ceiling of this number
223
Real ceiling (void) const;
225
/// @return the floor of this number
226
Real floor (void) const;
228
/// @return the absolute value of this number
229
Real abs (void) const;
231
/// @return the remainder of this value with the argument
232
Real mod (const Real& x) const;
234
/// @return the square root of this real
235
Real sqrt (void) const;
237
/// @return the natural logarithm of this number
238
Real log (void) const;
240
/// @return the exponential of this number
241
Real exp (void) const;
243
/// @return the power of this number with its argument
244
Real pow (const Real& x) const;
246
/// @return the sine of this number
247
Real sin (void) const;
249
/// @return the cosine of this number
250
Real cos (void) const;
252
/// @return the tangent of this number
253
Real tan (void) const;
255
/// @return the arc sine of this number
256
Real asin (void) const;
258
/// @return the arc cosine of this number
259
Real acos (void) const;
261
/// @return the arc tangent of this number
262
Real atan (void) const;
264
/// @return the hyperbolic sine of this number
265
Real sinh (void) const;
267
/// @return the hyperbolic cosine of this number
268
Real cosh (void) const;
270
/// @return the hyperbolic tangent of this number
271
Real tanh (void) const;
273
/// @return the hyperbolic arc sine of this number
274
Real asinh (void) const;
276
/// @return the hyperbolic arc cosine of this number
277
Real acosh (void) const;
279
/// @return the hyperbolic arc tangent of this number
280
Real atanh (void) const;
283
/// evaluate an object to a real value
284
/// @param robj the current runnable
285
/// @param nset the current nameset
286
/// @param object the object to evaluate
287
static t_real evalto (Runnable* robj, Nameset* nset, Object* object);
289
/// create a new object in a generic way
290
/// @param argv the argument vector
291
static Object* mknew (Vector* argv);
293
/// @return true if the given quark is defined
294
bool isquark (const long quark, const bool hflg) const;
296
/// operate this object with another object
297
/// @param type the operator type
298
/// @param object the operand object
299
Object* oper (t_oper type, Object* object);
301
/// set an object to this real
302
/// @param robj the current runnable
303
/// @param nset the current nameset
304
/// @param object the object to set
305
Object* vdef (Runnable* robj, Nameset* nset, Object* object);
307
/// apply this real with a set of arguments and a quark
308
/// @param robj the current runnable
309
/// @param nset the current nameset
310
/// @param quark the quark to apply these arguments
311
/// @param argv the arguments to apply
312
Object* apply (Runnable* robj, Nameset* nset, const long quark,
316
// the memory allocation
317
void* operator new (const t_size size);
318
void operator delete (void* handle);