# source:trunk/src/real.h@992Tweet

Last change on this file since 992 was 992, checked in by sam, 11 years ago

core: implement log() for real numbers, and start documenting our next
improved implementation of exp(), which relies on log().

File size: 1.9 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
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
21namespace lol
22{
23
24class real
25{
26public:
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 log(real const &x);
61    friend real exp(real const &x);
62
63    friend real sin(real const &x);
64    friend real cos(real const &x);
65
66    void print(int ndigits = 150) const;
67
68private:
69    /* XXX: changing this requires tuning real::fres (the number of
70     * Newton-Raphson iterations) and real::print (the number of printed
71     * digits) */
72    static int const BIGITS = 32;
73
74    uint32_t m_size;
75    uint32_t m_signexp;
76    uint16_t m_mantissa[BIGITS];
77};
78
79} /* namespace lol */
80
81#endif // __LOL_REAL_H__
82
Note: See TracBrowser for help on using the repository browser.