Can someone explain what does literals e and f mean while representing a floating point in c ? for eg
float f = 6.8558e-4f
Can someone explain what does literals e and f mean while representing a floating point in c ? for eg
float f = 6.8558e-4f
From the 2018 C standard, clause 6.4.4.2, reworded:
e
or E
followed by an optional sign and a sequence of digits, such as e13
or e-4
.double
. If suffixed by the letter f
or F
, it has type float
. If suffixed by the letter l
or L
, it has type long double
.”Thus 6.8558e-4f
represents 6.8558•10−4 and produces a float
value.
Note that most C implementations use a float
format based on powers of 2, not 10, so they cannot represent 6.8558•10−4 exactly. In the format commonly used, IEEE-754 binary32, the closest representable value is 0.0006855800165794789791107177734375.
The e
indicates scientific notation. So 6.8558e-4
is equivalent to 6.8558×10−4.
The f
is a suffix that indicates a floating-point number. (Floating-point numbers are treated as double precision by default.)
Incidentally, C99 also introduced a hexadecimal notation for floating point numbers, which you can read about here: hexadecimal floating constant in C