J
Joe Laughlin
On 6.2.3/115 of "Accelerated C++", there's this function:
double average(const vector<double>& v)
{
return accumulate(v.begin(), v.end(), 0.0) / v.size();
}
The author notes that it's important to use 0.0 in the function, as
accumulate uses the third argument's type as its return type.
Wouldn't it be better to explicity say
return accumulate(v.begin(), v.end(), double(0)) / v.size();
Is there a chance that floats and doubles might get mixed up if you don't do
a cast?
Thanks,
Joe
double average(const vector<double>& v)
{
return accumulate(v.begin(), v.end(), 0.0) / v.size();
}
The author notes that it's important to use 0.0 in the function, as
accumulate uses the third argument's type as its return type.
Wouldn't it be better to explicity say
return accumulate(v.begin(), v.end(), double(0)) / v.size();
Is there a chance that floats and doubles might get mixed up if you don't do
a cast?
Thanks,
Joe