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; |