I
Ioannis Vranos
ISO/IEC 9899:1990/1995 says (from K&R2):
“A6.4
When a less precise floating value is converted to an equally or more
precise floating type, the value is unchanged.
==> When a more precise floating value is converted to a less precise floating type, and the value is within
representable range, the result may be either the next higher or the next lower representable value.
If the result is out of range, the behavior is undefined”.
Question: Does the above mean that it is a good practice or *always*
needed to use the appropriate type suffixes with floating point constants?
An example of this:
#include <stdio.h>
int main(void)
{
float f1 = 0.33439F;
float f2= 0.33439f;
printf("\nf1= %f, f2= %f\n", f1, f2);
double d1= 0.33439;
double d2= 0.33439;
printf("\nd1= %f, d2= %f\n", d1, d2);
/* It doesn't work with MINGW, compiler is broken regarding long double. */
long double ld1= 0.33439L;
long double ld2= 0.33439l; /* 'l' is the lower case 'L'. */
printf("\nld1= %Lf, ld2= %Lf\n\n", ld1, ld2);
return 0;
}
“A6.4
When a less precise floating value is converted to an equally or more
precise floating type, the value is unchanged.
==> When a more precise floating value is converted to a less precise floating type, and the value is within
representable range, the result may be either the next higher or the next lower representable value.
If the result is out of range, the behavior is undefined”.
Question: Does the above mean that it is a good practice or *always*
needed to use the appropriate type suffixes with floating point constants?
An example of this:
#include <stdio.h>
int main(void)
{
float f1 = 0.33439F;
float f2= 0.33439f;
printf("\nf1= %f, f2= %f\n", f1, f2);
double d1= 0.33439;
double d2= 0.33439;
printf("\nd1= %f, d2= %f\n", d1, d2);
/* It doesn't work with MINGW, compiler is broken regarding long double. */
long double ld1= 0.33439L;
long double ld2= 0.33439l; /* 'l' is the lower case 'L'. */
printf("\nld1= %Lf, ld2= %Lf\n\n", ld1, ld2);
return 0;
}