hedgewars/uFloat.pas
changeset 6415 af2047bb4f70
parent 6328 d14adf1c7721
child 6443 23364a5fcc86
equal deleted inserted replaced
6414:8474b7fa84d6 6415:af2047bb4f70
    60 function int2hwFloat (const i: LongInt) : hwFloat; inline;
    60 function int2hwFloat (const i: LongInt) : hwFloat; inline;
    61 function hwFloat2Float (const i: hwFloat) : extended; inline;
    61 function hwFloat2Float (const i: hwFloat) : extended; inline;
    62 
    62 
    63 // The implemented operators
    63 // The implemented operators
    64 
    64 
       
    65 operator = (const z1, z2: hwFloat) z : boolean; inline;
    65 operator + (const z1, z2: hwFloat) z : hwFloat; inline;
    66 operator + (const z1, z2: hwFloat) z : hwFloat; inline;
    66 operator - (const z1, z2: hwFloat) z : hwFloat; inline;
    67 operator - (const z1, z2: hwFloat) z : hwFloat; inline;
    67 operator - (const z1: hwFloat) z : hwFloat; inline;
    68 operator - (const z1: hwFloat) z : hwFloat; inline;
    68 
    69 
    69 operator * (const z1, z2: hwFloat) z : hwFloat; inline;
    70 operator * (const z1, z2: hwFloat) z : hwFloat; inline;
    86 function DistanceI(const dx, dy: LongInt): hwFloat; // Same as above for integer parameters.
    87 function DistanceI(const dx, dy: LongInt): hwFloat; // Same as above for integer parameters.
    87 function AngleSin(const Angle: Longword): hwFloat;
    88 function AngleSin(const Angle: Longword): hwFloat;
    88 function AngleCos(const Angle: Longword): hwFloat;
    89 function AngleCos(const Angle: Longword): hwFloat;
    89 function SignAs(const num, signum: hwFloat): hwFloat; inline; // Returns an hwFloat with the value of parameter num and the sign of signum.
    90 function SignAs(const num, signum: hwFloat): hwFloat; inline; // Returns an hwFloat with the value of parameter num and the sign of signum.
    90 function hwSign(r: hwFloat): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
    91 function hwSign(r: hwFloat): LongInt; inline; // Returns an integer with value 1 and sign of parameter r.
    91 
    92 function isZero(const z: hwFloat): boolean; inline;
    92 {$IFDEF FPC}
    93 {$IFDEF FPC}
    93 {$J-}
    94 {$J-}
    94 {$ENDIF}
    95 {$ENDIF}
    95 {$WARNINGS OFF}
    96 {$WARNINGS OFF}
    96 
    97 
   157              _25: hwFloat = (isNegative: false; QWordValue:  4294967296 * 25);
   158              _25: hwFloat = (isNegative: false; QWordValue:  4294967296 * 25);
   158              _30: hwFloat = (isNegative: false; QWordValue:  4294967296 * 30);
   159              _30: hwFloat = (isNegative: false; QWordValue:  4294967296 * 30);
   159              _40: hwFloat = (isNegative: false; QWordValue:  4294967296 * 40);
   160              _40: hwFloat = (isNegative: false; QWordValue:  4294967296 * 40);
   160              _50: hwFloat = (isNegative: false; QWordValue:  4294967296 * 50);
   161              _50: hwFloat = (isNegative: false; QWordValue:  4294967296 * 50);
   161              _70: hwFloat = (isNegative: false; QWordValue:  4294967296 * 70);
   162              _70: hwFloat = (isNegative: false; QWordValue:  4294967296 * 70);
       
   163              _90: hwFloat = (isNegative: false; QWordValue:  4294967296 * 90);
   162             _128: hwFloat = (isNegative: false; QWordValue:  4294967296 * 128);
   164             _128: hwFloat = (isNegative: false; QWordValue:  4294967296 * 128);
       
   165             _180: hwFloat = (isNegative: false; QWordValue:  4294967296 * 180);
   163             _250: hwFloat = (isNegative: false; QWordValue:  4294967296 * 250);
   166             _250: hwFloat = (isNegative: false; QWordValue:  4294967296 * 250);
   164             _256: hwFloat = (isNegative: false; QWordValue:  4294967296 * 256);
   167             _256: hwFloat = (isNegative: false; QWordValue:  4294967296 * 256);
   165             _300: hwFloat = (isNegative: false; QWordValue:  4294967296 * 300);
   168             _300: hwFloat = (isNegative: false; QWordValue:  4294967296 * 300);
       
   169             _360: hwFloat = (isNegative: false; QWordValue:  4294967296 * 360);
   166             _450: hwFloat = (isNegative: false; QWordValue:  4294967296 * 450);
   170             _450: hwFloat = (isNegative: false; QWordValue:  4294967296 * 450);
   167            _1000: hwFloat = (isNegative: false; QWordValue:  4294967296 * 1000);
   171            _1000: hwFloat = (isNegative: false; QWordValue:  4294967296 * 1000);
   168            _1024: hwFloat = (isNegative: false; QWordValue:  4294967296 * 1024);
   172            _1024: hwFloat = (isNegative: false; QWordValue:  4294967296 * 1024);
   169            _2048: hwFloat = (isNegative: false; QWordValue:  4294967296 * 2048);
   173            _2048: hwFloat = (isNegative: false; QWordValue:  4294967296 * 2048);
   170            _4096: hwFloat = (isNegative: false; QWordValue:  4294967296 * 4096);
   174            _4096: hwFloat = (isNegative: false; QWordValue:  4294967296 * 4096);
   195 function hwFloat2Float (const i: hwFloat) : extended;
   199 function hwFloat2Float (const i: hwFloat) : extended;
   196 begin
   200 begin
   197 hwFloat2Float:= i.QWordValue / $100000000;
   201 hwFloat2Float:= i.QWordValue / $100000000;
   198 if i.isNegative then hwFloat2Float:= -hwFloat2Float;
   202 if i.isNegative then hwFloat2Float:= -hwFloat2Float;
   199 end;
   203 end;
       
   204 
       
   205 operator = (const z1, z2: hwFloat) z : boolean; inline;
       
   206 begin
       
   207     z:= (z1.isNegative = z2.isNegative) and (z1.QWordValue = z2.QWordValue);
       
   208 end;
       
   209 
   200 
   210 
   201 operator + (const z1, z2: hwFloat) z : hwFloat;
   211 operator + (const z1, z2: hwFloat) z : hwFloat;
   202 begin
   212 begin
   203 if z1.isNegative = z2.isNegative then
   213 if z1.isNegative = z2.isNegative then
   204    begin
   214    begin
   402 AngleCos.isNegative:= Angle > 1024;
   412 AngleCos.isNegative:= Angle > 1024;
   403 if Angle < 1024 then AngleCos.QWordValue:= SinTable[1024 - Angle]
   413 if Angle < 1024 then AngleCos.QWordValue:= SinTable[1024 - Angle]
   404                 else AngleCos.QWordValue:= SinTable[Angle - 1024]
   414                 else AngleCos.QWordValue:= SinTable[Angle - 1024]
   405 end;
   415 end;
   406 
   416 
       
   417 function isZero(const z: hwFloat): boolean; inline; 
       
   418 begin
       
   419     isZero := z.QWordValue = 0;
       
   420 end;
   407 {$ENDIF}
   421 {$ENDIF}
   408 
   422 
   409 end.
   423 end.