4#ifndef TETL_STRINGS_FROM_FLOATING_POINT_HPP
5#define TETL_STRINGS_FROM_FLOATING_POINT_HPP
7#include <etl/_algorithm/reverse.hpp>
8#include <etl/_concepts/floating_point.hpp>
9#include <etl/_math/ipow.hpp>
10#include <etl/_span/span.hpp>
11#include <etl/_type_traits/conditional.hpp>
32 using int_type = conditional_t<(
sizeof(Float) > 4),
long long,
long>;
34 constexpr auto toString = [](int_type x,
char* str,
int numDigits) ->
int {
37 str[i++] =
static_cast<
char>((x % 10) + int_type(
'0'));
43 while (i < numDigits) {
54 auto const whole =
static_cast<int_type>(val);
55 auto const frac = val -
static_cast<Float>(whole);
56 auto const pos = toString(whole, res, 0);
65 auto part =
static_cast<int_type>(frac *
static_cast<Float>(
etl::ipow<10
>(precision
)));
67 toString(part, res + pos + 1, precision);
69 return {.end = res + pos};
constexpr auto reverse(BidirIt first, BidirIt last) -> void
Reverses the order of the elements in the range [first, last).
Definition reverse.hpp:17
constexpr auto from_floating_point(Float val, span< char > out, int precision) -> from_floating_point_result
Definition from_floating_point.hpp:30
from_floating_point_error
Definition from_floating_point.hpp:19
Definition adjacent_find.hpp:9
constexpr auto ipow(decltype(Base) exponent) noexcept -> decltype(Base)
Definition ipow.hpp:22
constexpr auto data() const noexcept -> pointer
Returns a pointer to the beginning of the sequence.
Definition span.hpp:225
Definition from_floating_point.hpp:15
bool terminate_with_null
Definition from_floating_point.hpp:16
Definition from_floating_point.hpp:24
char * end
Definition from_floating_point.hpp:25
from_floating_point_error error
Definition from_floating_point.hpp:26