ESBLog2 Function
Returns Logarithm of X to Base 2.

Unit
QESBPCSMath

Declaration
Function ESBLog2(const X: Extended): Extended;

Parameters
Value to process.

Category
Arithmetic Routines for Floats

Implementation

function ESBLog2 (const X: Extended): Extended;

function FLog2 (X: Extended): Extended;
     asm
		fld1				// St(0) <- 1
		fld		[X]		// St(0) <- X, St(1) <-1
		fyl2x			// St(0) <- 1 * Log2 (X)
		fwait

     end;

     function AltFLog2 (X: Extended): Extended;
     asm
		fld1				// St(0) <- 1
		fld		[X]		// St(0) <- X, St(1) <-1
		fyl2xp1			// St(0) <- 1 * Log2 (X+1)
		fwait

     end;
begin
     if not FloatIsPositive (X) then // must be Positive
          raise EMathError.Create (rsValueGZero)
     else if abs (X - 1) < 0.1 then
          Result := AltFLog2 (X - 1)
     else
          Result := FLog2 (X);
End;


HTML generated by Time2HELP
http://www.time2help.com