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

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

core: add operators +=, *= etc. to the real class, and refactor the
print() method so that it displays decimal values.

File size: 1.5 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{
26    static int const BIGITS = 32;
27
28public:
29    inline real() { }
30
31    real(float f);
32    real(double f);
33    real(int i);
34    real(unsigned int i);
35
36    operator float() const;
37    operator double() const;
38    operator int() const;
39    operator unsigned int() const;
40
41    real operator -() const;
42    real operator +(real const &x) const;
43    real operator -(real const &x) const;
44    real operator *(real const &x) const;
45    real operator /(real const &x) const;
46    real &operator +=(real const &x);
47    real &operator -=(real const &x);
48    real &operator *=(real const &x);
49    real &operator /=(real const &x);
50
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    bool operator <=(real const &x) const;
56    bool operator >=(real const &x) const;
57
58    friend real fres(real const &x);
59
60    void print() const;
61
62private:
63    uint32_t m_size;
64    uint32_t m_signexp;
65    uint16_t m_mantissa[BIGITS];
66};
67
68} /* namespace lol */
69
70#endif // __LOL_REAL_H__
71
Note: See TracBrowser for help on using the repository browser.