Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2024 | ||
3 | ** my_strict_getnbr_float | ||
4 | ** File description: | ||
5 | ** Returns a float number starting from a string number (str) and -1.0 if the | ||
6 | ** string is not an exact positive number | ||
7 | */ | ||
8 | /** | ||
9 | * @file my_strict_getnbr_float.c | ||
10 | * @brief The file containing the my_strict_getnbr_float function | ||
11 | * @author Nicolas TORO | ||
12 | */ | ||
13 | |||
14 | #include "my.h" | ||
15 | |||
16 | 12 | float my_strict_getnbr_float(char const *str) | |
17 | { | ||
18 | 12 | float convert = 0; | |
19 | 12 | int index = 0; | |
20 | 12 | float index_float = 0.1; | |
21 | |||
22 |
4/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 5 times.
|
12 | if (str[0] < '0' || str[0] > '9') |
23 | 7 | return -1; | |
24 |
3/4✓ Branch 0 taken 19 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
24 | for (; str[index] >= '0' && str[index] <= '9'; index++) |
25 | 19 | convert = convert * 10 + (str[index] - 48); | |
26 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
|
5 | if (str[index] == '.') { |
27 | 3 | index++; | |
28 |
4/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
|
6 | for (; str[index] >= '0' && str[index] <= '9'; index++) { |
29 | 3 | convert = convert + index_float * (str[index] - 48); | |
30 | 3 | index_float = index_float * 0.1; | |
31 | } | ||
32 | } | ||
33 | 5 | return convert; | |
34 | } | ||
35 |