~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/lib/std/shl/obj/Real.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-03-16 21:31:18 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110316213118-gk4k3ez3e5d2huna
Tags: 2.0.0-1
* QA upload.
* New upstream release
* Debian source format is 3.0 (quilt)
* Fix debhelper-but-no-misc-depends
* Fix ancient-standards-version
* Fix package-contains-linda-override
* debhelper compatibility is 7
* Fix dh-clean-k-is-deprecated

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ---------------------------------------------------------------------------
2
 
// - Real.hpp                                                                -
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.                  -
7
 
// -                                                                         -
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
 
// ---------------------------------------------------------------------------
16
 
 
17
 
#ifndef AFNIX_REAL_HPP
18
 
#define AFNIX_REAL_HPP
19
 
 
20
 
#ifndef  AFNIX_INTEGER_HPP
21
 
#include "Integer.hpp"
22
 
#endif
23
 
 
24
 
namespace afnix {
25
 
 
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
31
 
 
32
 
  class Real : public Literal {
33
 
  public:
34
 
    /// the comparision epsilon
35
 
    static t_real d_eps;
36
 
 
37
 
  private:
38
 
    /// the real representation
39
 
    t_real d_value;
40
 
 
41
 
  public:
42
 
    /// create a new default real
43
 
    Real (void);
44
 
 
45
 
    /// create a new real from a native value
46
 
    /// @param value the value to create
47
 
    Real (const t_real value);
48
 
 
49
 
    /// create a new real from an integer class
50
 
    /// @param value the value to create
51
 
    Real (const Integer& value);
52
 
 
53
 
    /// create a new real from a string
54
 
    /// @param value the value to convert
55
 
    Real (const String& value);
56
 
 
57
 
    /// copy constructor for this real
58
 
    /// @param that the real class to copy
59
 
    Real (const Real& that);
60
 
 
61
 
    /// @return the class name
62
 
    String repr (void) const;
63
 
 
64
 
    /// @return a literal representation of this real
65
 
    String toliteral (void) const;
66
 
 
67
 
    /// @return a string representation of this real
68
 
    String tostring (void) const;
69
 
 
70
 
    /// @return a clone of this real
71
 
    Object* clone (void) const;
72
 
 
73
 
    /// @return the real serial code
74
 
    t_byte serialid (void) const;
75
 
 
76
 
    /// serialize this real to an output stream
77
 
    /// @param os the output stream to write
78
 
    void wrstream (class Output& os) const;
79
 
 
80
 
    /// deserialize a real from an input stream
81
 
    /// @param is the input steam to read in
82
 
    void rdstream (class Input& is);
83
 
 
84
 
    /// @return a formated string based on the precision
85
 
    String format (const long precision) const;
86
 
 
87
 
    /// @return a native value for this real
88
 
    t_real toreal (void) const;
89
 
 
90
 
    /// @return an integer representation from this real
91
 
    t_long tointeger (void) const;
92
 
 
93
 
    /// assign an real with a native value
94
 
    /// @param value the value to assign
95
 
    Real& operator = (const t_real value);
96
 
 
97
 
    /// assign an real with a native value
98
 
    /// @param value the value to assign
99
 
    Real& operator = (const Real& value);
100
 
 
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);
105
 
 
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);
111
 
 
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);
117
 
 
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);
123
 
 
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);
129
 
 
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);
134
 
 
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);
139
 
 
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);
144
 
 
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);
149
 
 
150
 
    /// prefix add one to the real
151
 
    Real& operator ++ (void);
152
 
 
153
 
    /// postfix add one to the real
154
 
    Real operator ++ (int);
155
 
 
156
 
    /// prefix sub one to the real
157
 
    Real& operator -- (void);
158
 
 
159
 
    /// postfix sub one to the real
160
 
    Real operator -- (int);
161
 
 
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;
166
 
 
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;
171
 
 
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;
176
 
 
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;
181
 
 
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;
186
 
 
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;
191
 
 
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;
196
 
 
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;
201
 
 
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;
206
 
 
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;
211
 
 
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;
215
 
 
216
 
    /// @return true if this real is zero
217
 
    bool iszero (void) const;
218
 
 
219
 
    /// @return true if the number is nan
220
 
    bool isnan (void) const;
221
 
  
222
 
    /// @return the ceiling of this number
223
 
    Real ceiling (void) const;
224
 
 
225
 
    /// @return the floor of this number
226
 
    Real floor (void) const;
227
 
 
228
 
    /// @return the absolute value of this number
229
 
    Real abs (void) const;
230
 
 
231
 
    /// @return the remainder of this value with the argument
232
 
    Real mod (const Real& x) const;
233
 
 
234
 
    /// @return the square root of this real
235
 
    Real sqrt (void) const;
236
 
 
237
 
    /// @return the natural logarithm of this number
238
 
    Real log (void) const;
239
 
 
240
 
    /// @return the exponential of this number
241
 
    Real exp (void) const;
242
 
 
243
 
    /// @return the power of this number with its argument
244
 
    Real pow (const Real& x) const;
245
 
 
246
 
    /// @return the sine of this number
247
 
    Real sin (void) const;
248
 
 
249
 
    /// @return the cosine of this number
250
 
    Real cos (void) const;
251
 
 
252
 
    /// @return the tangent of this number
253
 
    Real tan (void) const;
254
 
 
255
 
    /// @return the arc sine of this number
256
 
    Real asin (void) const;
257
 
 
258
 
    /// @return the arc cosine of this number
259
 
    Real acos (void) const;
260
 
 
261
 
    /// @return the arc tangent of this number
262
 
    Real atan (void) const;
263
 
 
264
 
    /// @return the hyperbolic sine of this number
265
 
    Real sinh (void) const;
266
 
 
267
 
    /// @return the hyperbolic cosine of this number
268
 
    Real cosh (void) const;
269
 
 
270
 
    /// @return the hyperbolic tangent of this number
271
 
    Real tanh (void) const;
272
 
 
273
 
    /// @return the hyperbolic arc sine of this number
274
 
    Real asinh (void) const;
275
 
 
276
 
    /// @return the hyperbolic arc cosine of this number
277
 
    Real acosh (void) const;
278
 
 
279
 
    /// @return the hyperbolic arc tangent of this number
280
 
    Real atanh (void) const;
281
 
 
282
 
  public:
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);
288
 
 
289
 
    /// create a new object in a generic way
290
 
    /// @param argv the argument vector
291
 
    static Object* mknew (Vector* argv);
292
 
 
293
 
    /// @return true if the given quark is defined
294
 
    bool isquark (const long quark, const bool hflg) const;
295
 
 
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);
300
 
 
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);
306
 
 
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,
313
 
                   Vector* argv);
314
 
    
315
 
  public:
316
 
    // the memory allocation
317
 
    void* operator new    (const t_size size);
318
 
    void  operator delete (void* handle);
319
 
  };
320
 
}
321
 
 
322
 
#endif