Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Returning NaN in a double array
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Farhan Ahmed  
View profile   Translate to Translated (View Original)
 More options Jul 5 2012, 5:07 pm
From: Farhan Ahmed <Far...@ycharts.com>
Date: Thu, 5 Jul 2012 14:07:58 -0700 (PDT)
Local: Thurs, Jul 5 2012 5:07 pm
Subject: Returning NaN in a double array

The UDF I've implemented in ExcelDNA returns an object[,] array wrapped in
a call to the "resize" function (as available in the samples) since I need
to be able to change the values of the adjacent cells.

The object[,] is guaranteed to always be object[1,n]. Values are *almost
always* doubles, except in cases where the requested data does not exist.
In cases where the data does not exist, I want to return NaN to Excel such
that this value does not affect the AVERAGE, STDDEV, etc. functions.

If I set the corresponding value in the array to double.NaN, Excel fills
the cell with a very large value (looks like double.MaxValue) and it screws
up the calculations. If I check for NaN and set the corresponding element
in object[,] to "", Excel shows a value error (assuming this is because the
the objects are of mixed types).

What is the correct way to handle this issue?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Govert van Drimmelen  
View profile   Translate to Translated (View Original)
 More options Jul 6 2012, 4:55 am
From: Govert van Drimmelen <gov...@icon.co.za>
Date: Fri, 6 Jul 2012 01:55:00 -0700 (PDT)
Subject: Re: Returning NaN in a double array
Hi Farhan,

Indeed Excel does not display the double.NaN or double.Infinity values
very well. However, even though these are displayed as large numbers,
you can do no calculations on them.

So if you make this function:

    public static double getNaN()
    {
        return double.NaN;
    }

and in cell A1 you put =GetNaN(), Excel will display something like:
2.69653970229347E+308
However, try to put in =getNaN() + 0, and Excel will go to a #NUM!
error immediately - it can't actually compute with that large number,
it's just the display routine outputting the double.NaN bits into a
string.
Similar for double.PositiveInfinity.

So if your functions is returning a double, or a double[,] array,
Excel gives us no way to return a value that will be ignored.

But I think you already have the answer -
"If I check for NaN and set the corresponding element in object[,] to
"", Excel shows a value error (assuming this is because the the
objects are of mixed types)."

This is the right plan and you should _not_ be getting an error from
Excel when doing this - if you return an object or object[,] array,
you can return a mixture of types, including some empty strings which
Excel will ignore that value in functions like AVERAGE.

For example, make this function:

    public static object get10Blank()
    {
        return new object[,] {{10}, {""}};
    }

Now putting =get10Blank() into as an array formula  into cells A1 and
A2, then in A3 I put =AVERAGE(A1:A2) I get the expected result: 10.

Maybe you were not returning the array that was modified with the ""
replacements, or there is some other error in your code causing an
exception (which is returned to Excel as #VALUE)?

Does this make sense?

Regards,
Govert

On Jul 5, 11:07 pm, Farhan Ahmed <Far...@ycharts.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Farhan Ahmed  
View profile   Translate to Translated (View Original)
 More options Jul 6 2012, 3:26 pm
From: Farhan Ahmed <far...@ycharts.com>
Date: Fri, 6 Jul 2012 14:26:40 -0500
Local: Fri, Jul 6 2012 3:26 pm
Subject: Re: [ExcelDna] Re: Returning NaN in a double array

Hey Govert,

Thank you for the detailed reply. You know what - replacing the object with
a "" works now. I have no idea why it wasn't working for me yesterday -
perhaps I was in need of more coffee.

Thanks for your help,

Farhan

On Fri, Jul 6, 2012 at 3:55 AM, Govert van Drimmelen <gov...@icon.co.za>wrote:

--
Farhan Ahmed
far...@ycharts.com | ycharts.com
P: 425-802-3818

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »