home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e067 / 1.ddi / SUPPORT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-10-07  |  2.2 KB  |  77 lines

  1. function ModestWholeNumber (X: real): boolean;
  2.   {Returns true iff X is a whole number in the range -maxint .. maxint.}
  3. begin
  4.   if abs (X) < maxint then ModestWholeNumber := X = trunc (X)
  5.   else ModestWholeNumber := false
  6. end;
  7.  
  8. function IntPow (Base: real;  NonNegInt: integer): real;
  9.   {Returns Base raised to the nonnegative integer power NonNegInt.}
  10. begin
  11.   if NonNegInt = 0 then IntPow := 1
  12.   else if odd (NonNegInt) then IntPow := Base * IntPow (Base, NonNegInt - 1)
  13.   else IntPow := sqr (IntPow (Base, NonNegInt div 2));
  14. end;
  15.  
  16. function POW (Base, Exponent: real): real;
  17.   {Returns Base raised to the Exponent power.
  18.    Prerequisite files: EvenReal.lib, IntPow.lib,}
  19. begin
  20.   if Exponent < 0.0 then POW := 1.0 / POW (Base, -Exponent)
  21.   else if (Base = 1.0) or (Exponent = 0.0) then POW := 1.0
  22.     {:assuming POW (0.0, 0.0) = 1.0}
  23.   else if Base = 0.0 then POW := 0.0
  24.   else if ModestWholeNumber (Exponent) then
  25.          POW := IntPow (Base, trunc (Exponent))
  26.   else POW := exp (Exponent * ln (Base));
  27. end;
  28.  
  29. function ASIN (ratio: real): real;
  30.   {Returns the principal inverse sine in radians.}
  31. begin
  32.   ASIN := arctan (ratio / sqrt ((1.0 - ratio) * (1.0 + ratio)));
  33. end;
  34.  
  35. function ACOS (ratio: real): real;
  36.   {Returns the principal inverse cosine in radians.}
  37. begin
  38.   ACOS := arctan (sqrt ((1.0 - ratio) * (1.0 + ratio)) / ratio);
  39. end;
  40.  
  41. function ATAN (ratio: real): real;
  42.   {Returns the principal arctangent of ratio in radians.}
  43. begin
  44.   ATAN := ARCTAN (ratio);
  45. end;
  46.  
  47. function TAN (angle: real): real;
  48.   {Returns the tangent of angle, which is measured in radians.}
  49. begin
  50.   TAN := SIN (angle) / COS (angle);
  51. end;
  52.  
  53. function COT (angle: real): real;
  54.   {Returns the cotangent of angle, which is measured in radians.}
  55. begin
  56.   COT := COS (angle) / SIN (angle);
  57. end;
  58.  
  59. function SIGN (R: real): real;
  60.   {returns -1 if R<0, 0 if R=0, or 1 if R>0.}
  61. begin
  62.   if R > 0.0 then SIGN := 1.0
  63.   else if R < 0.0 then SIGN := -1.0
  64.   else SIGN := 0.0;
  65. end;
  66.  
  67. function FACT (n: integer): real;
  68.   {Returns n! for n >= 0.  Intentionally provokes zero-divide for n<0.}
  69.   var k: integer;
  70.       ans: real;
  71. begin
  72.   ans := 1.0;
  73.   if n < 0 then FACT := ans / (n - n)
  74.   else for k := 2 to n do ans := k * ans;
  75.   FACT := ans
  76. end;
  77.