GCC Code Coverage Report


Directory: ./
File: lib/my/my_round_float_str.c
Date: 2024-06-05 00:36:48
Exec Total Coverage
Lines: 26 26 100.0%
Functions: 2 2 100.0%
Branches: 21 22 95.5%

Line Branch Exec Source
1 /*
2 ** EPITECH PROJECT, 2023
3 ** my_printf
4 ** File description:
5 ** Modify a string (float) and round it
6 */
7 /**
8 * @file my_round_float_str.c
9 * @brief The file containing the my_round_float_str function
10 * @author Nicolas TORO
11 */
12
13 #include "my.h"
14
15 3 static void add_number(char *float_nb)
16 {
17 3 char *temp_float_str = malloc(sizeof(char) * my_strlen(float_nb + 1));
18
19 3 temp_float_str[0] = '1';
20 3 my_strcat(temp_float_str, float_nb);
21 3 my_strcpy(float_nb, temp_float_str);
22
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if (float_nb[1] == '-') {
23 1 float_nb[1] = float_nb[0];
24 1 float_nb[0] = '-';
25 }
26 3 FREE(temp_float_str);
27 3 }
28
29 82 void my_round_float_str(char *float_nb, char last_char, int i, int enable)
30 {
31
4/4
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 79 times.
82 if (float_nb[i] == '\0' || float_nb[i] == '-')
32 3 add_number(float_nb);
33
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 78 times.
82 if (float_nb[i] == '.') {
34
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (float_nb[i - 1] == '9')
35 2 float_nb[i - 1] = '0';
36 else
37 2 float_nb[i - 1] = float_nb[i - 1] + 1;
38
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (float_nb[i - 1] == '0')
39 2 my_round_float_str(float_nb, float_nb[i - 1], i - 2, 0);
40 4 return;
41 }
42
5/6
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 25 times.
✓ Branch 5 taken 41 times.
78 if (float_nb[i] != '.' && (last_char > '4' || enable == 1)) {
43
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 13 times.
37 if (float_nb[i] == '9')
44 24 float_nb[i] = '0';
45 else
46 13 float_nb[i] = float_nb[i] + 1;
47
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 13 times.
37 if (float_nb[i] == '0')
48 24 my_round_float_str(float_nb, float_nb[i], i - 1, 1);
49 }
50 }
51