hedgewars/uFloat.pas
changeset 10114 68a72af636c3
parent 10108 c68cf030eded
child 10562 3388822b3914
equal deleted inserted replaced
10112:275ad81e4718 10114:68a72af636c3
    82 
    82 
    83 function cstr(const z: hwFloat): shortstring; // Returns a shortstring representations of the hwFloat.
    83 function cstr(const z: hwFloat): shortstring; // Returns a shortstring representations of the hwFloat.
    84 function hwRound(const t: hwFloat): LongInt; inline; // Does NOT really round but returns the integer representation of the hwFloat without fractional digits. (-_0_9 -> -0, _1_5 -> _1)
    84 function hwRound(const t: hwFloat): LongInt; inline; // Does NOT really round but returns the integer representation of the hwFloat without fractional digits. (-_0_9 -> -0, _1_5 -> _1)
    85 function hwAbs(const t: hwFloat): hwFloat; inline; // Returns the value of t with positive sign.
    85 function hwAbs(const t: hwFloat): hwFloat; inline; // Returns the value of t with positive sign.
    86 function hwSqr(const t: hwFloat): hwFloat; inline; // Returns the square value of parameter t.
    86 function hwSqr(const t: hwFloat): hwFloat; inline; // Returns the square value of parameter t.
    87 function hwPow(const t: hwFloat; p: LongWord): hwFloat; inline; // Returns the power of the value
       
    88 function hwSqrt1(const t: hwFloat): hwFloat; inline; // Returns the the positive square root of parameter t.
    87 function hwSqrt1(const t: hwFloat): hwFloat; inline; // Returns the the positive square root of parameter t.
    89 function hwSqrt(const x: hwFloat): hwFloat; inline; // Returns the the positive square root of parameter t.
    88 function hwSqrt(const x: hwFloat): hwFloat; inline; // Returns the the positive square root of parameter t.
    90 function Distance(const dx, dy: hwFloat): hwFloat; // Returns the distance between two points in 2-dimensional space, of which the parameters are the horizontal and vertical distance.
    89 function Distance(const dx, dy: hwFloat): hwFloat; // Returns the distance between two points in 2-dimensional space, of which the parameters are the horizontal and vertical distance.
    91 function DistanceI(const dx, dy: LongInt): hwFloat; // Same as above for integer parameters.
    90 function DistanceI(const dx, dy: LongInt): hwFloat; // Same as above for integer parameters.
    92 function AngleSin(const Angle: Longword): hwFloat;
    91 function AngleSin(const Angle: Longword): hwFloat;
   367 begin
   366 begin
   368     hwSqr.isNegative:= false;
   367     hwSqr.isNegative:= false;
   369     hwSqr.QWordValue:= ((QWord(t.Round) * t.Round) shl 32) + QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
   368     hwSqr.QWordValue:= ((QWord(t.Round) * t.Round) shl 32) + QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
   370 end;
   369 end;
   371 
   370 
   372 function hwPow(const t: hwFloat;p: LongWord): hwFloat;
       
   373 begin
       
   374     hwPow:= t;
       
   375     if p mod 2 = 0 then hwPow.isNegative:= false;
       
   376 
       
   377     while p > 0 do
       
   378         begin
       
   379         hwPow.QWordValue:= QWord(hwPow.Round) * t.Frac + QWord(hwPow.Frac) * t.Round + ((QWord(hwPow.Frac) * t.Frac) shr 32);
       
   380         dec(p)
       
   381         end
       
   382 end;
       
   383 
       
   384 function hwSqrt1(const t: hwFloat): hwFloat;
   371 function hwSqrt1(const t: hwFloat): hwFloat;
   385 const pwr = 8; // even value, feel free to adjust
   372 const pwr = 8; // even value, feel free to adjust
   386       rThreshold = 1 shl (pwr + 32);
   373       rThreshold = 1 shl (pwr + 32);
   387       lThreshold = 1 shl (pwr div 2 + 32);
   374       lThreshold = 1 shl (pwr div 2 + 32);
   388 var l, r: QWord;
   375 var l, r: QWord;