3#ifndef TETL_STRINGS_FROM_FLOATING_POINT_HPP
4#define TETL_STRINGS_FROM_FLOATING_POINT_HPP
28template <
floating_point Float, from_floating_point_options Options = from_floating_point_options{}>
31 using int_type =
conditional_t<(
sizeof(Float) > 4),
long long,
long>;
33 constexpr auto toString = [](int_type x,
char* str,
int numDigits) ->
int {
36 str[i++] = (x % 10) +
'0';
42 while (i < numDigits) {
51 auto* res = out.data();
53 auto const whole =
static_cast<int_type
>(val);
54 auto const frac = val -
static_cast<Float
>(whole);
55 auto const pos = toString(whole, res, 0);
64 auto part =
static_cast<int_type
>(frac *
static_cast<Float
>(
etl::ipow<10>(precision)));
66 toString(part, res + pos + 1, precision);
68 return {.end = res + pos};
The concept floating_point<T> is satisfied if and only if T is a floating-point type.
Definition floating_point.hpp:13
constexpr auto reverse(BidirIt first, BidirIt last) -> void
Reverses the order of the elements in the range [first, last).
Definition reverse.hpp:16
constexpr auto from_floating_point(Float val, span< char > out, int precision) -> from_floating_point_result
Definition from_floating_point.hpp:29
from_floating_point_error
Definition from_floating_point.hpp:18
@ overflow
Definition from_floating_point.hpp:20
@ none
Definition from_floating_point.hpp:19
typename conditional< B, T, F >::type conditional_t
Definition conditional.hpp:21
constexpr auto ipow(Int base, Int exponent) noexcept -> Int
Definition ipow.hpp:11
A non-owning view over a contiguous sequence of objects.
Definition span.hpp:83
Definition from_floating_point.hpp:14
bool terminate_with_null
Definition from_floating_point.hpp:15
Definition from_floating_point.hpp:23
char * end
Definition from_floating_point.hpp:24
from_floating_point_error error
Definition from_floating_point.hpp:25