3#ifndef TETL_STRINGS_TO_FLOATING_POINT_HPP
4#define TETL_STRINGS_TO_FLOATING_POINT_HPP
19template <
typename Float>
21 char const*
end{
nullptr};
26template <
typename Float>
31 auto afterDecimalPoint =
false;
32 auto leadingSpaces =
true;
34 auto const* ptr = str.data();
35 for (; *ptr !=
'\0'; ++ptr) {
39 leadingSpaces =
false;
42 if (!afterDecimalPoint) {
47 res +=
static_cast<Float
>(*ptr -
'0') /
div;
49 }
else if (*ptr ==
'.') {
50 afterDecimalPoint =
true;
56 return {.end = ptr, .error = {}, .value = res};
constexpr auto isdigit(int ch) noexcept -> int
Checks if the given character is one of the 10 decimal digits: 0123456789.
Definition isdigit.hpp:15
constexpr auto isspace(int ch) noexcept -> int
Checks if the given character is whitespace character as classified by the default C locale.
Definition isspace.hpp:19
basic_string_view< char, etl::char_traits< char > > string_view
Typedef for common character type char
Definition basic_string_view.hpp:704
constexpr auto to_floating_point(etl::string_view str) noexcept -> to_floating_point_result< Float >
Definition to_floating_point.hpp:27
@ overflow
Definition from_floating_point.hpp:20
@ none
Definition from_floating_point.hpp:19
to_floating_point_error
Definition to_floating_point.hpp:13
@ invalid_input
Definition to_floating_point.hpp:15
@ none
Definition to_floating_point.hpp:14
constexpr auto div(int x, int y) noexcept -> div_t
Computes both the quotient and the remainder of the division of the numerator x by the denominator y....
Definition div.hpp:37
Definition to_floating_point.hpp:20
to_floating_point_error error
Definition to_floating_point.hpp:22
char const * end
Definition to_floating_point.hpp:21
Float value
Definition to_floating_point.hpp:23