I am a C++ noob.
What I am trying to do is sum the values of a vector of doubles (let's call it x
) and ignore any values that are NaN. I tried to look this up, but I couldn't find anything specifically referencing what would happen if a vector contains any NaN values.
E.g.:
// let's say x = [1.0, 2.0, 3.0, nan, 4.0]
y = sum(x) // y should be equal to 10.0
Would the accumulate
function work here? Or would it return NaN
if x
contains a NaN
? Would a for loop work here with a condition to check for if the value is NaN
(if yes, how do I check if NaN
? In Python, the language I know best, this kind of check is not always straightforward).