-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_maths.h
114 lines (94 loc) · 1.85 KB
/
base_maths.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef BASIC_MATHS_HEADER_INCLUDED
#define BASIC_MATHS_HEADER_INCLUDED
#include <limits>
#include <cmath>
namespace Geometry
{
inline float Sqrt( float f )
{
return sqrtf( f );
}
inline double Sqrt( double f )
{
return sqrt( f );
}
inline float Fabs( float f )
{
return fabsf( f );
}
inline double Fabs( double f )
{
return fabs( f );
}
// http://www.codecodex.com/wiki/index.php?title=Calculate_an_integer_square_root
inline int Sqrt( int x )
{
unsigned long op, res, one;
op = x;
res = 0;
one = 1 << 30;
while (one > op) one >>= 2;
while (one != 0) {
if (op >= res + one) {
op = op - (res + one);
res = res + 2 * one;
}
res >>= 1;
one >>= 2;
}
return int(res);
}
inline float Sin( float f )
{
return sinf(f);
}
inline float Cos( float f )
{
return cosf(f);
}
inline double Sin( double d )
{
return sin(d);
}
inline double Cos( double d )
{
return cos(d);
}
inline int Abs( int i )
{
return abs(i);
}
inline float Abs( float f )
{
return fabs(f);
}
inline double Abs( double d )
{
return fabs(d);
}
inline double Pow( double b, double e )
{
return pow(b,e);
}
inline float Pow( float b, float e )
{
return pow(b,e);
}
inline int iPow( int b, int e )
{
int result = 1;
while (e)
{
if (e & 1)
result *= b;
e >>= 1;
b *= b;
}
return result;
}
inline int Pow( int b, int e )
{
return iPow(b,e);
}
}
#endif //BASIC_MATHS_HEADER_INCLUDED