Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!abcfd20.larc.nasa.gov!tab00.larc.nasa.gov!scott From: scott@tab00.larc.nasa.gov (Scott Yelich) Newsgroups: comp.unix.shell Subject: Re: Math routines (was bourne shell query) Message-ID: Date: 2 Sep 90 18:14:26 GMT References: <26DC6447.15922@maccs.dcss.mcmaster.ca> <8446@orca.wv.tek.com> <75@iconsys> <2494@uc.msc.umn.edu> Sender: news@abcfd20.larc.nasa.gov (USENET File Owner) Organization: NASA Langley Research Center, Hampton, Va. 23665 Lines: 73 In-Reply-To: glex@uh.msc.umn.edu's message of 2 Sep 90 14:16:01 GMT >#include >int argc; char *argv[]; >while (i <= j) > printf(" %d",i++); Hmmm.. that's the STRANGEST sh program I have ever seen... It must be that CSH that I keep hearing about! :-) This next routine isn't supposed to be sophisticated... but it works-- just give it two SMALL NUMBERS. ADDITION () { NUM1="$1" NUM2="$2" shift $# while test $# -lt $NUM1 do set - x $@ done NUM1="$@" shift $# while test $# -lt $NUM2 do set - x $@ done NUM2="$@" set - $NUM1 $NUM2 TOTAL=$# } I am working on a sort of LIBRARY of SHroutines where all I have to do is include the clode ``. COUNT'' for the next... and use the code. COUNT () { test $# = 0 &&\ { echo "$0: Usage: $0 value [...]" exit 1 } ||\ { for i { set "" while : do set $* " x" echo $# if test $# = $i; then break fi done } } } Of course, ``COUNT x'' is a great counter! :-) The main problem with the two loops is the ``set " $*"'' command. This is what takes so much time when the argument list grows. -- Signature follows. [Skip now] ----------------------------------------------------------------------------- Scott D. Yelich scott@[xanth.]cs.odu.edu [128.82.8.1] After he pushed me off the cliff, he asked me, as I fell, ``Why'd you jump?'' Administrator of: Game-Design requests to ODU/UNIX/BSD/X/C/ROOT/XANTH/CS/VSVN/ -----------------------------------------------------------------------------