{$N+,A+,G+,F+,D-,E-,L-,R-,S-,Q-,Y-,I-}
unit math2;

interface

function Shl_(A: LongInt; B: Byte): LongInt;
function Sar_(A: LongInt; B: Byte): LongInt;
function sqrt_(x:single):single;
function rsqrt_(x:single):single;
function sin_(x:single):single;
function cos_(x:single):single;
function rad(i:single):single;



implementation

function Shl_(A: LongInt; B: Byte): LongInt; assembler;
asm
  mov     cl,[B]
  db      $66; mov     ax, word ptr [A]
  db      $66; shl     ax, cl
  db      $66; push    ax
  pop     ax
  pop     dx
end;

function Sar_(A: LongInt; B: Byte): LongInt; assembler;
asm
  mov     cl,[B]
  db      $66; mov     ax, word ptr [A]
  db      $66; sar     ax, cl
  db      $66; push    ax
  pop     ax
  pop     dx
end;

function sqrt_(x:single):single;
var s:single;
begin
asm
finit
fld dword ptr x
db $d9,$fa {fsqrt}
fstp dword ptr s
end;
sqrt_:=s;
end;

function rsqrt_(x:single):single;
var s:single;
begin
asm
finit
fld1
fld dword ptr x
db $d9,$fa {fsqrt}
fdivp st(1), st(0)
fstp dword ptr s
end;
rsqrt_:=s;
end;

function sin_(x:single):single; assembler;
asm
finit
fld x
db $d9,$fe {fsin}
end;

function cos_(x:single):single; assembler;
asm
finit
fld x
db $d9,$ff {fcos}
end;


function rad(i:single):single;
begin
rad:=i*0.00872664625;
end;




end.