home *** CD-ROM | disk | FTP | other *** search
- { A first approximation of a set of routines to do transcendental functions in
- the BCD version of Turbo Pascal. I don't know how to calculate Ln(X) or
- ArcTan(X) so those functions are missing. Sqrt is missing because the easy
- way of doing it requires Ln(X).
-
- Anyone who figures out how to do ArcTan or Ln is welcome to upload a new set
- of routines. (Or if my methods are atrocious -- no doubt).
-
- By the way, these routines should give you some idea of why the
- transcendentals were left out of the BCD compiler: they are S*L*O*W!
-
- - Bela Lubkin
- Borland International Technical Support
- CompuServe 71016,1573 }
-
- Const
- HalfPi=1.57079632679489662;
- Pi=3.14159265358979323;
- TwoPi=6.28318530717958646;
-
- Function Sin(X: Real): Real;
- Var
- XX,X2,S: Real;
- I: Integer;
- Begin
- If Abs(X)>Pi Then
- X:=X-Round(X/TwoPi)*TwoPi;
- If Abs(X)>HalfPi Then
- If X>0 Then X:=Pi-X
- Else X:=-Pi-X;
- I:=1;
- XX:=X;
- X2:=Sqr(X);
- S:=0.0;
- Repeat
- S:=S+XX;
- I:=I+2;
- XX:=-XX*X2/(I-1)/I;
- Until XX=0.0;
- Sin:=S;
- End;
-
- Function Cos(X: Real): Real;
- Begin
- Cos:=Sin(X+HalfPi);
- End;
-
- Function Exp(X: Real): Real;
- Var
- XX,S: Real;
- I: Integer;
- Begin
- XX:=1.0;
- S:=0.0;
- I:=1;
- Repeat
- S:=S+XX;
- XX:=XX*X/I;
- I:=I+1;
- Until XX=0.0;
- Exp:=S;
- End;
-
- (*
- Function Ln(X: Real): Real;
- ???
-
- Function Sqrt(X: Real): Real;
- Begin
- Sqrt:=Exp(Ln(X)/2);
- End;
-
- Function Power(Y,X: Real): Real; { Y to the X }
- Begin
- Power:=Exp(Ln(Y)*X);
- End;
-
- Function ArcTan(X: Real): Real;
- ???
- *)
-
- { Demonstration program; delete the next line to enable }
- (*
-
- Var
- X: Real;
-
- Begin
- Repeat
- ReadLn(X);
- WriteLn(Sin(X):1:20);
- WriteLn(Cos(X):1:20);
- WriteLn(Exp(X):1:20);
- Until X=0.0;
- End.
- *)