NaN or false as double precision return value
问题 I have a function that returns a double value. In some cases the result is zero, and this results should be handled in the caller routing accordingly. I was wondering what is the proper way of returning zero (NaN, false, etc!) in place of double value number: double foo(){ if (some_conditions) { return result_of_calculations; } else { // Which of the following is better? return std::numeric_limits<double>::quiet_NaN(); // (1) return 0; // (2) return false; // (3) return (int) 0; // (4) } }