home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3246 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.8 KB  |  90 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!pacific.mps.ohio-state.edu!davis
  3. From: davis@pacific.mps.ohio-state.edu ("John E. Davis")
  4. Subject: Re: Small Language Wanted
  5. In-Reply-To: fjh@munta.cs.mu.OZ.AU's message of Thu, 27 Aug 1992 21:41:04 GMT
  6. Message-ID: <DAVIS.92Aug27211418@pacific.mps.ohio-state.edu>
  7. Sender: news@pacific.mps.ohio-state.edu
  8. Nntp-Posting-Host: pacific.mps.ohio-state.edu
  9. Reply-To: davis@pacific.mps.ohio-state.edu  (John E. Davis)
  10. Organization: "Dept. of Physics, The Ohio State University"
  11. References: <DAVIS.92Aug23010605@pacific.mps.ohio-state.edu>
  12.     <H.3lvmyc56w&A@lionbbs.bs.open.de>
  13.     <1992Aug27.181926.5677@alchemy.chem.utoronto.ca>
  14.     <9224107.5975@mulga.cs.mu.OZ.AU>
  15. Date: Fri, 28 Aug 1992 02:14:18 GMT
  16. Lines: 72
  17.  
  18. In article <9224107.5975@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  19.    [...]
  20.    Well, you are wrong.
  21.    [...]
  22.    Furthermore, when it sees
  23.  
  24.            pow(a,i)
  25.  
  26.    in your code, and "i" happens to be an integer then it can emit code to
  27.            - call the standard pow() function after convertin
  28.              i to a double
  29.            - call a special function the calculates doubles to
  30.              integer powers
  31.            - calculate the exponentiation using inline code.
  32.    Ie. it can make EXACTLY the same optimizations that Fortran compilers
  33.    make when they see a**i.
  34.    In other words, the _ONLY_ differences between an operator and a function are
  35.            (1) the syntax is different
  36.            (2) for the function, you should include the appropriate header file
  37.                before using it.
  38.    [...]
  39.    Any function that is part of the standard library is a "built-in" function.
  40.  
  41.  
  42. Hmm... don't bet on it.  Let's see:
  43.  
  44. /* t.c --- A small program which demonstrates one reason why Fortran is better
  45.    than C for numerical work.  It also shows that the above poster is wrong.
  46.  
  47.     To build:  save this file with the name t.c.  Then issue the shell
  48.     command:
  49.  
  50.             %  cc t.c -lm
  51.  
  52.     Note that -lm is passed to the linker for linking with the math library. */
  53.        
  54. #include <stdio.h>
  55. #include <math.h>  
  56.  
  57. int main()
  58. {
  59.     int i;
  60.     float x, y;
  61.  
  62.     x = 2.0;
  63.     i = 4;
  64.  
  65.     /* i and x should be cast to double for this to work properly */
  66.     y = pow(x, i);
  67.  
  68.     (void) fprintf(stdout, "%f = pow(%f, %d)\n", y, x, i);
  69.     return(0);
  70. }
  71.    
  72. [8:52pm] /net/pacific/4/davis>cc t.c -lm
  73. [pacific]
  74. [8:52pm] /net/pacific/4/davis>./a.out
  75. 1.000000 = pow(2.000000, 4)
  76.  
  77.  
  78. This was compiled on a sun sparc station.
  79.  
  80. Also note that all the comments and documentation in the world couldn't have
  81. saved this program.
  82. --
  83.      _____________
  84. #___/John E. Davis\_________________________________________________________
  85. #
  86. # internet: davis@amy.tch.harvard.edu
  87. #   bitnet: davis@ohstpy
  88. #   office: 617-735-6746
  89. #
  90.