hedgewars/uFloat.pas
changeset 953 237fc147950c
parent 916 1d0022336fbb
child 967 8be3938d73c2
equal deleted inserted replaced
952:9dd48265e0b9 953:237fc147950c
   277 
   277 
   278 function hwSqr(const t: hwFloat): hwFloat;
   278 function hwSqr(const t: hwFloat): hwFloat;
   279 begin
   279 begin
   280 hwSqr.isNegative:=false;
   280 hwSqr.isNegative:=false;
   281 hwSqr.QWordValue:= QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
   281 hwSqr.QWordValue:= QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
   282 hwSqr.Round:= hwSqr.Round + QWord(t.Round) * t.Round
   282 hwSqr.Round:= hwSqr.Round + t.Round * t.Round
   283 end;
   283 end;
   284 
   284 
   285 function hwSqrt(const t: hwFloat): hwFloat;
   285 function hwSqrt(const t: hwFloat): hwFloat;
   286 var l, r: QWord;
   286 var l, r: QWord;
   287     c: hwFloat;
   287     c: hwFloat;
   293    l:= t.QWordValue;
   293    l:= t.QWordValue;
   294    r:= $100000000
   294    r:= $100000000
   295    end else
   295    end else
   296    begin
   296    begin
   297    l:= $100000000;
   297    l:= $100000000;
   298    r:= t.QWordValue div 2 + $80000000 // r:= t / 2 + 0.5 
   298    r:= t.QWordValue div 2 + $80000000; // r:= t / 2 + 0.5
       
   299    if r > $FFFFFFFFFFFF then r:= $FFFFFFFFFFFF
   299    end;
   300    end;
   300 
   301 
   301 repeat
   302 repeat
   302   c.QWordValue:= (l + r) div 2;
   303   c.QWordValue:= (l + r) div 2;
   303   if hwSqr(c).QWordValue > t.QWordValue then r:= c.QWordValue else l:= c.QWordValue
   304   if hwSqr(c).QWordValue > t.QWordValue then r:= c.QWordValue else l:= c.QWordValue