Math routines (was bourne shell query)

Jeffrey Gleixner glex at uh.msc.umn.edu
Mon Sep 3 00:16:01 AEST 1990


In article <75 at iconsys>, mday at iconsys (Matt Day) writes:
> In article <SCOTT.90Aug30124930 at tab00.larc.nasa.gov>
scott at 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 <stdio.h>
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 at msc.umn.edu  ===  " I don't go out with girls that say bitch'n " ===



More information about the Comp.unix.shell mailing list