[net.bugs] Bug in BC Math library

malcolm (06/29/82)

#N:pur-ee:3200001:000:1374
pur-ee!malcolm    Jun 28 22:46:00 1982

There seems to be a bug in the arctangent function supplied with bc.
I have checked several systems and can't pin down which systems have
this problem.  So far I have found both V7 and 4BSD systems with this 
problem.  

The problem is that there is an if test at the start of the arctangent
code that checks for an arguement of 1.  It then always returns a value
of 45 degrees.  The offending code segement in /usr/lib/lib.b is shown
below:

	define a(x){
		auto a, b, c, d, e, f, g, s, t
		if(x==0) return(0)
****		if(x==1)
****			if(scale<52)
****				return(.7853981633974483096156608458198757210492923498437764/1)
		t = scale
		f=1
		while(x > .5){
			scale = scale + 1
		......and so on

There are two solutions to the problem.  I am not sure which is better (or
even why the supplied code fails.)  You can either remove the three lines
(which is how V6 supplied the code.)  Or you can add '{}'s and do it right.
		if(x==1){
			if(scale<52){
				return(.7853981633974483096156608458198757210492923498437764/1)
			}
		}

As long as I have your attention....Has anybody written a better program
to use as a desk calculator?  Right now I don't have the time to reinvent
the wheel.

Thanks.

						Malcolm Slaney
						Purdue EE Dept.
						decvax!pur-ee!malcolm
						ihnss!pur-ee!malcolm
						ucbvax!pur-ee!malcolm
						harpo!pur-ee!malcolm
						gsp86!intelqa!malcolm

rhm (06/29/82)

The second of Slaneys suggested fixes is the correct one and is the way
it left my hands.  I do not know how it got changed in the distributed
version.