User forums > Help
Code::Blocks don't recognize float and double types !!!!
thomas:
It is, but if x and y are both integers, it calculates
i = (float) (6/7) = (float)(0) = 0.0f
EDIT:
Besides, there are many other possible pitfalls that you can encounter using float or double.
Make sure you read and understand exactly what is going on there, or you will almost certainly run into problems.
For example, you should never use operator== on floats or doubles unless you know what you are doing.
Also, you should never rely on floating point operations to be exact, predictable or reproducable (example).
All that a float guarantees is that you have 32 bits of precision when it is written to memory (and double has 64 bits). Strictly speaking, you cannot even rely on that... but let's not make things too complicated and assume the 'usual'. ;)
Internally, the CPU may use 32bits, 64bits, 80bits, 96bits, or whatever the hardware happens to have as register size (usually 80+ bits). Thus, a float value that is passed from one register to another is different from one that is obtained from memory, even if you perform precisely the same operations. So a == b is almost certain to cause trouble!
Navigation
[0] Message Index
[*] Previous page
Go to full version