Subversion Repositories spk

Rev

Rev 114 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 114 Rev 273
Line 2... Line 2...
2
#define CONVERSION_INCLUDED
2
#define CONVERSION_INCLUDED
3
 
3
 
-
 
4
#include <cmath>
4
/*
5
/*
5
 
6
 
6
	conversion from:
7
	conversion from:
7
		int to double 
8
		int to double 
8
		int (modulo 100000) to int (modulo 0xFFFF)
9
		int (modulo 100000) to int (modulo 0xFFFF)
Line 10... Line 11...
10
 
11
 
11
*/
12
*/
12
 
13
 
13
namespace conversion
14
namespace conversion
14
{
15
{
-
 
16
#ifdef _WIN64
-
 
17
 
-
 
18
	static inline double __fastcall divideAndRound(double value) {
-
 
19
		const double MULTIPLIER = 1.52587890625E-05; // == 1 / 65535
-
 
20
 
-
 
21
		value /= MULTIPLIER;
-
 
22
		return std::round(value);
-
 
23
	}
-
 
24
 
-
 
25
	static inline int __stdcall double2int(double d)
-
 
26
	{
-
 
27
		return static_cast<int>(divideAndRound(d));
-
 
28
	}
-
 
29
 
-
 
30
	static int __stdcall vertex_bob2bod(int i)
-
 
31
	{
-
 
32
		// bod = i / 0.65535
-
 
33
		static double MULTIPLIER = 0.65536; // == 65535 / 100000
-
 
34
		return static_cast<int>(i / MULTIPLIER + 0.5f);
-
 
35
	}
-
 
36
 
-
 
37
	static inline int __stdcall vertex_bod2bob(int i)
-
 
38
	{
-
 
39
		// bob = i * 0.65535
-
 
40
		static double MULTIPLIER = 0.65536; // == 65535 / 100000
-
 
41
 
-
 
42
		double result = MULTIPLIER * i;
-
 
43
		return static_cast<int>(std::round(result));
-
 
44
	}
-
 
45
 
-
 
46
#else
15
 
47
 
16
__declspec(naked)
48
__declspec(naked)
17
static 
49
static 
18
int __stdcall vertex_bob2bod(int i)
50
int __stdcall vertex_bob2bod(int i)
19
{
51
{
Line 73... Line 105...
73
	static const double MULTIPLIER=1.52587890625E-05; // == 1 / 65535
105
	static const double MULTIPLIER=1.52587890625E-05; // == 1 / 65535
74
	
106
	
75
	return (int)(d / MULTIPLIER);
107
	return (int)(d / MULTIPLIER);
76
	
108
	
77
}*/
109
}*/
-
 
110
#endif
78
 
111
 
79
} // namespace conversion
112
} // namespace conversion
80
 
113
 
81
#endif // !defined(CONVERSION_INCLUDED)
114
#endif // !defined(CONVERSION_INCLUDED)