I am trying to print floats. Although variadic functions does not work with floats so they are promoted to double. I can manage to get rid of the warning by casting it to a double. While printing the results on some powerpc architecture, it gives incorrect value if printed with %f. Why ?

Test Code:

 #include <stdio.h>

 #define _echo_size(X) \
        printf ("Sizeof "#X" %u\n", sizeof(X))

int main (void)
{

        float x;
        long usec = 7L;

        _echo_size(float);
        _echo_size(double);
        _echo_size(short);
        _echo_size(int);
        _echo_size(long);
        _echo_size(long long);

        x = ((float) usec) / 2;
        printf("Expected: 3.5 Got: %1.1f\n", (double) x);
        printf("Expected: 3.5 Got: %1d.%.1d\n", (int)x,
                (int)((x-(int)x)*10));
        return 0;
}

X86 system result:

Sizeof float 4
Sizeof double 8
Sizeof short 2
Sizeof int 4
Sizeof long 8
Sizeof long long 8
Expected: 3.5 Got: 3.5
Expected: 3.5 Got: 3.5

ppc system result:

Sizeof float 4
Sizeof double 8
Sizeof short 2
Sizeof int 4
Sizeof long 4
Sizeof long long 8
Expected: 3.5 Got: 0.0  <--- Why this ?
Expected: 3.5 Got: 3.5

Is it a bug in the tool-chain ? otherwise what is the elegant way to print floats ?

Edit
Report