Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!unido!gmdzi!woetzel From: woetzel@gmdzi.UUCP (Gerd Woetzel) Newsgroups: sci.math.symbolic,comp.bugs.4bsd,comp.bugs.sys5 Subject: Re: bug in bc and dc division and sqrt (and fix, hopefully) Message-ID: <336@gmdzi.UUCP> Date: Tue, 5-May-87 16:58:57 EDT Article-I.D.: gmdzi.336 Posted: Tue May 5 16:58:57 1987 Date-Received: Thu, 7-May-87 07:14:08 EDT References: <586@entropy.ms.washington.edu> Distribution: world Organization: GMD, Sankt Augustin, F.R.Germany Lines: 119 Xref: mnetor sci.math.symbolic:73 comp.bugs.4bsd:341 comp.bugs.sys5:114 The division errors of bc(1) are caused by the dc(1) command, which is used indirectly by bc. Here are two fixes to dc.c made by Heinrich Schueth (schue%gmdzi@unido.UUCP). The first one addresses an error in the scale computation (line 60ff), the second is a correction to the divide algorithm (line 665ff). Please send only credits to Heinrich, and no flames to me. After the following diffs you'll find a little shell script to test your implementation of bc/dc. *** dc.c.OLD Tue May 5 13:27:28 1987 --- dc.c Tue May 5 14:13:14 1987 *************** *** 60,67 binop('*'); p = pop(); sunputc(p); ! savk = sk1+sk2; ! if(savk>k && savk>sk1 && savk>sk2){ sk = sk1; if(skk && n>sk1 && n>sk2){ sk = sk1; if(sk= 0)divd->wt--; } if(divcarry != 0){ salterc(p,dig-1); --- 655,668 ----- sbackc(p); salterc(p,dig); sbackc(p); ! if(--offset >= 0){ ! if(d > 0){ ! sbackc(divd); ! dd=sbackc(divd); ! salterc(divd,dd+100); ! } ! divd->wt--; ! } } if(divcarry != 0){ salterc(p,dig-1); ----------------- Test script --- Cut here ------------------- # Error in division. Found by schue%gmdzi@unido.UUCP (Heinrich Schueth) # Fixed in dc.c line 665ff (see diffs above)" echo "Test 1 (division): Result of expression is" bc <