Mercurial > mm7
annotate Math.h @ 1530:dec48a151390
Слияние
author | Ritor1 |
---|---|
date | Fri, 06 Sep 2013 16:42:32 +0600 |
parents | f0551cd4cbc9 |
children | 499761153844 |
rev | line source |
---|---|
0 | 1 #pragma once |
1527 | 2 |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
3 #include <cassert> |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
4 #include <limits> |
0 | 5 |
6 /* 186 */ | |
7 #pragma pack(push, 1) | |
8 struct stru193_math | |
9 { | |
10 stru193_math(); | |
323 | 11 int Cos(int angle); |
0 | 12 unsigned int Atan2(int x, int y); |
323 | 13 int Sin(int angle); |
0 | 14 |
15 int pTanTable[520]; | |
16 int pCosTable[520]; | |
17 int pInvCosTable[520]; | |
1214
0d6c7ff3cddd
simplified stru193_math constructor and class definition
Grumpy7
parents:
1131
diff
changeset
|
18 static const unsigned int uIntegerPi = 1024; |
0d6c7ff3cddd
simplified stru193_math constructor and class definition
Grumpy7
parents:
1131
diff
changeset
|
19 static const unsigned int uIntegerHalfPi = 512; |
0d6c7ff3cddd
simplified stru193_math constructor and class definition
Grumpy7
parents:
1131
diff
changeset
|
20 static const unsigned int uIntegerDoublePi = 2048; |
0d6c7ff3cddd
simplified stru193_math constructor and class definition
Grumpy7
parents:
1131
diff
changeset
|
21 static const unsigned int uDoublePiMask = 2047; |
0d6c7ff3cddd
simplified stru193_math constructor and class definition
Grumpy7
parents:
1131
diff
changeset
|
22 static const unsigned int uPiMask = 1023; |
0d6c7ff3cddd
simplified stru193_math constructor and class definition
Grumpy7
parents:
1131
diff
changeset
|
23 static const unsigned int uHalfPiMask = 511; |
0 | 24 }; |
25 #pragma pack(pop) | |
26 | |
1051 | 27 int fixpoint_sub0(int, int); |
28 int fixpoint_div(int, int); | |
29 int fixpoint_mul(int, int); | |
30 int fixpoint_from_float(float value); | |
31 | |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
32 template <typename FloatType> |
1527 | 33 inline int bankersRounding( |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
34 const FloatType& value |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
35 ) { |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
36 assert("Method unsupported for this type" && false); |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
37 return value; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
38 } |
1130 | 39 |
1527 | 40 template<> inline int bankersRounding<float>(const float& inValue) |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
41 { |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
42 union Cast |
1130 | 43 { |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
44 double d; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
45 long l; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
46 }; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
47 volatile Cast c; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
48 c.d = inValue + 6755399441055744.0; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
49 return c.l; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
50 } |
1130 | 51 |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
52 #pragma push_macro("max") |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
53 #undef max |
1527 | 54 template<> inline int bankersRounding<double>(const double& inValue) |
1131
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
55 { |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
56 double maxValue = std::numeric_limits<int>::max(); |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
57 assert(maxValue - 6755399441055744.0 >= inValue); |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
58 union Cast |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
59 { |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
60 double d; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
61 long l; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
62 }; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
63 volatile Cast c; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
64 c.d = inValue + 6755399441055744.0; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
65 return c.l; |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
66 } |
71ba92960bc5
banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents:
1130
diff
changeset
|
67 #pragma pop_macro("max") |
1130 | 68 |
1527 | 69 extern struct stru193_math *stru_5C6E00; |