52 template<std::
unsigned_
integral U>
54 constexpr auto kdigits(
const std::span<char> buffer, U value,
const radix_t radix,
const bool upper =
false) noexcept -> std::string_view {
57 constexpr auto LOWER {std::string_view {
"0123456789abcdef"}};
58 constexpr auto UPPER {std::string_view {
"0123456789ABCDEF"}};
59 const auto digits {upper ? UPPER : LOWER};
62 auto pos {buffer.end()};
67 const auto mask {
static_cast<U
>(
static_cast<U
>(radix) - 1U)};
70 value =
static_cast<U
>(value >> shift);
71 }
while (0U != value);
72 return std::string_view {pos, buffer.end()};
78 constexpr auto CHUNK {
static_cast<U
>(1000000000U)};
79 constexpr auto CHUNK_DIGITS {9};
80 while (value > std::numeric_limits<igros_usize_t>::max()) {
81 const auto res {
kdivmod(value, CHUNK)};
83 for (
auto i {0}; i < CHUNK_DIGITS; ++i) {
84 *--pos = digits[chunk % 10U];
93 auto rest {
static_cast<N
>(value)};
96 rest =
static_cast<N
>(rest / 10U);
98 return std::string_view {pos, buffer.end()};
108 [[gnu::format(printf, 3, 0)]]
117 [[gnu::format(printf, 3, 4)]]
123 [[gnu::format(printf, 1, 2)]]
124 void kprintf(const
char* const format, ...) noexcept;
std::size_t igros_usize_t
Unsigned size.
std::uint8_t igros_byte_t
8-bit unsigned integer
std::uint32_t igros_dword_t
32-bit unsigned integer
Kernel math functions definitions.
Freestanding kernel library: printing, math, alignment, flags, strings.
auto ksnprintf(char *const buffer, const igros_usize_t size, const char *const format,...) noexcept -> igros_usize_t
Kernel snprintf function (returns written length without terminator).
void kprintf(const char *const format,...) noexcept
Kernel printf function (arguments are checked against format at compile time).
auto kvsnprintf(char *const buffer, const igros_usize_t size, const char *const format, std::va_list list) noexcept -> igros_usize_t
Kernel vsnprintf function (returns written length without terminator).
radix_t
Integer representation types.
@ BIN
(Base 2) Binary integer format
@ DEC
(Base 10) Decimal integer format
@ OCT
(Base 8) Oct integer format
@ HEX
(Base 16) Hexidemical integer format
constexpr auto kdivmod(const T dividend, const D divisor) noexcept -> divmod_t< T >
Divide integer by integer of the same signedness.
constexpr auto kdigits(const std::span< char > buffer, U value, const radix_t radix, const bool upper=false) noexcept -> std::string_view
Digits of unsigned value written to the end of buffer (no sign, no terminator).
Common C++ types redefinition.