I'm implementing the printf()
function. Nearly everything works correctly, but I have an issue when called as ft_printf("%f", -0.0)
. My program outputs 0.0
instead of -0.0
. I can't use any libraries.
My condition for checking for negativity is simply "x<0" which doesn't include my problem. I've found a promising solution in Distinguish zero and negative zero.
this is what seems would solve my problem:
double a = -0.0;
printf("%d\n", (*((long *)&a) == 0x8000000000000000));
I'd like for this program to print 1
but in my program when I do it in my code it outputs 0
. The part I have a problem understanding is how this: *((long *)&a)
makes a number comparable to its hexadecimal counterpart.