-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathops_func4.c
131 lines (119 loc) · 2.64 KB
/
ops_func4.c
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ops_func4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jinpark <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 19:57:01 by jinpark #+# #+# */
/* Updated: 2019/04/26 16:21:58 by jinpark ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char g_d[] = "0123456789abcdef";
static char g_bd[] = "0123456789ABCDEF";
char *itoa_base(uint32_t di, int base)
{
int len;
char *new;
len = get_len_base(di, base);
new = (char *)malloc(sizeof(char) * len + 1);
if (di == 0)
{
new[0] = '0';
new[1] = '\0';
return (new);
}
if (new == 0)
return (NULL);
new[len] = '\0';
while (di)
{
new[--len] = g_d[di % base];
di /= base;
}
return (new);
}
char *big_itoa_base(unsigned int di, int base)
{
int len;
char *new;
len = get_len_base(di, base);
new = (char *)malloc(sizeof(char) * len + 1);
if (di == 0)
{
new[0] = '0';
new[1] = '\0';
return (new);
}
if (new == 0)
return (NULL);
new[len] = '\0';
while (di)
{
new[--len] = g_bd[di % base];
di /= base;
}
return (new);
}
char *p_itoa_base(uint64_t di, int base)
{
int len;
char *new;
len = get_len_base(di, base);
new = (char *)malloc(sizeof(char) * len);
if (new == 0)
return (NULL);
new[len - 1] = '\0';
while (di)
{
new[--len] = g_d[di % base];
di /= base;
}
return (new);
}
int f_op_get_prec(char *str, int i)
{
int n;
int prec;
char *temp;
prec = 0;
n = i + 1;
temp = (char *)malloc(sizeof(char) * (ft_strlen(str)));
if (str[n] == '-')
n++;
while (str[n] != '.' && (str[n] >= '0' && str[n] <= '9'))
n++;
n++;
while (str[n] >= '0' && str[n] <= '9')
temp[prec++] = str[n++];
temp[prec] = '\0';
prec = ft_atoi(temp);
free(temp);
return (prec);
}
char *ld_long_itoa(int64_t di)
{
int len;
char *new;
len = f_get_len(di);
new = (char *)malloc(sizeof(char) * (len + 1));
if (di == 0)
{
new[0] = '0';
new[1] = '\0';
return (new);
}
new[len] = '\0';
if (di < 0)
{
new[0] = '-';
di *= -1;
}
while (di)
{
new[--len] = (di % 10) + '0';
di /= 10;
}
return (new);
}