GCC Code Coverage Report


Directory: ./
File: lib/my/my_str_nbr_long_long.c
Date: 2024-06-05 00:34:38
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 string conversion of a long long number (nb)
6 */
7 /**
8 * @file my_str_nbr_long_long.c
9 * @brief The file containing the my_str_nbr_long_long function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 200 static char *set_str_nb(long long int nb, int int_nb, int signe)
16 {
17 200 char *nb_str = malloc(sizeof(char) * (int_nb + signe + 1));
18 200 int j = 0;
19 200 long long int figure_temp = nb;
20
21
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 199 times.
200 if (signe == 1)
22 1 nb_str[int_nb] = '-';
23
2/2
✓ Branch 0 taken 762 times.
✓ Branch 1 taken 200 times.
962 for (j = 0; j < int_nb; j++) {
24 762 nb_str[j] = 48 + (figure_temp % 10);
25 762 figure_temp = (figure_temp - (figure_temp % 10)) / 10;
26 }
27 200 nb_str[j + signe] = '\0';
28 200 return my_revstr(nb_str);
29 }
30
31 201 char *my_str_nbr_long_long(long long int nb)
32 {
33 201 int int_nb = 1;
34 201 long long int temp_nb = nb;
35 201 int signe = 0;
36
37
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 200 times.
201 if (nb == -9223372036854775807)
38 1 return "-9223372036854775807";
39
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 199 times.
200 if (nb < 0) {
40 1 signe = 1;
41 1 nb = -nb;
42 }
43
2/2
✓ Branch 0 taken 562 times.
✓ Branch 1 taken 200 times.
762 while ((temp_nb / 10) != 0) {
44 562 int_nb = int_nb + 1;
45 562 temp_nb = temp_nb / 10;
46 }
47 200 return set_str_nb(nb, int_nb, signe);
48 }
49