{MATH FUNCTION LIBRARY FOR PASCAL; (C) 1981 BY FICOMP, INC. FAIRFAX, VA.}

MODULE MATHLIB;

CONST DRCON = 1.74533E-02;
      HALFPI = 1.5708;
      LOGCON = 2.30259;

{TRIG FUNCTIONS}

FUNCTION RAD(X:REAL): REAL;
{CONVERTS DEGREES TO RADIANS}
BEGIN
  RAD := X*DRCON;
END;

FUNCTION DEG(X:REAL): REAL;
{CONVERTS RADIANS TO DEGREES}
BEGIN
  DEG := X/DRCON;
END;

FUNCTION TAN(X:REAL): REAL;
{TANGENT FUNCTION}
BEGIN
  TAN := SIN(X)/COS(X);
END;

FUNCTION COT(X:REAL): REAL;
{COTANGENT FUNCTION}
BEGIN
  COT := COS(X)/SIN(X);
END;

FUNCTION ASIN(X:REAL): REAL;
{ARCSIN FUNCTION}
BEGIN
  ASIN := ARCTAN(X/SQRT(-X*X+1.0));
END;

FUNCTION ACOS(X:REAL): REAL;
{ARCOSINE FUNCTION}
BEGIN
  ACOS := -ARCTAN(X/SQRT(-X*X+1.0))+HALFPI;
END;

FUNCTION ACOT(X:REAL): REAL;
{ARCOTANGENT FUNCTION}
BEGIN
  ACOT := ARCTAN(X)+HALFPI;
END;

{COMMON LOG FUNCTIONS}

FUNCTION LOG10(X:REAL): REAL;
{LOG (BASE 10) FUNCTION}
BEGIN
  IF X<=0 THEN
    LOG10 := 0.0
  ELSE
    LOG10 := LN(X)/LOGCON;
END;

FUNCTION ALOG10(X:REAL): REAL;
{ANTILOG (BASE 10) FUNCTION}
BEGIN
  ALOG10 := EXP(X*LOGCON);
END;

{POWER FUNCTIONS}

FUNCTION POWER(X:REAL;N:INTEGER): REAL;
{COMPUTES REAL X RAISED TO INTEGER POWER N RECURSIVELY}
BEGIN
  IF X=0.0 THEN
    POWER := 0.0
  ELSE
    IF N=0 THEN
      POWER := 1.0
  ELSE
    IF N<0 THEN
      POWER := POWER(X,N+1)/X
  ELSE
    POWER := POWER(X,N-1)*X;
END;

FUNCTION ROOT(X:REAL;N:INTEGER): REAL;
{COMPUTES INTEGER ROOT N OF REAL X}
BEGIN
  IF (X=0.0) OR (N=0) THEN
    ROOT := 0.0
  ELSE
    IF (NOT ODD(N)) AND (X<0) THEN
      ROOT := 0.0
  ELSE
    IF N=1 THEN
      ROOT := X
  ELSE
    IF X>0 THEN
      ROOT := EXP(LN(X)/N)
  ELSE
    ROOT := -EXP(LN(ABS(X))/N);
END;

FUNCTION RPOWER(X,N:REAL): REAL;
{COMPUTES REAL X RAISED TO REAL POWER N}
BEGIN
  IF (X<=0.0) OR (N=0.0) THEN
    RPOWER := 0.0
  ELSE
    RPOWER := EXP(LN(X)*N);
END;

MODEND.
 REAL POWER N}
BEGIN
  IF (X<=0.0) OR (N=0.0) THEN
    RPOWER := 0.