home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!pacific.mps.ohio-state.edu!davis
- From: davis@pacific.mps.ohio-state.edu ("John E. Davis")
- Subject: Re: Small Language Wanted
- In-Reply-To: davis@pacific.mps.ohio-state.edu's message of Fri, 28 Aug 1992 02:14:18 GMT
- Message-ID: <DAVIS.92Aug28015332@pacific.mps.ohio-state.edu>
- Sender: news@pacific.mps.ohio-state.edu
- Nntp-Posting-Host: pacific.mps.ohio-state.edu
- Reply-To: davis@pacific.mps.ohio-state.edu (John E. Davis)
- Organization: "Dept. of Physics, The Ohio State University"
- References: <DAVIS.92Aug23010605@pacific.mps.ohio-state.edu>
- <H.3lvmyc56w&A@lionbbs.bs.open.de>
- <1992Aug27.181926.5677@alchemy.chem.utoronto.ca>
- <9224107.5975@mulga.cs.mu.OZ.AU>
- <DAVIS.92Aug27211418@pacific.mps.ohio-state.edu>
- Date: Fri, 28 Aug 1992 06:53:32 GMT
- Lines: 67
-
-
- In a previous article <DAVIS.92Aug27211418@pacific.mps.ohio-state.edu> I
- presented a C program which demonstrates that simply including math.h into a C
- program does not guarantee that `float y, x = 2.0; int i = 4; y = pow(x,i)'
- will produce the correct value for y as a previous poster suggested:
-
- >In other words, the _ONLY_ differences between an operator and a
- >function are
- > (1) the syntax is different
- > (2) for the function, you should include the appropriate header file
- > before using it.
-
-
- It has been pointed out to me by several people that this is compiler
- dependent and the a true ansi compliant answer will produce the correct
- answer. This is because instead of a declaration like:
-
- extern double pow(/* double, double */);
-
- the ANSI declaration would read:
-
- extern double pow(double, double);
-
-
- This has the effect of performing the correct typecasts before calling the
- function `pow'.
-
- But then this behavior contradicts something else the other poster said:
-
- >pow(a,i)
-
- >in your code, and "i" happens to be an integer then it can emit code to
- > - call the standard pow() function after convertin
- > i to a double
- > - call a special function the calculates doubles to
- > integer powers
- > - calculate the exponentiation using inline code.
- >Ie. it can make EXACTLY the same optimizations that Fortran compilers
- >make when they see a**i.
- >[...]
- >Any function that is part of the standard library is a "built-in"
- >function.
-
- This seems to imply that if I do:
-
- int i = 4; float y, x = 2.0; y = pow(x,i)
-
- The code for pow will recognize that 4.0 = (double) i is equivalent to the
- integer 4 and will generate code like:
-
- return(tmp = 2.0 * 2.0, tmp * tmp);
-
- as opposed something like
-
- return( exp ( 4.0 * log(2.0));
-
- Are there really any existing C compliers out there that perform such
- optimizations?
-
- --
- _____________
- #___/John E. Davis\_________________________________________________________
- #
- # internet: davis@amy.tch.harvard.edu
- # bitnet: davis@ohstpy
- # office: 617-735-6746
- #
-