Re: How to store a number that is "n/a"?
From: Tony Proctor (tony_proctor_at_aimtechnology_NOSPAM_.com)
Date: 07/28/04
- Next message: Garry: "Re: MDI forms"
- Previous message: Larry Serflaten: "Re: Strange problem"
- In reply to: Duane Bozarth: "Re: How to store a number that is "n/a"?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 28 Jul 2004 10:31:19 +0100
There are actually 2 flavours of NaN ("Not A Number") values defined by the
IEEE standard: signalling (which raises an exception when accessed) and
quiet (which simply propagate through calculations. Although VB doesn't have
intrinsic support for these, I see no reason why you couldn't utilise them
in your code since they're supported by the processor. One special quiet
NaNs is called "indefinite" by Intel, and corresponds to the result of an
"invalid operation" in IEEE terms, e.g. 0/0, sqrt(-n), etc
You may need code to insert the correct bit pattern, and something similar
to C's isnan() function to test for them, but I believe they should work.
Even interfaces like CStr() and Format() will return the standard C-lib
string corresponding to a NaN, or Infinity value. I know this much because
these special numeric representations *can* be returned by other MS
components (e.g. Analysis Services).
...in fact, thinking about this a little, I'm sure I've posted some sample
code to test for NaNa in these newsgroups before, although I can't see it at
the moment.
Tony Proctor
"Duane Bozarth" <dp_bozarth@swko.dot.net> wrote in message
news:41011E0F.32A62971@swko.dot.net...
> Ed White wrote:
> >
> > Frequently when working with data tables, a number in a certain cell is
not available, e.g. "n/a". In Microsoft Excel, such a number can be stored
in a cell with the value #N/A. However, I'm working in VB.Net with a column
of numbers stored in an array which is Dim as Decimal. Is there a way to
store a number in the decimal array (or any other number array, e.g.
integer, etc.) as n/a similar to #N/A in Excel. Otherwise, storing zero, or
say -999999, just messes up my calculations based upon the array. Any
suggestions on how to deal with this?
>
> You've one of two choices--either use the "magic value" and test for it
> (fraught with the problem that unless the problem data range is bounded,
> there's always the possibility that the use really wants the particular
> value you've chosen--probably a rare event, but can't be ignored) or you
> make a corollary array that is a "quality indicator" and test it. My
> impression has been that this is what Excel is doing "under the hood",
> so to speak.
>
> One other option would be to make the data Variant and store the #N/A
> there and do the test/conversion on usage. I'm not sure what .Net's
> Decimal type is (this <is> a VB "classic" group :) ), but I'm presuming
> its some longer integer so any bit pattern may be a legal value. For
> floating point, there are bit patterns that represent NaN, etc., that
> <can> be used and trapped.
- Next message: Garry: "Re: MDI forms"
- Previous message: Larry Serflaten: "Re: Strange problem"
- In reply to: Duane Bozarth: "Re: How to store a number that is "n/a"?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|