hedgewars/uFloat.pas
changeset 8921 e5db2a42e7e8
parent 8919 67214340fa53
child 8924 13ac59499066
equal deleted inserted replaced
8920:caa614af152d 8921:e5db2a42e7e8
   313 end;
   313 end;
   314 
   314 
   315 operator / (const z1: hwFloat; z2: hwFloat) z : hwFloat; inline;
   315 operator / (const z1: hwFloat; z2: hwFloat) z : hwFloat; inline;
   316 var t: QWord;
   316 var t: QWord;
   317 begin
   317 begin
   318 if z2.QWordValue = 0 then inc(z2.QWordValue);
       
   319 z.isNegative:= z1.isNegative xor z2.isNegative;
   318 z.isNegative:= z1.isNegative xor z2.isNegative;
   320 z.Round:= z1.QWordValue div z2.QWordValue;
   319 z.Round:= z1.QWordValue div z2.QWordValue;
   321 t:= z1.QWordValue - z2.QWordValue * z.Round;
   320 t:= z1.QWordValue - z2.QWordValue * z.Round;
   322 z.Frac:= 0;
   321 z.Frac:= 0;
   323 
   322 
   326     while ((t and $FF00000000000000) = 0) and ((z2.QWordValue and $FF00000000000000) = 0) do
   325     while ((t and $FF00000000000000) = 0) and ((z2.QWordValue and $FF00000000000000) = 0) do
   327         begin
   326         begin
   328         t:= t shl 8;
   327         t:= t shl 8;
   329         z2.QWordValue:= z2.QWordValue shl 8
   328         z2.QWordValue:= z2.QWordValue shl 8
   330         end;
   329         end;
   331         
   330 
   332     if z2.Round > 0 then
   331     if z2.Round > 0 then
   333         inc(z.QWordValue, t div z2.Round);
   332         inc(z.QWordValue, t div z2.Round);
   334     end
   333     end
   335 end;
   334 end;
   336 
   335 
   455 end;
   454 end;
   456 
   455 
   457 
   456 
   458 
   457 
   459 function Distance(const dx, dy: hwFloat): hwFloat;
   458 function Distance(const dx, dy: hwFloat): hwFloat;
   460 begin
   459 var r: QWord;
   461 Distance:= hwSqrt(hwSqr(dx) + hwSqr(dy))
   460 begin
       
   461 r:= dx.QWordValue or dy.QWordValue;
       
   462 
       
   463 if r < $10000 then
       
   464     begin
       
   465     Distance.QWordValue:= r;
       
   466     Distance.isNegative:= false
       
   467     end else
       
   468     Distance:= hwSqrt(hwSqr(dx) + hwSqr(dy))
   462 end;
   469 end;
   463 
   470 
   464 function DistanceI(const dx, dy: LongInt): hwFloat;
   471 function DistanceI(const dx, dy: LongInt): hwFloat;
   465 begin
   472 begin
   466 DistanceI:= hwSqrt(int2hwFloat(sqr(dx) + sqr(dy)))
   473 DistanceI:= hwSqrt(int2hwFloat(sqr(dx) + sqr(dy)))