-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibft_f.c
64 lines (58 loc) · 1.66 KB
/
libft_f.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft_f.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: snara <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/20 08:23:41 by snara #+# #+# */
/* Updated: 2021/01/21 03:52:43 by snara ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_flen(long double n, int b, int l)
{
int i;
i = 0;
if (b < 2)
return (0);
while (1 <= ABS(n))
{
n /= b;
i++;
}
return (i + l);
}
char *ft_ftoa(long double n, t_fmt *f, const char *base)
{
const t_ld c = n;
int i;
int b;
b = 0;
i = F_INT + 1;
while (base[b])
b++;
f->a[i + 1] = '\0';
f->a[i] = '.';
while (0 < i--)
{
f->a[i] = base[(t_um)ABS(n) % b];
n /= b;
}
n = c;
i = F_INT + 1;
while (i++ < F_INT + F_FRAC)
{
n = ABS(n - (t_um)(n));
f->a[i] = base[(t_um)ABS(n * b) % b];
n = ABS(n * b - (t_um)(n * b));
f->a[i + 1] = '\0';
}
return (f->a);
}
/*
**int main(void){static t_fmt f;
**f.u = 0x0000000000000001;f.f = *(double*)&(f.u);
**ft_printf("%i: %s", ft_flen(f.f, 10, 0), ft_ftoa(f.f, &f, "01"));
**return (0);}
*/