0
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.

sjsam
  • 21,411
  • 5
  • 55
  • 102
Gopinath
  • 1
  • 1
  • ["f" after number/float in Objective-C/C](https://stackoverflow.com/q/2391818/995714), [Is there a functional difference between "2.00" and "2.00f"?](https://stackoverflow.com/q/7697148/995714), [C float assignment from literal](https://stackoverflow.com/q/25209576/995714), [Purpose of a ".f" appended to a number?](https://stackoverflow.com/q/4828167/995714) – phuclv Apr 22 '19 at 03:53

1 Answers1

1

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
sjsam
  • 21,411
  • 5
  • 55
  • 102
  • 1
    There may be very rare situations in which one wants a double initialized with the value that would have resulted from initializing a float to 3.35f, perhaps for comparison to a float. – Patricia Shanahan Apr 22 '19 at 08:49
  • @PatriciaShanahan I agree to what you pointed out. – sjsam Apr 22 '19 at 09:36