-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath.hpp
58 lines (49 loc) · 1.06 KB
/
math.hpp
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
static char buf[100];
struct Math
{
static LPSTR PrintInt(int i)
{
}
static float ParseFloat(LPSTR str)
{
return 0.0f;
}
static LPSTR PrintFloat(float f)
{
SecureZeroMemory(buf, 100);
int trunc = (int) f;
int digits = Digits(trunc);
char *ptr = buf+digits;
if (f < 0)
{
*buf = '-';
ptr++;
f = -f;
}
for (int i=0; i<digits; i++)
{
*(--ptr) = '0' + (trunc%10);
trunc /= 10;
}
ptr += digits;
float rest = f - (int)f;
if (rest != 0.0) {
*ptr++ = ',';
for (int i=0; i<2; i++) {
rest *= 10.0;
*ptr++ = '0' + (((int)rest)%10);
rest -= (int) rest;
}
}
return buf;
}
static int Digits(int x)
{
int cnt = 0;
while (x > 0) {
x /= 10;
cnt++;
}
return cnt;
}
};