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

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

core: add exp() for real numbers and fix the == operator.

File size: 1.8 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 fres(real const &x);
57    friend real sqrt(real const &x);
58    friend real exp(real const &x);
59
60    void print(int ndigits = 150) const;
61
62private:
63    /* XXX: changing this requires tuning real::fres (the number of
64     * Newton-Raphson iterations) and real::print (the number of printed
65     * digits) */
66    static int const BIGITS = 32;
67
68    uint32_t m_size;
69    uint32_t m_signexp;
70    uint16_t m_mantissa[BIGITS];
71};
72
73} /* namespace lol */
74
75#endif // __LOL_REAL_H__
76
Note: See TracBrowser for help on using the repository browser.