mirror of
https://github.com/tailix/libkernaux.git
synced 2025-04-07 17:32:45 -04:00
Add consts "KERNAUX_UTOA10_BUFFER_SIZE" and "KERNAUX_UTOA16_BUFFER_SIZE"
This commit is contained in:
parent
5adcd97ae6
commit
7ecbdd7c54
4 changed files with 24 additions and 10 deletions
|
@ -5,6 +5,8 @@
|
|||
* include/kernaux/ntoa.h: Rename const "KERNAUX_ITOA_BUFFER_SIZE" to
|
||||
"KERNAUX_ITOA10_BUFFER_SIZE"
|
||||
* include/kernaux/ntoa.h: Add funcs "kernaux_utoa16" and "kernaux_itoa16"
|
||||
* include/kernaux/ntoa.h: Add consts "KERNAUX_UTOA10_BUFFER_SIZE" and
|
||||
"KERNAUX_UTOA16_BUFFER_SIZE"
|
||||
|
||||
2022-01-22 Alex Kotov <kotovalexarian@gmail.com>
|
||||
|
||||
|
|
|
@ -7,14 +7,18 @@ extern "C" {
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
// uint64_t: "18446744073709551615"
|
||||
// int64_t: "9223372036854775807"
|
||||
// int64_t: "-9223372036854775808"
|
||||
// "18446744073709551615"
|
||||
#define KERNAUX_UTOA10_BUFFER_SIZE 21
|
||||
|
||||
// "9223372036854775807"
|
||||
// "-9223372036854775808"
|
||||
#define KERNAUX_ITOA10_BUFFER_SIZE 21
|
||||
|
||||
// uint64_t: "ffffffffffffffff"
|
||||
// int64_t: "7fffffffffffffff"
|
||||
// int64_t: "-8000000000000000"
|
||||
// "ffffffffffffffff"
|
||||
#define KERNAUX_UTOA16_BUFFER_SIZE 17
|
||||
|
||||
// "7fffffffffffffff"
|
||||
// "-8000000000000000"
|
||||
#define KERNAUX_ITOA16_BUFFER_SIZE 18
|
||||
|
||||
void kernaux_utoa10(uint64_t value, char *buffer);
|
||||
|
|
|
@ -47,7 +47,7 @@ VALUE rb_KernAux_utoa10(
|
|||
if (rb_funcall(number_rb, rb_intern_LESS, 1, INT2FIX(0))) {
|
||||
rb_raise(rb_eRangeError, "can't convert negative number to uint64_t");
|
||||
}
|
||||
char buffer[KERNAUX_ITOA10_BUFFER_SIZE];
|
||||
char buffer[KERNAUX_UTOA10_BUFFER_SIZE];
|
||||
kernaux_utoa10(NUM2ULL(number_rb), buffer);
|
||||
return rb_funcall(rb_str_new2(buffer), rb_intern_freeze, 0);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ VALUE rb_KernAux_utoa16(
|
|||
if (rb_funcall(number_rb, rb_intern_LESS, 1, INT2FIX(0))) {
|
||||
rb_raise(rb_eRangeError, "can't convert negative number to uint64_t");
|
||||
}
|
||||
char buffer[KERNAUX_ITOA16_BUFFER_SIZE];
|
||||
char buffer[KERNAUX_UTOA16_BUFFER_SIZE];
|
||||
kernaux_utoa16(NUM2ULL(number_rb), buffer);
|
||||
return rb_funcall(rb_str_new2(buffer), rb_intern_freeze, 0);
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ static const struct {
|
|||
int main()
|
||||
{
|
||||
{
|
||||
char buffer[KERNAUX_ITOA10_BUFFER_SIZE];
|
||||
char buffer[KERNAUX_UTOA10_BUFFER_SIZE];
|
||||
|
||||
for (
|
||||
size_t index = 0;
|
||||
|
@ -257,6 +257,10 @@ int main()
|
|||
kernaux_utoa10(utoa10_cases[index].value, buffer);
|
||||
assert(strcmp(buffer, utoa10_cases[index].result) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char buffer[KERNAUX_ITOA10_BUFFER_SIZE];
|
||||
|
||||
for (
|
||||
size_t index = 0;
|
||||
|
@ -277,7 +281,7 @@ int main()
|
|||
}
|
||||
|
||||
{
|
||||
char buffer[KERNAUX_ITOA16_BUFFER_SIZE];
|
||||
char buffer[KERNAUX_UTOA16_BUFFER_SIZE];
|
||||
|
||||
for (
|
||||
size_t index = 0;
|
||||
|
@ -287,6 +291,10 @@ int main()
|
|||
kernaux_utoa16(utoa16_cases[index].value, buffer);
|
||||
assert(strcmp(buffer, utoa16_cases[index].result) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
char buffer[KERNAUX_ITOA16_BUFFER_SIZE];
|
||||
|
||||
for (
|
||||
size_t index = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue