-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_print_g.c
59 lines (54 loc) · 1.7 KB
/
ft_printf_print_g.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_printf_print_g.c :+: :+: */
/* +:+ */
/* By: avan-ber <avan-ber@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/01/04 12:35:54 by avan-ber #+# #+# */
/* Updated: 2020/01/06 11:21:50 by avan-ber ######## odam.nl */
/* */
/* ************************************************************************** */
#include "printf.h"
int print_g_get_power(double nb)
{
int power;
power = 0;
while (nb < 1 && nb > -1)
{
power--;
nb *= 10;
}
while (nb >= 10 || nb <= -10)
{
power++;
nb /= 10;
}
return (power);
}
int print_g(t_flags flags, double nb, int cap)
{
int check;
int power;
int removezero;
setprecisionfloat(&flags);
if (flags.hash == 1)
removezero = 0;
else
removezero = 1;
if (nb == 0)
return (print_float(flags, nb, cap, removezero));
if (flags.prenumber == 0)
flags.prenumber = 1;
check = float_check_edge(nb, cap, flags);
if (check > 0)
return (check);
power = print_g_get_power(nb);
if (power < -4 || power >= flags.prenumber)
{
flags.prenumber--;
return (print_e(flags, nb, cap, removezero));
}
flags.prenumber -= power + 1;
return (print_float(flags, nb, cap, removezero));
}