Mercurial > mm7
comparison Engine/OurMath.h @ 2499:68cdef6879a0
engine folder
author | Ritor1 |
---|---|
date | Fri, 19 Sep 2014 02:57:42 +0600 |
parents | |
children | 1bcadc6dd203 |
comparison
equal
deleted
inserted
replaced
2498:92eeeb5200f2 | 2499:68cdef6879a0 |
---|---|
1 #pragma once | |
2 | |
3 #include <cassert> | |
4 #include <limits> | |
5 | |
6 /* 186 */ | |
7 #pragma pack(push, 1) | |
8 struct stru193_math | |
9 { | |
10 stru193_math(); | |
11 int Cos(int angle); | |
12 unsigned int Atan2(int x, int y); | |
13 int Sin(int angle); | |
14 | |
15 int pTanTable[520]; | |
16 int pCosTable[520]; | |
17 int pInvCosTable[520]; | |
18 static const unsigned int uIntegerPi = 1024; | |
19 static const unsigned int uIntegerHalfPi = 512; | |
20 static const unsigned int uIntegerDoublePi = 2048; | |
21 static const unsigned int uDoublePiMask = 2047; | |
22 static const unsigned int uPiMask = 1023; | |
23 static const unsigned int uHalfPiMask = 511; | |
24 }; | |
25 #pragma pack(pop) | |
26 | |
27 __int64 fixpoint_mul(int, int); | |
28 __int64 fixpoint_dot(int x1, int x2, int y1, int y2, int z1, int z2); | |
29 __int64 fixpoint_div(int, int); | |
30 __int64 fixpoint_sub_unknown(int, int); | |
31 int fixpoint_from_float(float value); | |
32 int fixpoint_from_int(int lhv, int rhv); | |
33 int integer_sqrt(int val); | |
34 int __fastcall GetDiceResult(unsigned int uNumDice, unsigned int uDiceSides); // idb | |
35 inline int round_to_int(float x) { return (int)floor(x + 0.5f); } | |
36 | |
37 template <typename FloatType> | |
38 inline int bankersRounding(const FloatType& value) | |
39 { | |
40 assert("Method unsupported for this type" && false); | |
41 return value; | |
42 } | |
43 | |
44 template<> inline int bankersRounding<float>(const float& inValue) | |
45 { | |
46 union Cast | |
47 { | |
48 double d; | |
49 long l; | |
50 }; | |
51 volatile Cast c; | |
52 c.d = inValue + 6755399441055744.0; | |
53 return c.l; | |
54 } | |
55 | |
56 #pragma push_macro("max") | |
57 #undef max | |
58 template<> inline int bankersRounding<double>(const double& inValue) | |
59 { | |
60 double maxValue = std::numeric_limits<int>::max(); | |
61 assert(maxValue - 6755399441055744.0 >= inValue); | |
62 union Cast | |
63 { | |
64 double d; | |
65 long l; | |
66 }; | |
67 volatile Cast c; | |
68 c.d = inValue + 6755399441055744.0; | |
69 return c.l; | |
70 } | |
71 #pragma pop_macro("max") | |
72 | |
73 extern struct stru193_math *stru_5C6E00; |