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 | real operator <<(int x) const; |
---|
50 | real operator >>(int x) const; |
---|
51 | real &operator <<=(int x); |
---|
52 | real &operator >>=(int x); |
---|
53 | |
---|
54 | bool operator ==(real const &x) const; |
---|
55 | bool operator !=(real const &x) const; |
---|
56 | bool operator <(real const &x) const; |
---|
57 | bool operator >(real const &x) const; |
---|
58 | bool operator <=(real const &x) const; |
---|
59 | bool operator >=(real const &x) const; |
---|
60 | |
---|
61 | bool operator !() const; |
---|
62 | operator bool() const; |
---|
63 | |
---|
64 | friend real fabs(real const &x); |
---|
65 | |
---|
66 | friend real re(real const &x); |
---|
67 | friend real sqrt(real const &x); |
---|
68 | friend real log(real const &x); |
---|
69 | friend real exp(real const &x); |
---|
70 | |
---|
71 | friend real sin(real const &x); |
---|
72 | friend real cos(real const &x); |
---|
73 | |
---|
74 | void print(int ndigits = 150) const; |
---|
75 | |
---|
76 | static real const R_0; |
---|
77 | static real const R_1; |
---|
78 | static real const R_2; |
---|
79 | static real const R_10; |
---|
80 | |
---|
81 | static real const R_E; |
---|
82 | static real const R_LOG2E; |
---|
83 | static real const R_LOG10E; |
---|
84 | static real const R_LN2; |
---|
85 | static real const R_LN10; |
---|
86 | static real const R_PI; |
---|
87 | static real const R_PI_2; |
---|
88 | static real const R_PI_4; |
---|
89 | static real const R_1_PI; |
---|
90 | static real const R_2_PI; |
---|
91 | static real const R_2_SQRTPI; |
---|
92 | static real const R_SQRT2; |
---|
93 | static real const R_SQRT1_2; |
---|
94 | |
---|
95 | private: |
---|
96 | /* XXX: changing this requires tuning real::fres (the number of |
---|
97 | * Newton-Raphson iterations) and real::print (the number of printed |
---|
98 | * digits) */ |
---|
99 | static int const BIGITS = 32; |
---|
100 | |
---|
101 | uint32_t m_size; |
---|
102 | uint32_t m_signexp; |
---|
103 | uint16_t m_mantissa[BIGITS]; |
---|
104 | }; |
---|
105 | |
---|
106 | } /* namespace lol */ |
---|
107 | |
---|
108 | #endif // __LOL_REAL_H__ |
---|
109 | |
---|