fast_div_proto #1

Merged
marco merged 3 commits from fast_div_proto into master 2026-02-26 09:56:51 +01:00
3 changed files with 27 additions and 32 deletions
Showing only changes of commit eb670e26a5 - Show all commits

View File

@@ -23,7 +23,6 @@
#include "bigint.h" #include "bigint.h"
#include "vector.h" #include "vector.h"
// Internal methods
/** /**
* bigint_trim_zeros * bigint_trim_zeros
* @number: a non-null big integer * @number: a non-null big integer
@@ -1673,8 +1672,6 @@ bigint_result_t bigint_prod(const bigint_t *x, const bigint_t *y) {
return result; return result;
} }
/** /**
* bigint_divmod * bigint_divmod
* @x: a valid non-null big integer * @x: a valid non-null big integer
@@ -1886,11 +1883,15 @@ bigint_result_t bigint_printf(const char *format, ...) {
// Process string char by char // Process string char by char
for (const char *p = format; *p != '\0'; p++) { for (const char *p = format; *p != '\0'; p++) {
if (*p == '%' && *(p + 1) == 'B') { if (*p == '%' && *(p + 1) != '%') {
// Process a big number p++;
const char placeholder = *p;
switch (placeholder) {
case 'B': {
bigint_t *num = va_arg(args, bigint_t*); bigint_t *num = va_arg(args, bigint_t*);
if (num == NULL) { if (num == NULL) {
printf("<invalid string>"); for (const char *s = "<invalid big integer>"; *s != '\0'; s++) { putchar(*s); }
} else { } else {
bigint_result_t num_str_res = bigint_to_string(num); bigint_result_t num_str_res = bigint_to_string(num);
if (num_str_res.status != BIGINT_OK) { if (num_str_res.status != BIGINT_OK) {
@@ -1898,28 +1899,21 @@ bigint_result_t bigint_printf(const char *format, ...) {
return num_str_res; return num_str_res;
} }
char* const number_str = num_str_res.value.string_num; char *number_str = num_str_res.value.string_num;
printf("%s", number_str); for (const char *s = number_str; *s != '\0'; s++) { putchar(*s); }
free(number_str); free(number_str);
} }
p++; break;
} else if (*p == '%' && *(p + 1) != '%') { }
// Handle common printf placeholders
p++;
char placeholder = *p;
switch (placeholder) {
case 'd': case 'd':
case 'i': { case 'i': {
int val = va_arg(args, int); int val = va_arg(args, int);
printf("%d", val); printf("%d", val);
break; break;
} }
case 'u': { case 'u': {
unsigned int val = va_arg(args, unsigned int); unsigned int val = va_arg(args, unsigned int);
printf("%u", val); printf("%u", val);
break; break;
} }
case 'l': { case 'l': {
@@ -1939,13 +1933,17 @@ bigint_result_t bigint_printf(const char *format, ...) {
break; break;
} }
case 's': { case 's': {
char *val = va_arg(args, char*); char* val = va_arg(args, char*);
printf("%s", val ? val : "<invalid string>"); if (val) {
for (const char *s = val; *s != '\0'; s++) { putchar(*s); }
} else {
for (const char *s = "<invalid string>"; *s != '\0'; s++) { putchar(*s); }
}
break; break;
} }
case 'c': { case 'c': {
int val = va_arg(args, int); int val = va_arg(args, int);
printf("%c", val); putchar(val);
break; break;
} }
case 'f': { case 'f': {
@@ -1954,7 +1952,7 @@ bigint_result_t bigint_printf(const char *format, ...) {
break; break;
} }
case 'p': { case 'p': {
void *val = va_arg(args, void*); void* const val = va_arg(args, void*);
printf("%p", val); printf("%p", val);
break; break;
} }

View File

@@ -10,8 +10,6 @@
#include "map.h" #include "map.h"
// Internal methods
/** /**
* hash_key * hash_key
* @key: The input string for the hash function * @key: The input string for the hash function

View File

@@ -9,7 +9,6 @@
#include "vector.h" #include "vector.h"
// Internal methods
/** /**
* vector_resize * vector_resize
* @vector: a non-null vector * @vector: a non-null vector