Floating Point Types
-
float
is the basic floating point type.
- There is also
double
and long double
- To make sure a constant is a float
- add a decimal point (8.0)
- These are by default a double.
- Add a f at the end indicates a float (8.0f)
- or a l is a long double (8.0l);
- Floats can be written in scientific notation
-
3E4
is $3.0 x 10^4$
- 8.4E-5 is valid as well.
- 9.34E+7 is good.
- Not all floating point numbers can be accurately represented.
- 1/10 for example.
- This is called roundoff error.
- Be careful, we can't represent all of the rational numbers between 1 and 2.
- Try 0.1