PASCAL MACRO COMPILER
Miscellaneous Pascal Macros



       The following Pascal macros generate various useful Pascal language expressions. Because these are macros the generated code is faster and more efficient than calling a function or procedure for the same task.

Power	 Raise a number to a power.
IPower	 Raise a number to an integer power.


       The macro prologues give the details of how to use each macro.


  {The Power macro function generates the Pascal}
  {code for raising a number to a given power.	}
  {That is, it generates a Pascal expression to }
  {calculate  base^exponent  where the base and }
  {exponent may be any integer or real Pascal	}
  {expressions. 				}
  {						}
  {Example:  Power (x+2.4,0.177)  generates	}
  {	     exp(ln(x+2.4)*(0.177))		}
%Function  Power (base, exponent: code): code;
%Begin	{Power}
%Power:=exp(ln(base)*(exponent))%;
%End;  {Power}


  {The IPower macro function generates the Pascal}
  {code for raising a number to an integer power.}
  {That is, it generates a Pascal expression to  }
  {calculate  base^exponent  where base may be	 }
  {any integer or real Pascal expression, and the}
  {exponent is an integer Macro expression.	 }
  {   For small exponents, using IPower produces }
  {faster code than using Power.		 }
  {						 }
  {Example:  IPower (x+2.4, 3)	generates	 }
  {	     (x+2.4)*(x+2.4)*(x+2.4)		 }
%Function  IPower (base:code; exponent:integer): code;
%Begin	{IPower}
%if  exponent < 0
     then  %IPower :=1.0/(IPower(base,-exponent))%;
%if  exponent = 0
     then  %IPower :=1%;
%if  exponent = 1
     then  %IPower :=(base)%;
%if  exponent > 1
     then  %IPower :=(base)*IPower(base,exponent-1)%;
%End;  {IPower}


© Copyright 2005 Frank Rubin