Path: utzoo!utgpu!watserv1!watmath!att!rutgers!ub.d.umn.edu!cs.umn.edu!uc!uh.msc.umn.edu!glex From: glex@uh.msc.umn.edu (Jeffrey Gleixner) Newsgroups: comp.unix.shell Subject: Math routines (was bourne shell query) Keywords: Use C Message-ID: <2494@uc.msc.umn.edu> Date: 2 Sep 90 14:16:01 GMT References: <26DC6447.15922@maccs.dcss.mcmaster.ca> <8446@orca.wv.tek.com> <75@iconsys> Sender: news@uc.msc.umn.edu Reply-To: glex@uh.msc.umn.edu (Jeffrey Gleixner) Organization: Minnesota Supercomputer Center Lines: 38 In article <75@iconsys>, mday@iconsys (Matt Day) writes: > In article scott@tab00.larc.nasa.gov (Scott Yelich) writes: > >As a side question, does ANYONE have any bourne shell routines which do > >math... reasonably effeciently? (For numbers > 1000?) > > For the Bourne shell, the most efficient way to do math is to use the "expr" > ... If you have a shell script that needs to do > a lot of math, I suggest you use the C shell built in math operators; it's If you're going to do a lot of math write a {your favorite language besides *sh here} program to do the math for you. Even if you're doing a small amount of math it will really speed it up. i.e. #!/bin/sh count 1 6 | while read value ; do some commands... done ========= /* * Count.c * * print succesive numbers from start to end. * Used in scripts instead of `expr $i +1` */ #include main(argc,argv) int argc; char *argv[]; { register int i,j; i=atoi(argv[1]); j=atoi(argv[2]); while (i <= j) printf(" %d",i++); } -- glex@msc.umn.edu === " I don't go out with girls that say bitch'n " ===