-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.cpp
114 lines (84 loc) · 2.16 KB
/
common.cpp
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
#include "common.h"
void appendString(char* output, char* input)
{
int i = 0;
for (i = 0 ; ; i++) { if (output[i] == '\0') break; }
for (int j = 0 ; input[j] != '\0' ; j++)
{
output[i++] = input[j];
}
output[i] = '\0';
return;
}
void printFloat(float f)
{
if (f < 0)
{
DEBUG_NOLN('-');
f = -f;
}
if (f > 1) { DEBUG_NOLN(int(f)); }
else { DEBUG_NOLN('0'); }
DEBUG_NOLN('.');
f = f - int(f); int a = int(f * 10); DEBUG_NOLN(a);
f = f - a * 0.1; int b = int(f * 100); DEBUG_NOLN(b);
f = f - b * 0.01; int c = int(f * 1000); DEBUG_NOLN(c);
f = f - c * 0.001; int d = int(f * 10000); DEBUG_NOLN(d);
}
void printFloatInString(char* output, float f)
{
int index = 0;
if (f < 0)
{
output[index++] = '-';
f = -f;
}
if (f > 1) output[index++] = (int(f)+48);
else output[index++] = '0';
output[index++] = '.';
f -= int(f); int a = int(f * 10); output[index++] = a+48;
f -= a * 0.1; int b = int(f * 100); output[index++] = b+48;
f -= b * 0.01; int c = int(f * 1000); output[index++] = c+48;
f -= c * 0.001; int d = int(f * 10000); output[index++] = d+48;
output[index] = '\0';
return;
}
/* Find out what's going on here
void printIntInString(char* output, int i)
{
int index = 0;
if (i < 0)
{
output[index++] = '-';
i = -i;
}
if (i >= 10)
{
output[index++] = (int(i/10)+48);
i = (int) (i / 10);
}
output[index++] = (int(i)+48);
output[index] = '\0';
return;
}
*/
void printHourInString(char* output, int h, int m, char separator)
{
int index = 0;
if (h >= 10) output[index++] = int(h/10)+48;
else output[index++] = '0';
if (h > 1) output[index++] = int(h - (h/10)*10)+48;
else output[index++] = '0';
output[index++] = separator;
if (m >= 10) output[index++] = int(m/10)+48;
else output[index++] = '0';
if (m > 1) output[index++] = int(m - (m/10)*10)+48;
else output[index++] = '0';
output[index] = '\0';
return;
}
void printFloatln(float f)
{
printFloat(f);
DEBUG_NOLN('\n');
}