Normed this shit

This commit is contained in:
Raphael (rparodi) 2024-07-30 16:35:56 +02:00
parent 5bc68504f9
commit 61ef75f212
26 changed files with 286 additions and 318 deletions

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_i64.c :+: :+: :+: */
/* i16_to_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */
/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */
/* Updated: 2024/07/30 16:32:22 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error i16_to_str_base_prefix(t_i16 val, t_str base, t_str prefix,
t_str *out)
t_error i16_to_str_base_prefix(t_i16 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error i16_to_str_base_prefix(t_i16 val, t_str base, t_str prefix,
is_nonnegative = val & 0x8000;
if (is_nonnegative)
value.u16 = ~value.u16 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
out));
}
t_error i16_to_str_base(t_i16 val, t_str base, t_str *out)
t_error i16_to_str_base(t_i16 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (i16_to_str_base_prefix(val, base, "", out));
}
t_error i16_to_str(t_i16 val, t_str *out)
t_error i16_to_str(t_i16 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_i64.c :+: :+: :+: */
/* i32_to_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */
/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */
/* Updated: 2024/07/30 16:31:39 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error i32_to_str_base_prefix(t_i32 val, t_str base, t_str prefix,
t_str *out)
t_error i32_to_str_base_prefix(t_i32 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error i32_to_str_base_prefix(t_i32 val, t_str base, t_str prefix,
is_nonnegative = val & 0x80000000;
if (is_nonnegative)
value.u32 = ~value.u32 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
out));
}
t_error i32_to_str_base(t_i32 val, t_str base, t_str *out)
t_error i32_to_str_base(t_i32 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (i32_to_str_base_prefix(val, base, "", out));
}
t_error i32_to_str(t_i32 val, t_str *out)
t_error i32_to_str(t_i32 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_i64.c :+: :+: :+: */
/* i64_to_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */
/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */
/* Updated: 2024/07/30 16:31:50 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error i64_to_str_base_prefix(t_i64 val, t_str base, t_str prefix,
t_str *out)
t_error i64_to_str_base_prefix(t_i64 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error i64_to_str_base_prefix(t_i64 val, t_str base, t_str prefix,
is_nonnegative = val & 0x8000000000000000;
if (is_nonnegative)
value.u64 = ~value.u64 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
out));
}
t_error i64_to_str_base(t_i64 val, t_str base, t_str *out)
t_error i64_to_str_base(t_i64 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (i64_to_str_base_prefix(val, base, "", out));
}
t_error i64_to_str(t_i64 val, t_str *out)
t_error i64_to_str(t_i64 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* str_to_i64.c :+: :+: :+: */
/* i8_to_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 21:15:19 by maiboyer #+# #+# */
/* Updated: 2024/02/01 23:18:52 by maiboyer ### ########.fr */
/* Updated: 2024/07/30 16:32:12 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error i8_to_str_base_prefix(t_i8 val, t_str base, t_str prefix,
t_str *out)
t_error i8_to_str_base_prefix(t_i8 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error i8_to_str_base_prefix(t_i8 val, t_str base, t_str prefix,
is_nonnegative = val & 0x80;
if (is_nonnegative)
value.u8 = ~value.u8 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
out));
}
t_error i8_to_str_base(t_i8 val, t_str base, t_str *out)
t_error i8_to_str_base(t_i8 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (i8_to_str_base_prefix(val, base, "", out));
}
t_error i8_to_str(t_i8 val, t_str *out)
t_error i8_to_str(t_i8 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_i16(t_i16 lhs, t_i16 rhs, t_i16 *out);
t_error checked_sub_i16(t_i16 lhs, t_i16 rhs, t_i16 *out);
t_error checked_mul_i16(t_i16 lhs, t_i16 rhs, t_i16 *out);
t_error checked_add_i16(t_i16 lhs, t_i16 rhs, t_i16 *out);
t_error checked_sub_i16(t_i16 lhs, t_i16 rhs, t_i16 *out);
t_error checked_mul_i16(t_i16 lhs, t_i16 rhs, t_i16 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_i16) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_i16) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_i16 digit, t_u8 op, t_i16 *result)
static inline t_error do_operation(t_i16 digit, t_u8 op, t_i16 *result)
{
t_i16 rhs;
t_i16 res;
t_i16 rhs;
t_i16 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_i16 digit, t_u8 op, t_i16 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i16 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i16 *out)
{
t_u32 digit;
t_i16 result;
t_u32 digit;
t_i16 result;
result = 0;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_i16(t_const_str s, t_u32 radix, t_i16 *out)
t_error str_to_i16(t_const_str s, t_u32 radix, t_i16 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
t_error checked_add_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
{
if (rhs > 0 && (lhs > 32767 - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
return (NO_ERROR);
}
t_error checked_sub_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
t_error checked_sub_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
{
if ((((rhs & (1 << (sizeof(t_i16) - 1)) || rhs == 0) || !true) && (lhs < -32768 + rhs)))
if ((((rhs & (1 << (sizeof(t_i16) - 1)) || rhs == 0) || !true) && (lhs <
-32768 + rhs)))
return (ERROR);
*out = (t_i16)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
t_error checked_mul_i16(t_i16 lhs, t_i16 rhs, t_i16 *out)
{
t_i16 mul;
t_i16 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_i32(t_i32 lhs, t_i32 rhs, t_i32 *out);
t_error checked_sub_i32(t_i32 lhs, t_i32 rhs, t_i32 *out);
t_error checked_mul_i32(t_i32 lhs, t_i32 rhs, t_i32 *out);
t_error checked_add_i32(t_i32 lhs, t_i32 rhs, t_i32 *out);
t_error checked_sub_i32(t_i32 lhs, t_i32 rhs, t_i32 *out);
t_error checked_mul_i32(t_i32 lhs, t_i32 rhs, t_i32 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_i32) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_i32) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_i32 digit, t_u8 op, t_i32 *result)
static inline t_error do_operation(t_i32 digit, t_u8 op, t_i32 *result)
{
t_i32 rhs;
t_i32 res;
t_i32 rhs;
t_i32 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_i32 digit, t_u8 op, t_i32 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i32 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i32 *out)
{
t_u32 digit;
t_i32 result;
t_u32 digit;
t_i32 result;
result = 0;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_i32(t_const_str s, t_u32 radix, t_i32 *out)
t_error str_to_i32(t_const_str s, t_u32 radix, t_i32 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
t_error checked_add_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
{
if (rhs > 0 && (lhs > 2147483647 - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
return (NO_ERROR);
}
t_error checked_sub_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
t_error checked_sub_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
{
if ((((rhs & (1 << (sizeof(t_i32) - 1)) || rhs == 0) || !true) && (lhs < -2147483648 + rhs)))
if ((((rhs & (1 << (sizeof(t_i32) - 1)) || rhs == 0) || !true) && (lhs <
-2147483648 + rhs)))
return (ERROR);
*out = (t_i32)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
t_error checked_mul_i32(t_i32 lhs, t_i32 rhs, t_i32 *out)
{
t_i32 mul;
t_i32 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_i64(t_i64 lhs, t_i64 rhs, t_i64 *out);
t_error checked_sub_i64(t_i64 lhs, t_i64 rhs, t_i64 *out);
t_error checked_mul_i64(t_i64 lhs, t_i64 rhs, t_i64 *out);
t_error checked_add_i64(t_i64 lhs, t_i64 rhs, t_i64 *out);
t_error checked_sub_i64(t_i64 lhs, t_i64 rhs, t_i64 *out);
t_error checked_mul_i64(t_i64 lhs, t_i64 rhs, t_i64 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_i64) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_i64) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_i64 digit, t_u8 op, t_i64 *result)
static inline t_error do_operation(t_i64 digit, t_u8 op, t_i64 *result)
{
t_i64 rhs;
t_i64 res;
t_i64 rhs;
t_i64 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_i64 digit, t_u8 op, t_i64 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i64 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i64 *out)
{
t_u32 digit;
t_i64 result;
t_u32 digit;
t_i64 result;
result = 0ll;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_i64(t_const_str s, t_u32 radix, t_i64 *out)
t_error str_to_i64(t_const_str s, t_u32 radix, t_i64 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
t_error checked_add_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
{
if (rhs > 0 && (lhs > 9223372036854775807ll - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
return (NO_ERROR);
}
t_error checked_sub_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
t_error checked_sub_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
{
if ((((rhs & (1 << (sizeof(t_i64) - 1)) || rhs == 0) || !true) && (lhs < -(~9223372036854775807ll + 1) + rhs)))
if ((((rhs & (1 << (sizeof(t_i64) - 1)) || rhs == 0) || !true) && (lhs <
-(~9223372036854775807ll + 1) + rhs)))
return (ERROR);
*out = (t_i64)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
t_error checked_mul_i64(t_i64 lhs, t_i64 rhs, t_i64 *out)
{
t_i64 mul;
t_i64 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_i8(t_i8 lhs, t_i8 rhs, t_i8 *out);
t_error checked_sub_i8(t_i8 lhs, t_i8 rhs, t_i8 *out);
t_error checked_mul_i8(t_i8 lhs, t_i8 rhs, t_i8 *out);
t_error checked_add_i8(t_i8 lhs, t_i8 rhs, t_i8 *out);
t_error checked_sub_i8(t_i8 lhs, t_i8 rhs, t_i8 *out);
t_error checked_mul_i8(t_i8 lhs, t_i8 rhs, t_i8 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_i8) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_i8) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_i8 digit, t_u8 op, t_i8 *result)
static inline t_error do_operation(t_i8 digit, t_u8 op, t_i8 *result)
{
t_i8 rhs;
t_i8 res;
t_i8 rhs;
t_i8 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_i8 digit, t_u8 op, t_i8 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i8 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_i8 *out)
{
t_u32 digit;
t_i8 result;
t_u32 digit;
t_i8 result;
result = 0;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_i8(t_const_str s, t_u32 radix, t_i8 *out)
t_error str_to_i8(t_const_str s, t_u32 radix, t_i8 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
t_error checked_add_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
{
if (rhs > 0 && (lhs > 127 - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
return (NO_ERROR);
}
t_error checked_sub_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
t_error checked_sub_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
{
if ((((rhs & (1 << (sizeof(t_i8) - 1)) || rhs == 0) || !true) && (lhs < -128 + rhs)))
if ((((rhs & (1 << (sizeof(t_i8) - 1)) || rhs == 0) || !true) && (lhs < -128
+ rhs)))
return (ERROR);
*out = (t_i8)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
t_error checked_mul_i8(t_i8 lhs, t_i8 rhs, t_i8 *out)
{
t_i8 mul;
t_i8 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_u16(t_u16 lhs, t_u16 rhs, t_u16 *out);
t_error checked_sub_u16(t_u16 lhs, t_u16 rhs, t_u16 *out);
t_error checked_mul_u16(t_u16 lhs, t_u16 rhs, t_u16 *out);
t_error checked_add_u16(t_u16 lhs, t_u16 rhs, t_u16 *out);
t_error checked_sub_u16(t_u16 lhs, t_u16 rhs, t_u16 *out);
t_error checked_mul_u16(t_u16 lhs, t_u16 rhs, t_u16 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_u16) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_u16) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_u16 digit, t_u8 op, t_u16 *result)
static inline t_error do_operation(t_u16 digit, t_u8 op, t_u16 *result)
{
t_u16 rhs;
t_u16 res;
t_u16 rhs;
t_u16 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_u16 digit, t_u8 op, t_u16 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u16 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u16 *out)
{
t_u32 digit;
t_u16 result;
t_u32 digit;
t_u16 result;
result = 0u;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_u16(t_const_str s, t_u32 radix, t_u16 *out)
t_error str_to_u16(t_const_str s, t_u32 radix, t_u16 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
t_error checked_add_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
{
if (rhs > 0 && (lhs > 65535u - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
return (NO_ERROR);
}
t_error checked_sub_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
t_error checked_sub_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
{
if ((((rhs & (1 << (sizeof(t_u16) - 1)) || rhs == 0) || !false) && (lhs < 0u + rhs)))
if ((((rhs & (1 << (sizeof(t_u16) - 1)) || rhs == 0) || !false) && (lhs < 0u
+ rhs)))
return (ERROR);
*out = (t_u16)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
t_error checked_mul_u16(t_u16 lhs, t_u16 rhs, t_u16 *out)
{
t_u16 mul;
t_u16 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_u32(t_u32 lhs, t_u32 rhs, t_u32 *out);
t_error checked_sub_u32(t_u32 lhs, t_u32 rhs, t_u32 *out);
t_error checked_mul_u32(t_u32 lhs, t_u32 rhs, t_u32 *out);
t_error checked_add_u32(t_u32 lhs, t_u32 rhs, t_u32 *out);
t_error checked_sub_u32(t_u32 lhs, t_u32 rhs, t_u32 *out);
t_error checked_mul_u32(t_u32 lhs, t_u32 rhs, t_u32 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_u32) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_u32) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_u32 digit, t_u8 op, t_u32 *result)
static inline t_error do_operation(t_u32 digit, t_u8 op, t_u32 *result)
{
t_u32 rhs;
t_u32 res;
t_u32 rhs;
t_u32 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_u32 digit, t_u8 op, t_u32 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u32 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u32 *out)
{
t_u32 digit;
t_u32 result;
t_u32 digit;
t_u32 result;
result = 0u;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_u32(t_const_str s, t_u32 radix, t_u32 *out)
t_error str_to_u32(t_const_str s, t_u32 radix, t_u32 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
t_error checked_add_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
{
if (rhs > 0 && (lhs > 4294967295u - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
return (NO_ERROR);
}
t_error checked_sub_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
t_error checked_sub_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
{
if ((((rhs & (1 << (sizeof(t_u32) - 1)) || rhs == 0) || !false) && (lhs < 0u + rhs)))
if ((((rhs & (1 << (sizeof(t_u32) - 1)) || rhs == 0) || !false) && (lhs < 0u
+ rhs)))
return (ERROR);
*out = (t_u32)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
t_error checked_mul_u32(t_u32 lhs, t_u32 rhs, t_u32 *out)
{
t_u32 mul;
t_u32 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_u64(t_u64 lhs, t_u64 rhs, t_u64 *out);
t_error checked_sub_u64(t_u64 lhs, t_u64 rhs, t_u64 *out);
t_error checked_mul_u64(t_u64 lhs, t_u64 rhs, t_u64 *out);
t_error checked_add_u64(t_u64 lhs, t_u64 rhs, t_u64 *out);
t_error checked_sub_u64(t_u64 lhs, t_u64 rhs, t_u64 *out);
t_error checked_mul_u64(t_u64 lhs, t_u64 rhs, t_u64 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_u64) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_u64) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_u64 digit, t_u8 op, t_u64 *result)
static inline t_error do_operation(t_u64 digit, t_u8 op, t_u64 *result)
{
t_u64 rhs;
t_u64 res;
t_u64 rhs;
t_u64 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_u64 digit, t_u8 op, t_u64 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u64 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u64 *out)
{
t_u32 digit;
t_u64 result;
t_u32 digit;
t_u64 result;
result = 0llu;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_u64(t_const_str s, t_u32 radix, t_u64 *out)
t_error str_to_u64(t_const_str s, t_u32 radix, t_u64 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
t_error checked_add_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
{
if (rhs > 0 && (lhs > 18446744073709551615llu - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
return (NO_ERROR);
}
t_error checked_sub_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
t_error checked_sub_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
{
if ((((rhs & (1 << (sizeof(t_u64) - 1)) || rhs == 0) || !false) && (lhs < 0llu + rhs)))
if ((((rhs & (1 << (sizeof(t_u64) - 1)) || rhs == 0) || !false)
&& (lhs < 0llu + rhs)))
return (ERROR);
*out = (t_u64)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
t_error checked_mul_u64(t_u64 lhs, t_u64 rhs, t_u64 *out)
{
t_u64 mul;
t_u64 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -20,20 +20,20 @@
#define OP_MUL 0b0100
#define OP_CHK 0b1000
t_error checked_add_u8(t_u8 lhs, t_u8 rhs, t_u8 *out);
t_error checked_sub_u8(t_u8 lhs, t_u8 rhs, t_u8 *out);
t_error checked_mul_u8(t_u8 lhs, t_u8 rhs, t_u8 *out);
t_error checked_add_u8(t_u8 lhs, t_u8 rhs, t_u8 *out);
t_error checked_sub_u8(t_u8 lhs, t_u8 rhs, t_u8 *out);
t_error checked_mul_u8(t_u8 lhs, t_u8 rhs, t_u8 *out);
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
static inline bool can_not_overflow(t_u32 radix, bool is_signed_type,
t_usize digits_len)
{
return (radix <= 16 &&
digits_len <= sizeof(t_u8) * 2 - (t_usize)is_signed_type);
return (radix <= 16 && digits_len <= sizeof(t_u8) * 2
- (t_usize)is_signed_type);
}
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
{
t_u32 digit;
t_u32 digit;
if (radix < 2 || radix > 36)
return (ERROR);
@ -50,10 +50,10 @@ static inline t_error to_digit(t_u8 ascii, t_u32 radix, t_u32 *out)
return (NO_ERROR);
}
static inline t_error do_operation(t_u8 digit, t_u8 op, t_u8 *result)
static inline t_error do_operation(t_u8 digit, t_u8 op, t_u8 *result)
{
t_u8 rhs;
t_u8 res;
t_u8 rhs;
t_u8 res;
rhs = *result;
res = *result;
@ -79,14 +79,13 @@ static inline t_error do_operation(t_u8 digit, t_u8 op, t_u8 *result)
return (NO_ERROR);
}
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u8 *out)
static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
t_u8 *out)
{
t_u32 digit;
t_u8 result;
t_u32 digit;
t_u8 result;
result = 0u;
while (*s)
{
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
@ -102,9 +101,9 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
return (NO_ERROR);
}
t_error str_to_u8(t_const_str s, t_u32 radix, t_u8 *out)
t_error str_to_u8(t_const_str s, t_u32 radix, t_u8 *out)
{
t_usize digits_len;
t_usize digits_len;
bool is_positive;
t_u8 op;

View file

@ -10,14 +10,13 @@
/* */
/* ************************************************************************** */
#include "me/char/char.h"
#include "me/convert/str_to_numbers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include "me/printf/printf.h"
t_error checked_add_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
t_error checked_add_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
{
if (rhs > 0 && (lhs > 128u - rhs))
return (ERROR);
@ -25,17 +24,18 @@ t_error checked_add_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
return (NO_ERROR);
}
t_error checked_sub_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
t_error checked_sub_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
{
if ((((rhs & (1 << (sizeof(t_u8) - 1)) || rhs == 0) || !false) && (lhs < 0u + rhs)))
if ((((rhs & (1 << (sizeof(t_u8) - 1)) || rhs == 0) || !false) && (lhs < 0u
+ rhs)))
return (ERROR);
*out = (t_u8)(lhs - rhs);
return (NO_ERROR);
}
t_error checked_mul_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
t_error checked_mul_u8(t_u8 lhs, t_u8 rhs, t_u8 *out)
{
t_u8 mul;
t_u8 mul;
mul = lhs * rhs;
if (lhs != 0 && mul / lhs != rhs)

View file

@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error u16_to_str_base_prefix(t_u16 val, t_str base, t_str prefix,
t_str *out)
t_error u16_to_str_base_prefix(t_u16 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error u16_to_str_base_prefix(t_u16 val, t_str base, t_str prefix,
is_nonnegative = val & 0x0000;
if (is_nonnegative)
value.u16 = ~value.u16 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
out));
}
t_error u16_to_str_base(t_u16 val, t_str base, t_str *out)
t_error u16_to_str_base(t_u16 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (u16_to_str_base_prefix(val, base, "", out));
}
t_error u16_to_str(t_u16 val, t_str *out)
t_error u16_to_str(t_u16 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error u32_to_str_base_prefix(t_u32 val, t_str base, t_str prefix,
t_str *out)
t_error u32_to_str_base_prefix(t_u32 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error u32_to_str_base_prefix(t_u32 val, t_str base, t_str prefix,
is_nonnegative = val & 0x00000000;
if (is_nonnegative)
value.u32 = ~value.u32 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
out));
}
t_error u32_to_str_base(t_u32 val, t_str base, t_str *out)
t_error u32_to_str_base(t_u32 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (u32_to_str_base_prefix(val, base, "", out));
}
t_error u32_to_str(t_u32 val, t_str *out)
t_error u32_to_str(t_u32 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error u64_to_str_base_prefix(t_u64 val, t_str base, t_str prefix,
t_str *out)
t_error u64_to_str_base_prefix(t_u64 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error u64_to_str_base_prefix(t_u64 val, t_str base, t_str prefix,
is_nonnegative = val & 0x0000000000000000;
if (is_nonnegative)
value.u64 = ~value.u64 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
out));
}
t_error u64_to_str_base(t_u64 val, t_str base, t_str *out)
t_error u64_to_str_base(t_u64 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (u64_to_str_base_prefix(val, base, "", out));
}
t_error u64_to_str(t_u64 val, t_str *out)
t_error u64_to_str(t_u64 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -15,13 +15,12 @@
#include "me/str/str.h"
#include "me/types.h"
t_error _format_u64(t_num_str args, t_str *out);
t_error _format_u64(t_num_str args, t_str *out);
t_error u8_to_str_base_prefix(t_u8 val, t_str base, t_str prefix,
t_str *out)
t_error u8_to_str_base_prefix(t_u8 val, t_str base, t_str prefix, t_str *out)
{
union u_nums value;
bool is_nonnegative;
union u_nums value;
bool is_nonnegative;
if (out == NULL || base == NULL || prefix == NULL)
return (ERROR);
@ -29,21 +28,19 @@ t_error u8_to_str_base_prefix(t_u8 val, t_str base, t_str prefix,
is_nonnegative = val & 0x00;
if (is_nonnegative)
value.u8 = ~value.u8 + 1;
return (_format_u64((t_num_str){.value = value.u64, \
.is_nonnegative = is_nonnegative, \
.base = base, \
.prefix = prefix}, \
out));
return (_format_u64((t_num_str){.value = value.u64,
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
out));
}
t_error u8_to_str_base(t_u8 val, t_str base, t_str *out)
t_error u8_to_str_base(t_u8 val, t_str base, t_str *out)
{
if (out == NULL || base == NULL)
return (ERROR);
return (u8_to_str_base_prefix(val, base, "", out));
}
t_error u8_to_str(t_u8 val, t_str *out)
t_error u8_to_str(t_u8 val, t_str *out)
{
if (out == NULL)
return (ERROR);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 19:06:05 by maiboyer #+# #+# */
/* Updated: 2024/07/30 16:26:28 by maiboyer ### ########.fr */
/* Updated: 2024/07/30 16:35:28 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,7 +17,7 @@
#include <stdlib.h>
/// This has to be added into the me/fs/fs.h header at one point
t_error read_to_vec(t_const_str filename, t_vec_u8 *out);
t_error read_to_vec(t_const_str filename, t_vec_u8 *out);
t_i32 qoi_write(t_const_str filename, const void *data,
const t_qoi_desc *desc)

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
/* Updated: 2024/07/30 16:20:50 by maiboyer ### ########.fr */
/* Updated: 2024/07/30 16:34:34 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -87,9 +87,9 @@ void me_abort(t_str msg)
{
if (msg == NULL)
msg = "No message provided";
put_string_fd(get_stderr(),"Abort: ");
put_string_fd(get_stderr(),msg);
put_char_fd(get_stderr(),'\n');
put_string_fd(get_stderr(), "Abort: ");
put_string_fd(get_stderr(), msg);
put_char_fd(get_stderr(), '\n');
print_trace();
me_exit(134);
}