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 firstname.lastname@example.org. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Modulus of two float or double numbers
- C/C++ program to find the size of int, float, double and char
- What is the difference between single quoted and double quoted declaration of char array?
- Difference between Single Precision and Double Precision
- Difference between Single Bus Structure and Double Bus Structure
- Comparison of a float with a value in C
- <cfloat> float.h in C/C++ with Examples
- Function Overloading and float in C++
- gcvt() | Convert float value to string in C
- Assigning an integer to float and comparison in C/C++
- Double forking to prevent Zombie process
- C program to print a string without any quote (singe or double) in the program
- Double Pointer (Pointer to Pointer) in C
- Difference between H.323 and SIP
- Difference Between Gi-Fi and Li-Fi
- Difference between DML and TCL
- Difference between PNG and GIF
- Difference between ADO and ADO.NET
- Difference between DTE and DCE
- Difference between LAN and MAN
Improved By : msdeep14