I have a question that might save a lot of debugging time for many people...
Given a function:
void my_func(double value)
Is there any difference between the 2 following code lines?
double my_value = 1 - value;
and
double my_value = 1.0 - value;
I.e. given that value is double, if I use 1 - value, can I feel safe that the result will be the correct real number, like when using 1.0 - value?
There is no difference. To subtract a double from an int, the int has to be promoted to a double. I personally prefer to use 1.0 because I think that makes it clearer that it's not integer subtraction. But it's purely a style issue.
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