GCC Code Coverage Report


Directory: ./
File: lib/my/my_str_nbr_long_long.c
Date: 2024-06-05 00:29:21
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 10 10 100.0%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_str_nbr_long_long
4 ** File description:
5 ** Returns the strings conversion of a long long number (nb)
6 */
7
8 #include "my.h"
9
10 186 static char *set_str_nb(long long int nb, int int_nb, int signe)
11 {
12 186 char *nb_str = malloc(sizeof(char) * (int_nb + signe + 1));
13 186 int j = 0;
14 186 long long int figure_temp = nb;
15
16
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 185 times.
186 if (signe == 1)
17 1 nb_str[int_nb] = '-';
18
2/2
✓ Branch 0 taken 736 times.
✓ Branch 1 taken 186 times.
922 for (j = 0; j < int_nb; j++) {
19 736 nb_str[j] = 48 + (figure_temp % 10);
20 736 figure_temp = (figure_temp - (figure_temp % 10)) / 10;
21 }
22 186 nb_str[j + signe] = '\0';
23 186 return my_revstr(nb_str);
24 }
25
26 187 char *my_str_nbr_long_long(long long int nb)
27 {
28 187 int int_nb = 1;
29 187 long long int temp_nb = nb;
30 187 int signe = 0;
31
32
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 186 times.
187 if (nb == -9223372036854775807)
33 1 return "-9223372036854775807";
34
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 185 times.
186 if (nb < 0) {
35 1 signe = 1;
36 1 nb = -nb;
37 }
38
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 186 times.
736 while ((temp_nb / 10) != 0) {
39 550 int_nb = int_nb + 1;
40 550 temp_nb = temp_nb / 10;
41 }
42 186 return set_str_nb(nb, int_nb, signe);
43 }
44