home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / sci / math / 17358 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  3.8 KB

  1. Path: sparky!uunet!pipex!unipalm!uknet!acorn!armltd!dseal
  2. From: dseal@armltd.co.uk (David Seal)
  3. Newsgroups: sci.math
  4. Subject: Re: Not-a-Number
  5. Message-ID: <11023@armltd.uucp>
  6. Date: 23 Dec 92 13:16:12 GMT
  7. References: <1428@kepler1.rentec.com>
  8. Sender: dseal@armltd.uucp
  9. Distribution: sci
  10. Organization: A.R.M. Ltd, Swaffham Bulbeck, Cambs, UK
  11. Lines: 71
  12.  
  13. In article <1428@kepler1.rentec.com> andrew@rentec.com (Andrew Mullhaupt)
  14. writes:
  15.  
  16. >In article <BzGwEC.ALr@unx.sas.com> sasbmt@jjoyce.unx.sas.com (Bruce Tindall) writes:
  17. >>
  18. >>In article <7ZJ0uB1w165w@west.darkside.com>, susskind@west.darkside.com (Mark Susskind) writes:
  19. >>>On to the main purpose.  I believe that it would be pointless to assign
  20. >>>Not-a-Number to a variable because one cannot really do any algebra with
  21. >>>it.  For a quick example, let x=NaN.  What would be x+1?  What about 2x?
  22. >>>And 0x would be every real (or complex) number, would it not?
  23. >
  24. >Actually, there are _conceivable_ uses of NaN assignment...
  25.  
  26. See below for an actual use of NaNs...
  27.  
  28. >>Certain software systems, such as the SAS system, recognize several
  29. >>different "not a number" values (which SAS calls "missing values").  
  30. >>Usually, any arithmetic operation on a missing value yields a missing 
  31. >>value.  There are some circumstances in which missing values are 
  32. >>treated as zero instead. 
  33. >
  34. >Which in particular shows that the sensible treatment of missing values
  35. >is different than the sensible treatment of non-numbers.
  36. >
  37. >> In sorting and comparisons, missing values 
  38. >>sort as less than the "most negative" number (i.e., less than the 
  39. >>negative number with the greatest absolute value).
  40. >
  41. >This is also different than not a number.
  42.  
  43. The IEEE standard allows for two types of NaN, namely "quiet" NaNs and
  44. "signalling" NaNs. Arithmetic operations on a quiet NaN simply produce the
  45. NaN itself as the result. Arithmetic operations on a signalling NaN raise an
  46. "invalid operation" exception. The exception can be trapped; if not, by
  47. default the result is a quiet NaN. If it *is* trapped, a well-designed trap
  48. handler can find out what the operation and operands were, then produce
  49. results by its own rules. (I say "well-designed" because the standard
  50. doesn't actually require that this is possible: it is intended to be the
  51. case, but the standard allows you to produce a system which has been cut
  52. down in this respect.)
  53.  
  54. Now for the application: you can use signalling NaNs to represent such
  55. missing values. You simply write and install a trap handler that implements
  56. whatever arithmetic rules you want to apply to them (e.g. producing another
  57. "missing value" by returning a suitable signalling NaN as the result of the
  58. operation). Then enable the "invalid operation" trap and arithmetic on
  59. missing values works the way you want it to. Similarly, a comparison of a
  60. signalling NaN and a number will enter the trap handler: you can then make
  61. the result come out as "less than" if you want.
  62.  
  63. Provisos: Many systems don't implement this area of the IEEE standard fully,
  64. or require performance losses to get full compliance. Also, obtaining the
  65. result of an operation by executing a trap handler is obviously much slower
  66. than just using an instruction or two. In short, these facilities don't come
  67. for free!
  68.  
  69. >It would be nice to have a standard arithmetic which dealt with unspecified
  70. >values, but none exists to my knowledge.
  71.  
  72. IEEE arithmetic does at least give you the building blocks for such an
  73. arithmetic. Admittedly, something that did not depend on the use of trap
  74. handlers would be better - i.e. something that handled missing values in
  75. hardware. But there are many different extensions to ordinary arithmetic
  76. that people might want, and specialised hardware would be useless for all
  77. but the one it actually implements. In short, there's a trade-off between
  78. speed and flexibility here...
  79.  
  80. David Seal
  81. dseal@armltd.co.uk
  82.  
  83. All opinions are mine only...
  84.