author | celestar |
Tue, 13 Mar 2007 21:49:33 +0000 | |
branch | gamebalance |
changeset 9887 | 3d32aa4ae67c |
parent 9882 | 059933c94c5d |
child 9898 | 324dad59eb35 |
permissions | -rw-r--r-- |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
1 |
/* $Id */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
2 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
3 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
4 |
* @file |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
5 |
* Implements a Fixed-point data type. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
6 |
* This files defines a new data type |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
7 |
* "FixedT<Tstorage, Tdec_bits>", which can be used to compute fractional |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
8 |
* numbers without having to worry about network stability (because |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
9 |
* there is no real rounding taking place. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
10 |
* Use "Fixed" for the defaults values (48 bits integral part, 16 bits |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
11 |
* fractional part) or "FixedT<typename, int>" for flexible sizes. "int" |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
12 |
* number of bits are taken from a variable of "typename" for the fractional |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
13 |
* representation, the rest stays available for the integral part. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
14 |
* @warning More than 16 bits fractional should not be used when working |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
15 |
* with large integers. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
16 |
* @warning More than 31 fractional bits are not supported, and will |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
17 |
* trigger a compiler warning with appropriate settings. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
18 |
* @warning There are no warnings for buffer overflows. Those are very likely |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
19 |
* to happen with divisions, as those first shift the numerator by the number |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
20 |
* of fractional bits. Use multiplication with the reciprocal whereever |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
21 |
* it is possible. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
22 |
* @warning Please use signed variables for storage at the moment ONLY |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
23 |
* |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
24 |
* Variables can be initialized: |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
25 |
* - with integers: "FixedT<int, 9> a = -5" |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
26 |
* - with fractionals: "FixedT<int64, 11> b(7, 2);" where the first number is |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
27 |
* the numerator and the second is the denominator. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
28 |
* - not at all: "Fixed c;", which will automatically set c to zero. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
29 |
* |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
30 |
* @example fixed_ex.cpp How to initialize Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
31 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
32 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
33 |
/* Included to overload the stream operator << */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
34 |
#include <iostream> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
35 |
/* Needed for some ottd-specific data types */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
36 |
#include "stdafx.h" |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
37 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
38 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
39 |
* Base Class for storing fixed-point data types. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
40 |
* Fixed-point data types are stored in a single integer-type variable |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
41 |
* (Tstorage) of which a certain number of bits (Tdec_bits) is used to |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
42 |
* represent the fractional part of the number. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
43 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
44 |
template <typename Tstorage, int Tdec_bits> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
45 |
class FixedRawT { |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
46 |
public: |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
47 |
/** The number of bits that represent the fractional */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
48 |
static const int dec_bits = Tdec_bits; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
49 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
50 |
/** The storage of the number itself */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
51 |
Tstorage m_data; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
52 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
53 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
54 |
* Basic constructor for integer arguments. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
55 |
* @param value The raw value to which we want to initialize |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
56 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
57 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
58 |
FixedRawT(T value) : m_data(value) {} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
59 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
60 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
61 |
* Make sure that a Fixed variable is always inizialized to zero by default. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
62 |
* We need this ctor so that we can declare variable without |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
63 |
* the need to initialize it explicitly |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
64 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
65 |
FixedRawT() : m_data (0) {} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
66 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
67 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
68 |
* Returns the biggest integral number we can represent |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
69 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
70 |
int64 FIXED_MAX() const { return m_maximum; } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
71 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
72 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
73 |
* Returns the biggest integral number we can represent |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
74 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
75 |
int64 FIXED_MIN() const { return m_minimum; } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
76 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
77 |
private: |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
78 |
/** The largest number we can hold */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
79 |
static const int64 m_maximum = +(1ULL << ((sizeof(Tstorage) * 8) - Tdec_bits - 1)) - 1; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
80 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
81 |
/** The smallest number we can hold */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
82 |
static const int64 m_minimum = -(1ULL << ((sizeof(Tstorage) * 8) - Tdec_bits - 1)) - 0; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
83 |
}; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
84 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
85 |
/* forward-declare some structs */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
86 |
template <typename Tstorage, int Tdec_bits> class FixedT; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
87 |
template <typename T> struct FixedHelperT; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
88 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
89 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
90 |
* Specialization of FixedHelperT. Used to decimal-align two variables of Fixed type. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
91 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
92 |
template <typename Tstorage, int Tdec_bits> struct FixedHelperT<FixedRawT<Tstorage, Tdec_bits> > |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
93 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
94 |
/** The number of bits used for the fraction */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
95 |
static const int dec_bits = Tdec_bits; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
96 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
97 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
98 |
* Gives the raw data of a FixedRaw |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
99 |
* @param t The number to return |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
100 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
101 |
static int64 Raw(const FixedRawT<Tstorage, Tdec_bits>& t) {return (int64)t.m_data;} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
102 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
103 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
104 |
* Returns the data from FixedRawT aligned so that it is aligned to a given number |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
105 |
* @param t The number to be aligned |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
106 |
* @param bits The number of bits in the fractional part to be aligned to |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
107 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
108 |
static int64 Raw(const FixedRawT<Tstorage, Tdec_bits>& t, int bits) |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
109 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
110 |
return (((int64)t.m_data) << (bits > Tdec_bits ? bits - Tdec_bits : 0)) >> (bits < Tdec_bits ? Tdec_bits - bits : 0); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
111 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
112 |
}; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
113 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
114 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
115 |
* Specialization of FixedHelperT. Used to decimal-align two variables of Fixed type. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
116 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
117 |
template <typename Tstorage, int Tdec_bits> struct FixedHelperT<FixedT<Tstorage, Tdec_bits> > : public FixedHelperT<FixedRawT<Tstorage, Tdec_bits> > {}; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
118 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
119 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
120 |
* General implementation of FixedHelperT. This tempate makes sure that |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
121 |
* some number supplied is properly aligned at the decimal |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
122 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
123 |
template <typename T> struct FixedHelperT |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
124 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
125 |
/** This version of FixedHelperT is only used for full integers, so assume the number of dec_bits to be zero */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
126 |
static const int dec_bits = 0; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
127 |
/** Converts a full integer to one that has a given number of fractional bits, assumes |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
128 |
* the number of fractional bits to be zero. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
129 |
* @param t the number to be converted |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
130 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
131 |
static int64 Raw(const T& t) {return (int64)t;} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
132 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
133 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
134 |
* Converts a full integer to one that has a given number of fractional bits |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
135 |
* @param bits the number of bits for the fraction |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
136 |
* @param t the number to be converted |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
137 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
138 |
static int64 Raw(const T& t, int bits) {return ((int64)t) << bits;} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
139 |
}; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
140 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
141 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
142 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
143 |
* A class that defines a fixed-point data type, which a variable length and precision. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
144 |
* The data type that is defined is a fixed-point variable that has and number of Tdec_bits |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
145 |
* bits to represent the fractional part, the remaining bits of Tstorage are then used for |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
146 |
* the integer part of the number. This means, we always need to make a trade-off between |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
147 |
* the precision we want (higher number in Tdec_bits) and the range (smaller number of |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
148 |
* Tdec_bits). This class here only defines the constructors and the operators, everything |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
149 |
* else is happning in helper classes. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
150 |
* @note for usage of fprintf and similar, explicit casts are needed (double or int64). |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
151 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
152 |
template <typename Tstorage, int Tdec_bits> class FixedT : public FixedRawT<Tstorage, Tdec_bits> { |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
153 |
/* private block up here, because we need the typedef later on */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
154 |
private: |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
155 |
/** We shortcut the underlying data type to "Raw", to save typing */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
156 |
typedef FixedRawT<Tstorage, Tdec_bits> Raw; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
157 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
158 |
public: |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
159 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
160 |
* Ctor for assignment with other, non floating, variable types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
161 |
* @param value The Value we should assign to the Fixed |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
162 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
163 |
template <typename T> FixedT(T value) : Raw(FixedHelperT<T>::Raw(value, Tdec_bits)) {} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
164 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
165 |
/** As a constructor without initializing, just use the one that Raw uses. Sets a variable to zero */ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
166 |
FixedT() : Raw() {} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
167 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
168 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
169 |
* Ctor for use with a fraction, useful for initing a variable to a non-integer number at declaration. |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
170 |
* @param numerator The Nominator of the fraction |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
171 |
* @param denominator The Denominator of the fraction |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
172 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
173 |
FixedT(int numerator, int denominator) {Raw::m_data = ((int64)numerator << Raw::dec_bits) / (int64)denominator;} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
174 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
175 |
/** |
9879
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
176 |
* Cast to a double (for outputs) |
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
177 |
*/ |
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
178 |
operator double() const |
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
179 |
{ |
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
180 |
return (double)Raw::m_data / (1 << Raw::dec_bits); |
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
181 |
} |
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
182 |
|
c552b8cedd3d
(svn r9110) [gamebalance] -Add: Added a double-cast operator for FixedT data type for C-compatible output with fprintf.
celestar
parents:
9878
diff
changeset
|
183 |
/** |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
184 |
* Equality operator |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
185 |
* @param comparator The non-floating point variable we want to compare against |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
186 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
187 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
188 |
bool operator ==(const T &comparator) const { return Raw::m_data == (Tstorage)FixedHelperT<T>::Raw(comparator, Tdec_bits); } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
189 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
190 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
191 |
* Inequality operator |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
192 |
* @param comparator The non-floating point variable we want to compare against |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
193 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
194 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
195 |
bool operator !=(const T &comparator) const { return Raw::m_data != (Tstorage)FixedHelperT<T>::Raw(comparator, Tdec_bits); } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
196 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
197 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
198 |
* Greater or equal operator |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
199 |
* @param comparator The non-floating point variable we want to compare against |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
200 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
201 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
202 |
bool operator >=(const T &comparator) const { return Raw::m_data >= (Tstorage)FixedHelperT<T>::Raw(comparator, Tdec_bits); } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
203 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
204 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
205 |
* Less or equal operator |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
206 |
* @param comparator The non-floating point variable we want to compare against |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
207 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
208 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
209 |
bool operator <=(const T &comparator) const { return Raw::m_data <= (Tstorage)FixedHelperT<T>::Raw(comparator, Tdec_bits); } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
210 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
211 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
212 |
* Greater than operator |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
213 |
* @param comparator The non-floating point variable we want to compare against |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
214 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
215 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
216 |
bool operator >(const T &comparator) const { return Raw::m_data > (Tstorage)FixedHelperT<T>::Raw(comparator, Tdec_bits); } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
217 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
218 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
219 |
* Less than operator |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
220 |
* @param comparator The non-floating point variable we want to compare against |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
221 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
222 |
template <typename T> |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
223 |
bool operator <(const T &comparator) const { return Raw::m_data < (Tstorage)FixedHelperT<T>::Raw(comparator, Tdec_bits); } |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
224 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
225 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
226 |
* Addition for Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
227 |
* @param value The non-floating point number to add |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
228 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
229 |
template <typename T> FixedT operator +(const T &value) const |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
230 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
231 |
return Raw(Raw::m_data + (Tstorage)FixedHelperT<T>::Raw(value, Tdec_bits)); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
232 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
233 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
234 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
235 |
* Subtraction for Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
236 |
* @param value The non-floating point number to subtract |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
237 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
238 |
template <typename T> FixedT operator -(const T &value) const |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
239 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
240 |
return Raw(Raw::m_data - (Tstorage)FixedHelperT<T>::Raw(value, Tdec_bits)); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
241 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
242 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
243 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
244 |
* A simple multiplication for non-floating data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
245 |
* @param value The non floating-point factor |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
246 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
247 |
template <typename T> FixedT operator *(const T &value) const |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
248 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
249 |
return Raw( (((int64)Raw::m_data) * FixedHelperT<T>::Raw(value)) >> FixedHelperT<T>::dec_bits); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
250 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
251 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
252 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
253 |
* A simple division for non-floating data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
254 |
* @param value The non floating-point divisor |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
255 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
256 |
template <typename T> FixedT operator /(const T &value) const |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
257 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
258 |
return Raw( (((int64)Raw::m_data) << FixedHelperT<T>::dec_bits) / FixedHelperT<T>::Raw(value)); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
259 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
260 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
261 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
262 |
* Addition-assignment for Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
263 |
* @param value The non-floating point number to add |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
264 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
265 |
template <typename T> FixedT& operator +=(const T &value) |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
266 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
267 |
Raw::m_data = Raw::m_data + (Tstorage)FixedHelperT<T>::Raw(value, Tdec_bits); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
268 |
return *this; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
269 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
270 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
271 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
272 |
* Subtract-assignment for Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
273 |
* @param value The non-floating point number to subtract |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
274 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
275 |
template <typename T> FixedT& operator -=(const T &value) |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
276 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
277 |
Raw::m_data = Raw::m_data - (Tstorage)FixedHelperT<T>::Raw(value, Tdec_bits); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
278 |
return *this; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
279 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
280 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
281 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
282 |
* Multiply-assignment for Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
283 |
* @param value The non-floating point number to multiply |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
284 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
285 |
template <typename T> FixedT& operator *=(const T &value) |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
286 |
{ |
9882
059933c94c5d
(svn r9135) [gamebalance] -Fix(r9026): Buffer overflows in multiplications of FixedT
celestar
parents:
9880
diff
changeset
|
287 |
Raw::m_data = ((int64)Raw::m_data * (Tstorage)FixedHelperT<T>::Raw(value)) >> FixedHelperT<T>::dec_bits; |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
288 |
return *this; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
289 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
290 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
291 |
/** |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
292 |
* Divide-assignment for Fixed-point data types |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
293 |
* @param value The non-floating point number to use as divisor |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
294 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
295 |
template <typename T> FixedT& operator /=(const T &value) |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
296 |
{ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
297 |
Raw::m_data = (Raw::m_data << FixedHelperT<T>::dec_bits) / (Tstorage)FixedHelperT<T>::Raw(value); |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
298 |
return *this; |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
299 |
} |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
300 |
|
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
301 |
/** |
9877
29bb0e8924b7
(svn r9052) [gamebalance] -Add: Unary minus operator for FixedT
celestar
parents:
9876
diff
changeset
|
302 |
* Unary minus operator |
29bb0e8924b7
(svn r9052) [gamebalance] -Add: Unary minus operator for FixedT
celestar
parents:
9876
diff
changeset
|
303 |
*/ |
29bb0e8924b7
(svn r9052) [gamebalance] -Add: Unary minus operator for FixedT
celestar
parents:
9876
diff
changeset
|
304 |
FixedT operator -() const { return Raw(-Raw::m_data); } |
29bb0e8924b7
(svn r9052) [gamebalance] -Add: Unary minus operator for FixedT
celestar
parents:
9876
diff
changeset
|
305 |
|
29bb0e8924b7
(svn r9052) [gamebalance] -Add: Unary minus operator for FixedT
celestar
parents:
9876
diff
changeset
|
306 |
/** |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
307 |
* Stream operator, used for floating point output |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
308 |
* @param os The stream we are going to write to |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
309 |
* @param value The Fixed-point variable we want to write in the stream |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
310 |
*/ |
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
311 |
friend std::ostream& operator << (std::ostream &os, const FixedT &value) { os << (double)value.m_data / (1ULL << Raw::dec_bits); return os; } |
9887
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
312 |
}; |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
313 |
|
9887
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
314 |
/** The value of \f$\pi\f$ with ample precision for our computations */ |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
315 |
static const FixedT<int64, 16> PI(3141592, 1000000); |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
316 |
/** The number of elements used in Taylor approximations */ |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
317 |
static const int PRECISION = 5; |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
318 |
|
9880
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
319 |
/** |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
320 |
* Computes a integral, positive power of a FixedT. Uses an optimized algorithm |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
321 |
* to keep computational requirement at bay, by decomposing the power into powers |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
322 |
* of two itself. |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
323 |
* |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
324 |
* @param arg The number to compute the power for |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
325 |
* @param pow the power |
9887
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
326 |
* @return arg^pow |
9880
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
327 |
* @todo Add a nice LaTeX forumla to the documentation |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
328 |
* @todo Implement negative powers |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
329 |
*/ |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
330 |
template <typename Tstorage, int Tdec_bits> |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
331 |
FixedT<Tstorage, Tdec_bits> pow(const FixedT<Tstorage, Tdec_bits> &arg, int pow) |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
332 |
{ |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
333 |
FixedT<int64, Tdec_bits> temp = 1; |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
334 |
FixedT<int64, Tdec_bits> mul = arg; |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
335 |
if (pow == 0) return (FixedT<Tstorage, Tdec_bits>)1; |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
336 |
for (int i = 1; pow > 0; pow >>= 1, i <<= 1, mul *= mul) if (pow & 1) temp *= mul; |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
337 |
|
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
338 |
return temp; |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
339 |
} |
bd97cc28b569
(svn r9113) [gamebalance] -Add: Implemented a function that computes positive, integral powers of a FixedT
celestar
parents:
9879
diff
changeset
|
340 |
|
9887
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
341 |
/** |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
342 |
* Computes the n-th root of a number using an iterative scheme |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
343 |
* @param arg the number to compute the root from |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
344 |
* @param root The "n" in the n-th root |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
345 |
* @return the root |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
346 |
* @todo Abort not after a fixed number of iterations but dynamically by step size |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
347 |
* @todo Make some better first-guess. |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
348 |
*/ |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
349 |
template <typename Tstorage, int Tdec_bits> |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
350 |
FixedT<Tstorage, Tdec_bits> nroot(const FixedT<Tstorage, Tdec_bits> &arg, int root) |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
351 |
{ |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
352 |
FixedT<int64, 20> one = 1; |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
353 |
FixedT<int64, 20> guess(6, 5); |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
354 |
for (int i = 0; i < 150; i++) guess = (one / root) * ( guess * (root - 1) + arg / pow(guess, root - 1)); |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
355 |
|
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
356 |
return guess; |
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
357 |
} |
9876
f8302fbd236d
(svn r9026) [gamebalance] -Add: Added a new data type that allows fixed-point computations, as to enable computing non-integral numbers without worrying about the FPU rounding differences and, thus, desyncs. It is fully doxygenned, read the usage there. Thanks a bunch to KUDr for helping me with templates
celestar
parents:
diff
changeset
|
358 |
|
9878
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
359 |
/** |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
360 |
* Computes a single element of the Taylor series for the approximation of the cosine. |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
361 |
* A single element of the Taylor series computes as: |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
362 |
* \f[ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
363 |
* \frac{(-1)^nx^{2n}}{(2n)!} |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
364 |
* \f] |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
365 |
* In order to prevent overflows, underflows and other nasty stuff, we do not compute |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
366 |
* the numerator and denominator separately in the formula but build a product of |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
367 |
* fractions: |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
368 |
* \f[ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
369 |
* \frac{x}{2n} * \frac{x}{2n-1} * \frac{x}{2n-2} ... |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
370 |
* \f] |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
371 |
* @param arg The value of "x" in above formula |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
372 |
* @param pow The value of "2n" in above formula |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
373 |
* @return The value of the element of the Taylor series |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
374 |
*/ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
375 |
template <typename Tstorage, int Tdec_bits> |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
376 |
FixedT<Tstorage, Tdec_bits> trigbase(const FixedT<Tstorage, Tdec_bits> &arg, int pow) |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
377 |
{ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
378 |
/* Shortcut for the very first element */ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
379 |
if (pow == 0) return (FixedT<Tstorage, Tdec_bits>)1; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
380 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
381 |
/* find out the (-1)^n part, element should be negative if n is non-even |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
382 |
* but "pow" already holds 2n, account for that |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
383 |
*/ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
384 |
bool neg = ( (pow / 2) % 2 > 0); |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
385 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
386 |
FixedT<Tstorage, Tdec_bits> element = arg / pow; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
387 |
for (--pow; pow > 0; pow --) element *= arg / pow; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
388 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
389 |
return (neg) ? -element : element; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
390 |
} |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
391 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
392 |
/** |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
393 |
* Computes the cosine of an argument using a Taylor series. |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
394 |
* @param arg The number to compute the cosine from, assumes arg to be in radians. |
9887
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
395 |
* @return The cosine |
9878
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
396 |
* @todo Optimize the two while loops. |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
397 |
* @note It is possible to factor out the series to optimize even further, but is it |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
398 |
* worth the effort? It could reduce the opcount a little. |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
399 |
* @see trigbase, PRECISION |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
400 |
*/ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
401 |
template <typename Tstorage, int Tdec_bits> |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
402 |
FixedT<Tstorage, Tdec_bits> cos(const FixedT<Tstorage, Tdec_bits> &arg) |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
403 |
{ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
404 |
FixedT<Tstorage, Tdec_bits> l_arg = arg; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
405 |
FixedT<Tstorage, Tdec_bits> cosine = 0; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
406 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
407 |
/* We've got to adjust the argument around zero, otherwise we will need |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
408 |
* (literally) hundreds of elements |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
409 |
*/ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
410 |
while (l_arg < -PI) l_arg += PI * 2; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
411 |
while (l_arg > PI) l_arg -= PI * 2; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
412 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
413 |
/* sum up the Taylor elements */ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
414 |
for(int i = 0; i < PRECISION; i++) cosine += trigbase(l_arg, 2 * i); |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
415 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
416 |
return cosine; |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
417 |
} |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
418 |
|
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
419 |
/** |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
420 |
* Computes the sine of an argument using a Taylor series, uses the cosine |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
421 |
* computation in fact, as \f$sin(x) = cos(x - \frac{\pi}{2}))\f$ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
422 |
* @param arg The number to compute the cosine from, assumes arg to be in radians. |
9887
3d32aa4ae67c
(svn r9150) [gamebalance] -Add: a function to compute the n-th root of a FixedT.
celestar
parents:
9882
diff
changeset
|
423 |
* @return The sine |
9878
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
424 |
*/ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
425 |
template <typename Tstorage, int Tdec_bits> |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
426 |
FixedT<Tstorage, Tdec_bits> sin(const FixedT<Tstorage, Tdec_bits> &arg) |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
427 |
{ |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
428 |
return cos(arg - PI / 2); |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
429 |
} |
98be05df31ef
(svn r9060) [gamebalance] -Add: Added the two basic trigonometric functions (sine / cosine) for variables of types FixedT, so that we can compute periodic fluctuations.
celestar
parents:
9877
diff
changeset
|
430 |