By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,045 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,045 IT Pros & Developers. It's quick & easy.

Excluding NAN entries when summing an array

P: n/a
RS
Hi all, what is a safe and efficient way to sum the contents of an array
or a matrix, skipping any possible NANs or INFs?

Thanks,
RS
Sep 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
RS wrote:
Hi all, what is a safe and efficient way to sum the contents of an array
or a matrix, skipping any possible NANs or INFs?
The NaN has this queer property that if x is a NaN, then
x!=x. Therefore you may skip NaNs with something like

for(...) {
if(myarray[i]!=myarray[i]) // skip this entry, a NaN
}
HTH,
- J.
Sep 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.