Good day
A simple question, whats the difference between :
andCode:
float number = 12.34f;
Code:
float number = 12.34;
Printable View
Good day
A simple question, whats the difference between :
andCode:
float number = 12.34f;
Code:
float number = 12.34;
>float number = 12.34f;
This assigns a single precision value to a single precision variable.
>float number = 12.34;
This assigns a double precision value to a single precision variable, your compiler may warn about this.
-Prelude
that then begs the question, What's the difference between a single precision variable and a double precision variable?
A double precision variable has twice the precision of a single precision variable. Isn't that kind of obvious?
Actually, double doesn't necissarily mean twice the precission.
Yea, but you can't quantify exactly what the difference is, so twice as much as as good as any for a "Duh" question like that.
consider a number 3.14285
If you store it in a variable do you want to save it as 3.14 or 3.142.
According to my c++ book float uses 7 digits precision and a total of 4 bytes. Does that mean if I write
it uses 7 digits precision and if I writeCode:float number = 12.34;
it uses 14 digits precision ?Code:float number = 12.34f;
No, the former has more precision than the latter.Quote:
Originally posted by laasunde
According to my c++ book float uses 7 digits precision and a total of 4 bytes. Does that mean if I write
it uses 7 digits precision and if I writeCode:float number = 12.34;
it uses 14 digits precision ?Code:float number = 12.34f;
So this is correct thenQuote:
Originally posted by Polymorphic OOP
No, the former has more precision than the latter.
float number = 12.34; // 14 digits precision
float number = 12.34f; // 7 digits precision
Both using 4 bytes of memory.
Nono, float is usually 4 bytes and double is usually 8 bytes. Notice it's usually -- the standard only says that double has to be greater than or equal to the size and precission of float.
4-byte float is generally accurate to 23 binary digits and 8-byte double is generally accurate to 52 binary digits.