A procedure to find tan inverse in PL/SQL

From: Mahesh Vallampati <m0v5533_at_tam2000.tamu.edu>
Date: 1995/06/12
Message-ID: <3rhvrn$qr3_at_news.tamu.edu>#1/1


/*
This is a program which will calculate the tan inverse of a value and give the angle in radians. The input to the procedure taninverse is taninvx which is the value for which we have to find the angle. The output obtained is the angle which is in radians. The infinite series approximation for taninv(x) has been used to find the angle. The series has been approximated upto n terms depending on where taninvx lies. The angle returned is in the region ( 0,PI ). */
-- Procedure which will calculate the taninverse of a value and give the

  • angle in radians. /* Author : Mahesh Vallampati Department of Electrical Engineering Texas A and M University, College Station, Texas 77840. Important: The software and the program is provided as is and you are using it at your own risk. In case you find it useful, please send me an e-mail to oracle7_at_tamu.edu. If you have any corrections/suggestions please send them to the same address. */ /* This can also be used to find arcsin,arccos. The procedure is outlined as follows. Given sin(theta) where theta is the angle to be found, use the well known trignometric identity cos(theta) = sqrt(1-(sin(theta)*sin(theta))) and hence obtain tan(theta)=sin(theta)/cos(theta) and then use the procedure below to find the angle. Similarly cos(theta) where theta is the angle to be found can be done as sin(theta)=sqrt(1-(cos(theta)*cos(theta))) and hence obtain tantheta=sin(theta)/cos(theta) and then use the procedure. */ /* KNOWN BUGS For large values of taninvx the Oracle error: ORA-06502 occurs. ORA-06502 PL/SQL : numeric or value error. This error is happening becase the power function is being used. For large values of x or y in power(x,y) the value exceeds the range and hence causes error */

declare
tantheta1 real;
newtheta1 real;

  • Procedure to find taninverse begins here procedure taninverse(radian IN OUT real,taninvx IN real) IS M_PI_2 CONSTANT REAL :=1.57079632679489661923; M_PI_4 CONSTANT REAL :=0.78539816339744830962; i number(4); j number(4); k number(4); n number(4); p number(6); temp real; begin k:=1; n:=120; if taninvx = 0.0 then radian:=0.0; else if abs(taninvx) > 1 then radian:=M_PI_2; if abs(taninvx) > 11 then if abs(taninvx) < 20 then n:=60; else n:=30; end if; end if; for i in 1..n loop if mod(i,2) > 0 then temp:=power(-1,k)/(i*(power(taninvx,i))); radian:=radian+temp; k:=k+1; end if; end loop; elsif ( abs(taninvx) ) < 1 then radian:=0.0; for i in 1..n loop if mod(i,2) > 0 then temp:=power(-1,k+1)*(power(taninvx,i))/i; radian:=radian+temp; k:=k+1; end if; end loop; elsif taninvx = 1 then radian:= M_PI_4; elsif taninvx = -1 then radian:= M_PI_4 + M_PI_2 ; end if;
	if radian < 0
	then
		radian:= radian +  2*M_PI_2;
	end if;

end if;
end taninverse;
  • Procedure to find taninverse ends here

begin
tantheta1:= ; /* A value for which you want to find the tangent */ taninverse(newtheta1,tantheta1);
-- The angle is stored in newtheta1 n radians and can be used
end;
/



Thanks
Mahesh Vallampati
oracle7_at_tamu.edu
If anybody can test the procedure and comment upon it, I would appreciate it. Received on Mon Jun 12 1995 - 00:00:00 CEST

Original text of this message