I am aware that suffixing a floating point number with f lets the compiler know that it is a float rather than a double. Which is important to prevent unnecessary casting when operating on floats rather than doubles. However in some code I have been provided by an external company I have seen the following for example:
double i = 1.4f;
Now what I'm wondering is what happens in this case? Will the compiler silently ignore the 'f' and it is just something that has no bearing on anything and I can safely ignore?
I then wondered that if numbers are assigned to doubles with an f suffix elsewhere, not just on initialisation would that be a different case that acts differently?
Relevant quotes from the C standard:
§6.4.4.2 paragraph 4
If suffixed by the letter f or F, it has type float.
paragraph 5
Floating constants are converted to internal format as if at translation-time.
paragraph 7
The translation-time conversion of floating constants should match the execution-time conversion of character strings by library functions, such as strtod, given matching inputs suitable for both conversions, the same result format, and default execution-time rounding.
Assuming IEEE-754 numerics 1.4f
produces the value:
1.39999997615814208984375
whereas 1.4
has the value:
1.399999999999999911182158029987476766109466552734375.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With