Excluding NAN entries when summing an array

Discussion in 'C++' started by RS, Sep 21, 2006.

  1. RS

    RS Guest

    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
    RS, Sep 21, 2006
    #1
    1. Advertising

  2. 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!=myarray) // skip this entry, a NaN
    }


    HTH,
    - J.
    Jacek Dziedzic, Sep 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alf P. Steinbach
    Replies:
    2
    Views:
    531
    Chris Theis
    Feb 5, 2004
  2. max(NaN,0) should be NaN

    , Aug 28, 2006, in forum: C Programming
    Replies:
    61
    Views:
    1,251
    Michel Hack
    Sep 8, 2006
  3. RS
    Replies:
    0
    Views:
    345
  4. Replies:
    6
    Views:
    1,514
    Richard Tobin
    Mar 19, 2009
  5. Don Bruder
    Replies:
    3
    Views:
    965
    spikeysnack
    Aug 3, 2010
Loading...

Share This Page