home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11221 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  2.5 KB

  1. Path: sparky!uunet!usc!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Power Operator vs NANs
  5. Message-ID: <TMB.92Jul21152204@arolla.idiap.ch>
  6. Date: 21 Jul 92 19:22:04 GMT
  7. References: <BqJ16w.n3J@world.std.com> <1992Jun28.094255.13827@ucc.su.OZ.AU>
  8.     <BqM2JG.8Ds@news.cso.uiuc.edu> <1992Jun29.144814.5240@u.washington.edu>
  9.     <819@nazgul.UUCP> <1992Jul15.123527.3771@bnr.co.uk> <850@nazgul.UUCP>
  10. Sender: news@ai.mit.edu
  11. Reply-To: tmb@idiap.ch
  12. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  13.     Perceptive)
  14. Lines: 44
  15. In-reply-to: bright@nazgul.UUCP's message of 20 Jul 92 18:18:48 GMT
  16.  
  17. In article <850@nazgul.UUCP> bright@nazgul.UUCP (Walter Bright) writes:
  18.  
  19.    C++ has abandoned ones-complement hardware and 6-char linkers, that C
  20.    was unwilling to leave behind. Maybe it is time to leave behind non-IEEE
  21.    floating point too.
  22.  
  23. C++ does not specify how integer arithmetic is to be performed on the
  24. machine. And, personally, I don't think it's time to leave behind
  25. non-IEEE floating point.
  26.  
  27.    /Exactly what would a language extension give you that you couldn't do using
  28.    /(FPU specific) function calls?
  29.  
  30.    What you gain with a language extension vs function calls:
  31.    1. syntactic clarity
  32.    2. portability (assuming others implement it too)
  33.    3. compiler can detect errors
  34.    4. static initialization
  35.    5. efficiency
  36.  
  37. There is a nice middle road. You can use functional/macro syntax
  38. (isnan(x), isinf(x), ...) to denote standardized IEEE floating point
  39. operations. Such notation is straighforward, simple, and easy to
  40. implement even in existing compilers. Via the usual "#define foo(x)
  41. __foo(x)" trick, you can get macro semantics (i.e., you don't get the
  42. feature unless you #include the header file) with the efficiency and
  43. flexibility of a language extension.
  44.  
  45.    For instance, only Zortech's compiler correctly (IEEE 754) implements
  46.    == and != (others set the exception bits incorrectly if one operand
  47.    is a NAN). Do you really want to do isequal(a,b) instead of a==b?
  48.  
  49. I would want neither. The behavior of operator== on NaN's should be
  50. left undefined. If you care to know whether operator== is operating on
  51. a NaN, you should simply test beforehand:
  52.  
  53.     if(isnan(x)||isnan(y)) { ... }
  54.     else if(x==y) { ... }
  55.  
  56. Sadly, this is a losing battle. NCEG seems to be determined to go down
  57. this route of adding lots of IEEE specific, complicated, useless
  58. operators, and the C++ language is likely to follow suite.
  59.  
  60.                 Thomas.
  61.