home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-13 | 2.2 KB | 86 lines | [TEXT/PJMM] |
- (**********************************************************************************)
- (* Unit to perform math functions when no coprocessor is available. *)
- (* Last modified: 1995-11-12 *)
- (* *)
- (* send comments & suggestions to: *)
- (* Daniel W. Rickey *)
- (* Department of Medical Physics *)
- (* Manitoba Cancer Treatment and Research Foundation *)
- (* 100 Olivia Street *)
- (* Winnipeg, Manitoba *)
- (* R3E 0V9 CANADA *)
- (* daniel@kaon.mctrf.mb.ca or physics@escape.ca *)
- (**********************************************************************************)
- Unit NoCoprocessorMath;
-
- Interface
- (* performs arcsine *)
- Function aSin (x: double): double;
-
- (* performs arccosine *)
- Function aCos (x: double): double;
-
- (* two to the power of X *)
- Function Exp2 (x: double): double;
-
- Implementation
- Const
- Pi = 3.141592654;
-
-
- (**** two to the power of X ****)
- Function Exp2 (x: double): Double;
- Const
- kln2 = 0.69314718;
-
- Begin
- Exp2 := Exp(kln2 * x);
- End; {Exp2}
-
-
- (**** performs arccosine ****)
- Function aCos (x: double): double;
- Begin
- {do a range check in case x = ±1.0000001}
- If x > 1 Then
- aCos := 0
- Else If x < -1 Then
- aCos := Pi
- Else
- aCos := (2 * ArcTan(SQRT((1 - x) / (1 + x))));
- End; {aCos}
-
-
- (**** performs arcsine ****)
- Function aSin (x: double): double;
- Var
- y: Double;
-
- Begin
- {do a range check in case x = ±1.0000001}
- If x > 1.0 Then
- Begin
- aSin := Pi / 2;
- Exit(aSin);
- End
- Else If x < -1.0 Then
- Begin
- aSin := -Pi / 2;
- Exit(aSin);
- End;
-
- y := Abs(x);
-
- If (y > 0.5) Then
- Begin
- y := 1 - y;
- y := 2 * y - y * y;
- End
- Else
- Begin
- y := 1 - y * y;
- End;
- aSin := (ArcTan(x / SQRT(y)));
- End; {aSin}
-
- End.