Normed this shit
This commit is contained in:
parent
5bc68504f9
commit
61ef75f212
26 changed files with 286 additions and 318 deletions
|
|
@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix}, \
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_i16 result;
|
||||
|
||||
result = 0;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_i32 result;
|
||||
|
||||
result = 0;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_i64 result;
|
||||
|
||||
result = 0ll;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_i8 result;
|
||||
|
||||
result = 0;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_u16 result;
|
||||
|
||||
result = 0u;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_u32 result;
|
||||
|
||||
result = 0u;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_u64 result;
|
||||
|
||||
result = 0llu;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ 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)
|
||||
{
|
||||
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)
|
||||
|
|
@ -86,7 +86,6 @@ static inline t_error loop_inner(t_const_str s, t_u32 radix, t_u8 op,
|
|||
t_u8 result;
|
||||
|
||||
result = 0u;
|
||||
|
||||
while (*s)
|
||||
{
|
||||
if (do_operation(radix, (op & OP_CHK) | OP_MUL, &result))
|
||||
|
|
|
|||
|
|
@ -10,12 +10,11 @@
|
|||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
#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)
|
||||
{
|
||||
|
|
@ -27,7 +26,8 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@
|
|||
|
||||
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;
|
||||
|
|
@ -29,10 +28,8 @@ 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}, \
|
||||
return (_format_u64((t_num_str){.value = value.u64,
|
||||
.is_nonnegative = is_nonnegative, .base = base, .prefix = prefix},
|
||||
out));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue