+ 2
Why is it advisory to use "float" instead o"double" in C++?
Float Vs Double
4 Answers
+ 6
Your answer shouldn't be "why" it's advisory, it should be "when" it's advisory.
Double usually has a lot more precision, but uses more bytes.
How much depends on the compiler and the hardware, so if you want constant precision on every system, use float. However, that's rarely the case.
It could be problematic if you convert double to float and vice versa, so try not to.
Modern computers don't have any space or speed issues when preferring double over float, most compilers even use double automatically if you don't use a float literal.
(1 is int, 0.0 is double, 0.0f is float)
You might have memory issues on embedded systems (microchips etc), so perhaps float is advisory there if you don't need high precision.
+ 6
The C++ standard adds: The value representation of floating-point types is implementation-defined. ... A double is 64 and single precision (float) is 32 bits. The double has a bigger mantissa (the integer bits of the real number).
+ 2
đgood explanation @Chris I now understand.
@Kinshuk Vasisht @SD thanks I now have a clear understanding