Re: How to store a number that is "n/a"?

From: Tony Proctor (tony_proctor_at_aimtechnology_NOSPAM_.com)
Date: 07/28/04


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.



Relevant Pages

  • Re: Rich Comparisons Gotcha
    ... No float can be equal to nan, ... The truth value of an array with more than one element is ... The designers of numpy thought that this would be a more desirable behavior. ... But the fact that someone can create a bug with a language is not a condemnation of the language. ...
    (comp.lang.python)
  • Re: Problem with log function - Intel fortran compiler under Linux
    ... compiler under Linux ... an NaN (while the argument is a perfectly acceptable value of about ... Linux: Red Hat Enterprise Linux, ... I then tried with debugging on and array bound checking ...
    (comp.lang.fortran)
  • Re: Comparing floating point values in Java
    ... I was calculating an array of float values from some user input. ... Having a magic value isn't generally a good idea, although NaN would be ... Using any magic value, including NaN, has the risk that a bug elsewhere ...
    (comp.lang.java.programmer)
  • Re: Comparing floating point values in Java
    ... I was calculating an array of float values from some user input. ... Having a magic value isn't generally a good idea, although NaN would be ... Using any magic value, including NaN, has the risk that a bug elsewhere ...
    (comp.lang.java.programmer)
  • Re: What should MIN and MAX do when an argument is NaN ?
    ... The proposed new IEEE standard specifies operations ... language extension of them to multiple arguments is obvious). ... If one argument is NaN, but not the other, the result is required ... no deficiencies and the other way is to make it so complicated ...
    (comp.lang.fortran)