For representing floating point numbers, we use float, double and long double.
What’s the difference ?
double has 2x more precision then float.
float is a 32 bit IEEE 754 single precision Floating Point Number1 bit for the sign, (8 bits for the exponent, and 23* for the value), i.e. float has 7 decimal digits of precision.
double is a 64 bit IEEE 754 double precision Floating Point Number (1 bit for the sign, 11 bits for the exponent, and 52* bits for the value), i.e. double has 15 decimal digits of precision.
Let’s take a example(example taken from here) :
For a quadratic equation x2 – 4.0000000 x + 3.9999999 = 0, the exact roots to 10 significant digits are, r1 = 2.000316228 and r2 = 1.999683772
roots of equation x2 - 4.0000000 x + 3.9999999 = 0 are : for float values: 2.00000 2.00000 for double values: 2.00032 1.99968
This article is contributed by Mandeep Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- What is size_t data type in C language?
- Interesting facts about data-types and modifiers in C/C++
- std::next vs std::advance in C++
- Differences between JDK, JRE and JVM
- Difference between fork() and exec()
- Why quicksort is better than mergesort ?
- Character arithmetic in C and C++
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- Type Conversion in C
- Setting decimal precision in C
- Storage Classes in C
- Static Variables in C
- Data Types in C
- Comparison of a float with a value in C
- C Language Introduction
Improved By : msdeep14