tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
strtod.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_CSTDLIB_STRTOD_HPP
5#define TETL_CSTDLIB_STRTOD_HPP
6
7#include <etl/_strings/to_floating_point.hpp>
8
9namespace etl {
10
11/// \brief Interprets a floating point value in a byte string pointed to by str.
12/// \param str Pointer to the null-terminated byte string to be interpreted.
13/// \param last Pointer to a pointer to character.
14/// \returns Floating point value corresponding to the contents of str on
15/// success. If the converted value falls out of range of corresponding return
16/// type, range error occurs and HUGE_VAL, HUGE_VALF or HUGE_VALL is returned.
17/// If no conversion can be performed, `0` is returned and *last is set to str.
18[[nodiscard]] constexpr auto strtod(char const* str, char const** last = nullptr) noexcept -> double
19{
20 auto result = strings::to_floating_point<double>(str);
21 if (last != nullptr) {
22 *last = result.end;
23 }
24 return result.value;
25}
26
27} // namespace etl
28
29#endif // TETL_CSTDLIB_STRTOD_HPP
Definition find.hpp:9
constexpr auto to_floating_point(etl::string_view str) noexcept -> to_floating_point_result< Float >
Definition to_floating_point.hpp:28
Definition adjacent_find.hpp:9
constexpr auto strtod(char const *str, char const **last=nullptr) noexcept -> double
Interprets a floating point value in a byte string pointed to by str.
Definition strtod.hpp:18