source: trunk/src/real.h @ 1082

Last change on this file since 1082 was 1082, checked in by sam, 8 years ago

core: port all code to NativeClient. Nothing runs for now, but it builds.

File size: 4.0 KB
Line 
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/* Avoid issues with NaCl headers */
22#undef log2
23
24namespace lol
25{
26
27class real
28{
29public:
30    real();
31    real(real const &x);
32    real const &operator =(real const &x);
33    ~real();
34
35    real(float f);
36    real(double f);
37    real(int i);
38    real(unsigned int i);
39
40    operator float() const;
41    operator double() const;
42    operator int() const;
43    operator unsigned int() const;
44
45    real operator +() const;
46    real operator -() const;
47    real operator +(real const &x) const;
48    real operator -(real const &x) const;
49    real operator *(real const &x) const;
50    real operator /(real const &x) const;
51    real const &operator +=(real const &x);
52    real const &operator -=(real const &x);
53    real const &operator *=(real const &x);
54    real const &operator /=(real const &x);
55
56    real operator <<(int x) const;
57    real operator >>(int x) const;
58    real const &operator <<=(int x);
59    real const &operator >>=(int x);
60
61    bool operator ==(real const &x) const;
62    bool operator !=(real const &x) const;
63    bool operator <(real const &x) const;
64    bool operator >(real const &x) const;
65    bool operator <=(real const &x) const;
66    bool operator >=(real const &x) const;
67
68    bool operator !() const;
69    operator bool() const;
70
71    /* Trigonometric functions */
72    friend real sin(real const &x);
73    friend real cos(real const &x);
74    friend real tan(real const &x);
75    friend real asin(real const &x);
76    friend real acos(real const &x);
77    friend real atan(real const &x);
78    friend real atan2(real const &y, real const &x);
79
80    /* Hyperbolic functions */
81    friend real sinh(real const &x);
82    friend real cosh(real const &x);
83    friend real tanh(real const &x);
84
85    /* Exponential and logarithmic functions */
86    friend real exp(real const &x);
87    friend real exp2(real const &x);
88    friend real log(real const &x);
89    friend real log2(real const &x);
90    friend real log10(real const &x);
91    friend real frexp(real const &x, int *exp);
92    friend real ldexp(real const &x, int exp);
93    friend real modf(real const &x, real *iptr);
94
95    /* Power functions */
96    friend real re(real const &x);
97    friend real sqrt(real const &x);
98    friend real cbrt(real const &x);
99    friend real pow(real const &x, real const &y);
100    friend real gamma(real const &x);
101
102    /* Rounding, absolute value, remainder etc. */
103    friend real ceil(real const &x);
104    friend real copysign(real const &x, real const &y);
105    friend real floor(real const &x);
106    friend real fabs(real const &x);
107    friend real round(real const &x);
108    friend real fmod(real const &x, real const &y);
109
110    void hexprint() const;
111    void print(int ndigits = 150) const;
112
113    static real const R_0;
114    static real const R_1;
115    static real const R_2;
116    static real const R_3;
117    static real const R_10;
118
119    static real const R_E;
120    static real const R_LOG2E;
121    static real const R_LOG10E;
122    static real const R_LN2;
123    static real const R_LN10;
124    static real const R_PI;
125    static real const R_PI_2;
126    static real const R_PI_3;
127    static real const R_PI_4;
128    static real const R_1_PI;
129    static real const R_2_PI;
130    static real const R_2_SQRTPI;
131    static real const R_SQRT2;
132    static real const R_SQRT3;
133    static real const R_SQRT1_2;
134
135    /* XXX: changing this requires tuning real::fres (the number of
136     * Newton-Raphson iterations) and real::print (the number of printed
137     * digits) */
138    static int const BIGITS = 16;
139    static int const BIGIT_BITS = 32;
140
141private:
142    uint32_t *m_mantissa;
143    uint32_t m_signexp;
144};
145
146} /* namespace lol */
147
148#endif // __LOL_REAL_H__
149
Note: See TracBrowser for help on using the repository browser.