3 Attachment(s)
128 bit (long double) printf not working
I have run the following code to see what my computer's byte size is for each data type:
Code:
#include <stdio.h>
#include <limits.h>
int main()
{
printf("The size of char in bytes is: %llu.", sizeof(char));
printf("\nThe size of short in bytes is: %llu.", sizeof(short));
printf("\nThe size of int in bytes is: %llu.", sizeof(int));
printf("\nThe size of long in bytes is: %llu.", sizeof(long));
printf("\nThe size of long long in bytes is: %llu.", sizeof(long long));
printf("\nThe size of float in bytes is: %llu.", sizeof(float));
printf("\nThe size of double in bytes is: %llu.", sizeof(double));
printf("\nThe size of long double in bytes is: %llu.", sizeof(long double));
return 0;
}
Attachment 14837
However, when I try to use printf for long double, it always prints the same junk exponent value regardless of what the variable is set to in the program.
Code:
#include <stdio.h>
int main()
{
long double x = 3.1415;
printf("%Lg", x);
return 0;
}
Attachment 14836
I have read on the internet forums that this is either a printf limitation or a compiler issue or some combination of these. I am using a MinGW GCC 6.1.0 compiler on a 64-bit Windows PC.
How do I fix this? Do I need to get a different compiler or is there another C function that can print this 16-bit (or 20-bit) long double properly?