Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!att!cbnewsl!stewart From: stewart@cbnewsl.att.com (richard.a.stewart) Newsgroups: comp.unix.shell Subject: Re: Math routines (was bourne shell query) Summary: usa Keywords: Use C Message-ID: <1990Sep3.223654.24139@cbnewsl.att.com> Date: 3 Sep 90 22:36:54 GMT References: <26DC6447.15922@maccs.dcss.mcmaster.ca> <8446@orca.wv.tek.com> <2494@uc.msc.umn.edu> Distribution: usa Organization: AT&T Bell Laboratories Lines: 24 In article <2494@uc.msc.umn.edu>, glex@uh.msc.umn.edu (Jeffrey Gleixner) writes: > > In article 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)