annotate Math.h @ 1163:3d96daa7e069

Merge
author Grumpy7
date Tue, 04 Jun 2013 01:41:12 +0200
parents 71ba92960bc5
children 0d6c7ff3cddd
rev   line source
0
Ritor1
parents:
diff changeset
1 #pragma once
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
2 #include <cassert>
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
3 #include <limits>
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
4 #include <float.h>
0
Ritor1
parents:
diff changeset
5
Ritor1
parents:
diff changeset
6
Ritor1
parents:
diff changeset
7 /* 186 */
Ritor1
parents:
diff changeset
8 #pragma pack(push, 1)
Ritor1
parents:
diff changeset
9 struct stru193_math
Ritor1
parents:
diff changeset
10 {
Ritor1
parents:
diff changeset
11 stru193_math();
323
d720a13e2273 Very basic picking & entering houses
Nomad
parents: 0
diff changeset
12 int Cos(int angle);
0
Ritor1
parents:
diff changeset
13 unsigned int Atan2(int x, int y);
323
d720a13e2273 Very basic picking & entering houses
Nomad
parents: 0
diff changeset
14 int Sin(int angle);
0
Ritor1
parents:
diff changeset
15
Ritor1
parents:
diff changeset
16 int pTanTable[520];
Ritor1
parents:
diff changeset
17 int pCosTable[520];
Ritor1
parents:
diff changeset
18 int pInvCosTable[520];
Ritor1
parents:
diff changeset
19 unsigned int uIntegerPi;
Ritor1
parents:
diff changeset
20 unsigned int uIntegerHalfPi;
Ritor1
parents:
diff changeset
21 unsigned int uIntegerDoublePi;
Ritor1
parents:
diff changeset
22 unsigned int uDoublePiMask;
Ritor1
parents:
diff changeset
23 unsigned int uPiMask;
Ritor1
parents:
diff changeset
24 unsigned int uHalfPiMask;
Ritor1
parents:
diff changeset
25 };
Ritor1
parents:
diff changeset
26 #pragma pack(pop)
Ritor1
parents:
diff changeset
27
Ritor1
parents:
diff changeset
28
1051
05c62d166182 004C1D2B cleaned
Nomad
parents: 323
diff changeset
29 int fixpoint_sub0(int, int);
05c62d166182 004C1D2B cleaned
Nomad
parents: 323
diff changeset
30 int fixpoint_div(int, int);
05c62d166182 004C1D2B cleaned
Nomad
parents: 323
diff changeset
31 int fixpoint_mul(int, int);
05c62d166182 004C1D2B cleaned
Nomad
parents: 323
diff changeset
32 int fixpoint_from_float(float value);
05c62d166182 004C1D2B cleaned
Nomad
parents: 323
diff changeset
33
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
34 #ifndef ROUNDING_EPSILON
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
35 #define ROUNDING_EPSILON 0.0000001
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
36 #endif
0
Ritor1
parents:
diff changeset
37
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
38 #include <cmath>
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
39 #include <cstdlib>
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
40 #include <ciso646>
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
41
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
42 template <typename FloatType>
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
43 int bankersRounding(
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
44 const FloatType& value
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
45 ) {
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
46 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
47 return value;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
48 }
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
49
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
50 template<> static int bankersRounding<float>(const float& inValue)
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
51 {
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
52 union Cast
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
53 {
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
54 double d;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
55 long l;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
56 };
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
57 volatile Cast c;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
58 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
59 return c.l;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
60 }
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
61
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
62 #pragma push_macro("max")
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
63 #undef max
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
64
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
65 template<> static int bankersRounding<double>(const double& inValue)
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 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
68 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
69 union Cast
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
70 {
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
71 double d;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
72 long l;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
73 };
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
74 volatile Cast c;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
75 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
76 return c.l;
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
77 }
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
78
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
79
1131
71ba92960bc5 banker's rounding template made as fast as before and a bit more safe
Grumpy7
parents: 1130
diff changeset
80 #pragma pop_macro("max")
1130
d98415be04ca banker's rounding template
Grumpy7
parents: 1051
diff changeset
81
0
Ritor1
parents:
diff changeset
82 extern struct stru193_math *stru_5C6E00;