1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | // |
---|
12 | // The Real class |
---|
13 | // -------------- |
---|
14 | // |
---|
15 | |
---|
16 | #if !defined __LOL_REAL_H__ |
---|
17 | #define __LOL_REAL_H__ |
---|
18 | |
---|
19 | #include <stdint.h> |
---|
20 | |
---|
21 | namespace lol |
---|
22 | { |
---|
23 | |
---|
24 | class real |
---|
25 | { |
---|
26 | public: |
---|
27 | inline real() { } |
---|
28 | |
---|
29 | real(float f); |
---|
30 | real(double f); |
---|
31 | real(int i); |
---|
32 | real(unsigned int i); |
---|
33 | |
---|
34 | operator float() const; |
---|
35 | operator double() const; |
---|
36 | operator int() const; |
---|
37 | operator unsigned int() const; |
---|
38 | |
---|
39 | real operator -() const; |
---|
40 | real operator +(real const &x) const; |
---|
41 | real operator -(real const &x) const; |
---|
42 | real operator *(real const &x) const; |
---|
43 | real operator /(real const &x) const; |
---|
44 | real &operator +=(real const &x); |
---|
45 | real &operator -=(real const &x); |
---|
46 | real &operator *=(real const &x); |
---|
47 | real &operator /=(real const &x); |
---|
48 | |
---|
49 | bool operator ==(real const &x) const; |
---|
50 | bool operator !=(real const &x) const; |
---|
51 | bool operator <(real const &x) const; |
---|
52 | bool operator >(real const &x) const; |
---|
53 | bool operator <=(real const &x) const; |
---|
54 | bool operator >=(real const &x) const; |
---|
55 | |
---|
56 | friend real fabs(real const &x); |
---|
57 | |
---|
58 | friend real fres(real const &x); |
---|
59 | friend real sqrt(real const &x); |
---|
60 | friend real exp(real const &x); |
---|
61 | |
---|
62 | friend real sin(real const &x); |
---|
63 | friend real cos(real const &x); |
---|
64 | |
---|
65 | void print(int ndigits = 150) const; |
---|
66 | |
---|
67 | private: |
---|
68 | /* XXX: changing this requires tuning real::fres (the number of |
---|
69 | * Newton-Raphson iterations) and real::print (the number of printed |
---|
70 | * digits) */ |
---|
71 | static int const BIGITS = 32; |
---|
72 | |
---|
73 | uint32_t m_size; |
---|
74 | uint32_t m_signexp; |
---|
75 | uint16_t m_mantissa[BIGITS]; |
---|
76 | }; |
---|
77 | |
---|
78 | } /* namespace lol */ |
---|
79 | |
---|
80 | #endif // __LOL_REAL_H__ |
---|
81 | |
---|