result
is float
and I could code this three ways:
if (result < 0)
if (result < 0.)
if (result < 0.f)
As I understand it,
0
is implicitly int
,0.
is implicitly double
0.f
is float
.I'd prefer to use the first method since it is clear and simple but am I forcing a type conversion by using it?
Conceptually yes, conversions are made.
But you should defer such micro-considerations to the compiler and write what's clearest which, for me is
if (result < 0)
If you are ever in any doubt, check the generated assembly (very easy with https://gcc.godbolt.org/).
Finally, when deciding to use a float
over a double
, consider double or float, which is faster?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With