double f_64 = 3.35f;
double f1_64 = 3.35;
What is the effect if suffix 'f' is used?
With the online FPU compilers, hexadecimal results are as below
With suffix f
- 0x400ACCCCC0000000
,
without suffix f
- 0x400ACCCCCCCCCCCD
.
double f_64 = 3.35f;
double f1_64 = 3.35;
What is the effect if suffix 'f' is used?
With the online FPU compilers, hexadecimal results are as below
With suffix f
- 0x400ACCCCC0000000
,
without suffix f
- 0x400ACCCCCCCCCCCD
.
The f
suffix forces the compiler to treat the value as float
as opposed to a double
which in the below assignment doesn't make much sense.
double f_64 = 3.35f;
// Why force a value to float when you've allocated memory for a double
Remember that double
is is 2X the precision of float
. Choose the type as per your specific needs.
But, say,you're doing
float ans;
ans = 3/2; // ans is trimmed to an int
ans = 3/2.0f; // The decimals are retained