Skip to main content
gamedev.net
🔒 Locked

Float vs. Double?

Started by fallout2600 Aug 6, 2002 at 9:08 AM 9 replies 1.6k views
Original Post
fallout2600
fallout2600
Just a quick question.......Is the difference between float and double a difference in size? If so....what are the sizes? Also in Visual C++ 6.0....how is this interrepted? 0.001 <- as a float or double? Thanks, fallout2600 ***The mind is the enemy....
shurcool
shurcool
i''m not sure about 0.001, but if u add a ''f'' to the end, it will be a float for sure. for example:
x += 0.001f; 
oh, and about sizes? try something like this:
printf("size of a float: %i\nsize of a double: %i", sizeof(float), sizeof(double)); 
hope that helped.

---
shurcool
wwdev
fallout2600
fallout2600
Shurcool,

Thanks....the printf was what I needed.

fallout2600
core
core
From an old edition of MSDN of mine:
quote:

Double precision values with double type have 8 bytes. The format is similar to the float format except that it has an 11-bit excess-1023 exponent and a 52-bit mantissa, plus the implied high-order 1 bit. This format gives a range of approximately 1.7E-308 to 1.7E308 for type double.



In a nutshell, doubles have twice the size and twice the precision of a float.


"If people are good only because they fear punishment and hope for reward, then we are a sorry lot indeed." - Albert Einstein
fallout2600
fallout2600
I get that doubles are 2 times in size than floats.....but in Visual C++ 6.0.............what does the compiler interrept this as?

x = 0.001; <- will this be a float or double value
x = 0.001f; <- or do I have to specify the f?


Thanks for the replies.......

fallout2600
krez
krez
it is a double unless you put the "f", then it is a float.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Shannon Barber
Shannon Barber
That''s the C specification that says floating point numbers default to double precision - you can override with by postpending an ''f'' to set it to float/single precision.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Jim_
Jim_
You could also write

x = float(0.001);

which is a little bit more readable, IMO

Jim
Shadow Wolf
Shadow Wolf
Typical ranges of float and double.
These values may vary on different computers and/or compilers.

float -3.4E-38 to 3.4E+38
double -1.7E-308 to 1.7E+308

Zipster
Zipster
quote:
You could also write

x = float(0.001);

which is a little bit more readable, IMO

Actually, the postfix ''f'' is quite readable too, and it''s really nice if you have a nested statement with lots of parenthesis as it is
Ronin_54
Ronin_54
You can also do:

x = (float)0.001;

I guess that one if the most difficult to read ;P

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.