I have to reimplement printf(3)
with C
wihtout using any function that would do the conversion for me.
I thought I was done after I understood thanks you to guys how %a
worked: How %a conversion work in printf statement?
Then I realized I didn't understand how the rounding
was done so I asked: C printf float rounding and then thought that I was done after you helped me.
And now that %a
is completely working just like the official one I thought %La
would do exactly the same as %a
but with a long double
since the man only says:
Modifier a, A, e, E, f, F, g, G
l (ell) double (ignored, same behavior as without it)
L long double
And I discover that it outputs something completely different :'(
double a_double = 0.0001;
long double a_long_double = 0.0001;
printf("%a\n", a_double); #=> 0x1.a36e2eb1c432dp-14
printf("%La\n", a_long_double); #=> 0xd.1b71758e21968p-17
The %a
result always begins with 1.
and now I don't understand at all what the %La
is doing.
Could you help me understand the process that transforms 0.0001
to 0xd.1b71758e21968p-17
?
EDIT: the part that I really don't understand is why %a
always outputs something that starts with 1.
and not %La
?
EDIT2: To be even more precise: why does %a
chooses to output 1. ...p-14
and %La
chooses to output d. ...p-17
?