As everybody knows, you have limited precision when you use printf to output the value of a float.
However, there is a trick to increase the accuracy in the output, as this example shows:
#include <stdio.h>
int main()
{
float f = 1318926965; /* 10 random digits */
printf("%10.f\n", f); /* prints only 8 correct digits */
printf("%10d\n", *(int*)&f); /* prints all digits correctly */
return 0;
}
and my question is, why don’t people use this trick more often?
April fool?
Your “random number”
1318926965have the same underlying representation both in decimal and floating-point form.Try another value, like
10. It will print as:So to answer your question:
Because only one day of the year is April Fools Day… The rest of the days the trick doesn’t work…