-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.cpp
More file actions
64 lines (54 loc) 路 1.28 KB
/
Copy pathcustom.cpp
File metadata and controls
64 lines (54 loc) 路 1.28 KB
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
// Watermeloned on JJJakubJJ implementation found https://stackoverflow.com/questions/7228438/convert-double-double-to-string
#include <stdio.h>
int n_tu(int number, int count)
{
int result = 1;
while(count-- > 0)
result *= number;
return result;
}
void double_to_string(double f, char r[])
{
long long int length, length2, i, number, position, sign;
double number2;
sign = -1;
if (f < 0)
{
sign = '-';
f *= -1;
}
number2 = f;
number = f;
length = 0;
length2 = 0;
while( (number2 - static_cast<double>(number)) != 0.0 && !((number2 - static_cast<double>(number)) < 0.0) )
{
number2 = f * (n_tu(10.0, length2 + 1));
number = number2;
length2++;
}
for (length = (f > 1) ? 0 : 1; f > 1; length++)
f /= 10;
position = length;
length = length + 1 + length2;
number = number2;
if (sign == '-')
{
length++;
position++;
}
for (i = length; i >= 0 ; i--)
{
if (i == (length))
r[i] = '\0';
else if(i == (position))
r[i] = '.';
else if(sign == '-' && i == 0)
r[i] = '-';
else
{
r[i] = (number % 10) + '0';
number /=10;
}
}
}