home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!usc!zaphod.mps.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: fjh@munta.cs.mu.OZ.AU's message of Thu, 27 Aug 1992 21:41:04 GMT
- Message-ID: <DAVIS.92Aug27211418@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>
- Date: Fri, 28 Aug 1992 02:14:18 GMT
- Lines: 72
-
- In article <9224107.5975@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- [...]
- Well, you are wrong.
- [...]
- Furthermore, when it sees
-
- 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.
- 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.
- [...]
- Any function that is part of the standard library is a "built-in" function.
-
-
- Hmm... don't bet on it. Let's see:
-
- /* t.c --- A small program which demonstrates one reason why Fortran is better
- than C for numerical work. It also shows that the above poster is wrong.
-
- To build: save this file with the name t.c. Then issue the shell
- command:
-
- % cc t.c -lm
-
- Note that -lm is passed to the linker for linking with the math library. */
-
- #include <stdio.h>
- #include <math.h>
-
- int main()
- {
- int i;
- float x, y;
-
- x = 2.0;
- i = 4;
-
- /* i and x should be cast to double for this to work properly */
- y = pow(x, i);
-
- (void) fprintf(stdout, "%f = pow(%f, %d)\n", y, x, i);
- return(0);
- }
-
- [8:52pm] /net/pacific/4/davis>cc t.c -lm
- [pacific]
- [8:52pm] /net/pacific/4/davis>./a.out
- 1.000000 = pow(2.000000, 4)
-
-
- This was compiled on a sun sparc station.
-
- Also note that all the comments and documentation in the world couldn't have
- saved this program.
- --
- _____________
- #___/John E. Davis\_________________________________________________________
- #
- # internet: davis@amy.tch.harvard.edu
- # bitnet: davis@ohstpy
- # office: 617-735-6746
- #
-