changed stuff
This commit is contained in:
parent
74336f37a3
commit
8d76630152
7 changed files with 31 additions and 192 deletions
|
|
@ -1,61 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/06 14:14:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/11 15:37:28 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/char/char.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/convert/atoi.h"
|
||||
|
||||
t_i32 me_atoi(t_const_str str)
|
||||
{
|
||||
t_u64 out;
|
||||
t_u64 sign;
|
||||
t_usize i;
|
||||
|
||||
out = 0;
|
||||
i = 0;
|
||||
sign = 1;
|
||||
while (me_isspace(str[i]))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
if (str[i++] == '-')
|
||||
sign = -1;
|
||||
while (me_isdigit(str[i]))
|
||||
{
|
||||
out *= 10;
|
||||
out += str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return ((t_i32)(out * sign));
|
||||
}
|
||||
|
||||
t_i64 me_atoi_64(t_const_str str)
|
||||
{
|
||||
t_u64 out;
|
||||
t_u64 sign;
|
||||
t_usize i;
|
||||
|
||||
out = 0;
|
||||
i = 0;
|
||||
sign = 1;
|
||||
while (me_isspace(str[i]))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
if (str[i++] == '-')
|
||||
sign = -1;
|
||||
while (me_isdigit(str[i]))
|
||||
{
|
||||
out *= 10;
|
||||
out += str[i] - '0';
|
||||
i++;
|
||||
}
|
||||
return ((t_i64)(out * sign));
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/08/03 21:05:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2023/11/10 14:56:42 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "me/convert/itoa.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/str/str.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void me_itoa_inner(t_u64 nb, t_str out)
|
||||
{
|
||||
t_i32 modulus;
|
||||
bool need_print;
|
||||
char c;
|
||||
t_usize idx;
|
||||
|
||||
need_print = false;
|
||||
modulus = 1000000000;
|
||||
idx = 0;
|
||||
while (modulus)
|
||||
{
|
||||
c = (char)(nb / modulus) + '0';
|
||||
if (c != '0' || need_print)
|
||||
{
|
||||
out[idx++] = c;
|
||||
need_print = true;
|
||||
}
|
||||
nb = nb % modulus;
|
||||
modulus /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
t_str me_itoa(t_i32 nb)
|
||||
{
|
||||
char out[12];
|
||||
t_u64 n;
|
||||
|
||||
n = (t_u64)nb;
|
||||
mem_set(out, 0, 12);
|
||||
if (nb < 0)
|
||||
{
|
||||
out[0] = '-';
|
||||
me_itoa_inner(-n, out + 1);
|
||||
}
|
||||
else if (nb == 0)
|
||||
out[0] = '0';
|
||||
else
|
||||
me_itoa_inner(n, out);
|
||||
return (str_clone(out));
|
||||
}
|
||||
/*R
|
||||
int main(void)
|
||||
{
|
||||
me_putnbr(-2147483648);
|
||||
write(1, "\n", 1);
|
||||
me_putnbr(0);
|
||||
write(1, "\n", 1);
|
||||
me_putnbr(12345);
|
||||
return (0);
|
||||
}
|
||||
R*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue