home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1182 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  4.1 KB

  1. Xref: sparky comp.std.c++:1182 comp.lang.c++:13666
  2. Newsgroups: comp.std.c++,comp.lang.c++
  3. Path: sparky!uunet!mcsun!sunic!lth.se!newsuser
  4. From: dag@control.lth.se (Dag Bruck)
  5. Subject: Re: Exponentiation operator proposal
  6. Message-ID: <1992Sep15.061626.21735@lth.se>
  7. Sender: newsuser@lth.se (LTH network news server)
  8. Organization: Department of Automatic Control, Lund, Sweden
  9. References: <23660@alice.att.com> <1992Sep13.193507.27813@ima.isc.com> <BuJJxs.8Hx@world.std.com> <23663@alice.att.com>
  10. Date: Tue, 15 Sep 1992 06:16:26 GMT
  11. Lines: 103
  12.  
  13. In <comp.std.c++,comp.lang.c++> bs@alice.att.com (Bjarne Stroustrup) writes:
  14. >
  15. >How frequent is a**p anyway?
  16.  
  17. I asked the net how frequent exponentiation is, and got very few
  18. answers back; there are some interesting observations, though. Nobody
  19. took the offer to look at the really big FORTRAN libraries.  In my
  20. view the results are inconclusive at this point.
  21.  
  22. I haven't looked at the latest version of the proposal, but I strongly
  23. ask the authors to support their requests with solid user's experience
  24. from related applications, not necessarily in C++.  If you can show
  25. that exponentiation is more common than division (just as an example),
  26. that is indeed a very strong argument.  Sorry to nit pick if you have
  27. already done it.
  28.  
  29. In any case, here follows the answers I got, somewhat edited for
  30. clarity:
  31.  
  32.             -- Dag
  33.  
  34. ========================================================================
  35.  
  36. From: matt@physics.berkeley.edu (Matt Austern)
  37. Subject: Re: Power operator for C++
  38. Date: 6 Jul 92 14:28:39
  39. Organization: Lawrence Berkeley Laboratory (Theoretical Physics Group)
  40.  
  41. In article <1992Jul5.133125.5575@lth.se> dag@control.lth.se (Dag Bruck) writes:
  42.  
  43. > I ask someone with access to a lot of numerical code (perhaps written
  44. > in FORTRAN) to do us a favour: gather some statistics that can tell us
  45. > how common exponentiation is compared to other operators, such as,
  46. > addition, subtraction, multiplication and division.  Compared to
  47. > square root?
  48.  
  49. I just did a bit of grepping on a moderate-sized (30,000 lines)
  50. Fortran program, called Papageno.  I suspect that it is fairly typical
  51. of code used in particle physics.
  52.  
  53. Some statistics:
  54.     Operator    Number of lines containing operator
  55.     --------    -----------------------------------
  56.       total        32000
  57.       +        10711
  58.       *        6805
  59.       -        6253
  60.       /        3382
  61.       **        1481
  62.  
  63. The result, then, is that exponentiation is about half as common in
  64. this program as division.  To me, at least, this qualifies as
  65. "common".  Certainly nobody would suggest that a division operator is
  66. unnecessary just because it is used only half as much as subtraction!
  67.  
  68. (Many lines uses exponentiation more than once; in total, the operator
  69. ** is used 4496 times in PAPAGENO.)
  70.  
  71. Looking over the code, by the way, it seems that the vast majority of
  72. the time, ** is used to raise a quantity to an integral power.  (I
  73. didn't gather statistics; that would require more effort than a simple
  74. grep!)  This suggests that pow(double,double) is not a good
  75. substitute; a better substitute would be pow(double,int), which is not
  76. in the standard library.
  77.  
  78.  
  79. From: maxtal@extro.ucc.su.OZ.AU (John (MAX) Skaller)
  80. Subject: Re: Power operator for C++
  81. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  82. Date: Mon, 6 Jul 1992 06:22:57 GMT
  83.  
  84.     I have a program which calculates gaussian dispersion of
  85. toxic materials in air. In the bits that do calculations work,
  86. here are the scores in terms of line counts
  87. [I did grep token file | wc]
  88.  
  89. Lines total:    172
  90. +        27
  91. -        24
  92. *        25
  93. /        32
  94. %        2
  95. =,==,etc    79
  96. pow        13
  97. fsqr        12    // inline to square number
  98. sqrt        3
  99.  
  100. IMHO if you cheat a bit and add the last three you get 28, second
  101. only to use of '/'. I'd be happy to post the code if that was
  102. desired [minus flames on style :-)
  103.  
  104.  
  105.  
  106. Date: Tue, 7 Jul 92 17:11:44 -0700
  107. From: Paul Kunz <pfkeb@KAON.SLAC.Stanford.EDU>
  108. Subject: Power operator for C++
  109.  
  110.    I asked Bill Atwood about what happen to **2 type constructs in
  111. Gismo.   He looked puzzled.   He agrees that in the FORTRAN programs
  112. the code is littered with **2, but he's not sure what happened to
  113. such constructs in the Gismo C++ code.   Perhaps they have disappeared
  114. into member functions of some base or low level classes so they are
  115. not so visible anymore.   We don't know.
  116.