Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
savalet committed Oct 27, 2024
1 parent f829eef commit 1fa3840
Showing 1 changed file with 7 additions and 41 deletions.
48 changes: 7 additions & 41 deletions src/handler/put_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,25 @@
** display an int in hexadecimal format
*/

#include <stdio.h>

#include "my.h"

void printf_put_float(flags_t *flags)
{
x += baby_put_nbr(entier);
baby_putchar('.');
x++;
for (int i = 0; i < precision; i++)
if (decimal[i] != 0)
x += baby_put_nbr(decimal[i]);
}

int printf_put_float_sav(flags_t *flags)
{
int x = 0;
float nb = va_arg(flags->args, double);
int entier = (int)nb;
int precision = flags->precision;
int decimal[precision];
int b = 10;
int tt;

for (int i = 0; i < precision; i++) {
tt = (int)(nb * b);
decimal[i] = tt % 10;
b = b * 10;
}
if (nb < 0) {
baby_putchar('-');
nb = nb * -1;
entier = nb;
}
printf_put_float2(decimal, x, precision, entier);
return (0);
}

int printf_put_float(flags_t *flags)
{
double nbr = va_arg(flags->args, double);
int copy = (int)nbr;
int precision = flags->precision;
int i = 0;

if (precision == -1)
precision = 6;
if (nbr < 0)
baby_putchar('-');
baby_put_nbr(copy);
baby_putchar('.');
i += baby_put_nbr(copy, flags, i);
i++;
flags->spec_buff.str[i] = '.';
nbr -= copy;
for (int i = 0; i < precision; i++)
nbr*= 10;
baby_put_nbr(nbr);
return baby_intlen(copy, 10) + baby_intlen(nbr, 10) + 1;
nbr *= 10;
i += baby_put_nbr(nbr, flags, i);
flags->spec_buff.count = baby_intlen(copy, 10) + baby_intlen(nbr, 10) + 1;
}

0 comments on commit 1fa3840

Please sign in to comment.