Math routines (was bourne shell query)

richard.a.stewart stewart at cbnewsl.att.com
Tue Sep 4 08:36:54 AEST 1990


In article <2494 at uc.msc.umn.edu>, glex at uh.msc.umn.edu (Jeffrey Gleixner) writes:
> > In article <SCOTT.90Aug30124930 at tab00.larc.nasa.gov> writes:
> > >As a side question, does ANYONE have any bourne shell routines which do
> > >math... reasonably effeciently?  (For numbers > 1000?)

> 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.

Generally concur except for prior suggestion re "expr".
-----
Not my favorite language(:-) but one might also consider
a (Bourne) shell counting function using dc:

	cnt() { echo "[p1+d${2}!<0]s0${1}l0xq"|dc; }

   This counts at a rate of about 100/second (on a 3B2) which may be adequate
   for many shell programming purposes although MUCH slower than "count".
   The function saves 99.6+% in "diskspace" over a private a.out from count.c;
   "count" of course might well be shared by all users as /usr/lbin/count.
-----
   Other possibilities for consideration could include bc, awk, awkcc,
   various public domain calculators and "Hoc" (SEE Appendices 2&3 of
   "The UNIX Programming Environment" by Kernighan & Pike)



More information about the Comp.unix.shell mailing list