lol, how did it manage to work for years? (z1 - z2 * z.Round) shouldn't respect signs of z1 and z2. It turns out we often had arbitrary .Frac value in division result. Also fixes issue 613.
authorunc0rr
Thu, 18 Apr 2013 17:37:50 +0400
changeset 8919 67214340fa53
parent 8918 512753ea4b1b
child 8920 caa614af152d
lol, how did it manage to work for years? (z1 - z2 * z.Round) shouldn't respect signs of z1 and z2. It turns out we often had arbitrary .Frac value in division result. Also fixes issue #613.
hedgewars/uFloat.pas
--- a/hedgewars/uFloat.pas	Thu Apr 18 00:41:27 2013 +0400
+++ b/hedgewars/uFloat.pas	Thu Apr 18 17:37:50 2013 +0400
@@ -313,24 +313,24 @@
 end;
 
 operator / (const z1: hwFloat; z2: hwFloat) z : hwFloat; inline;
-var t: hwFloat;
+var t: QWord;
 begin
 if z2.QWordValue = 0 then inc(z2.QWordValue);
 z.isNegative:= z1.isNegative xor z2.isNegative;
 z.Round:= z1.QWordValue div z2.QWordValue;
-t:= z1 - z2 * z.Round;
+t:= z1.QWordValue - z2.QWordValue * z.Round;
 z.Frac:= 0;
 
-if t.QWordValue <> 0 then
+if t <> 0 then
     begin
-    while ((t.QWordValue and $FF00000000000000) = 0) and ((z2.QWordValue and $FF00000000000000) = 0) do
+    while ((t and $FF00000000000000) = 0) and ((z2.QWordValue and $FF00000000000000) = 0) do
         begin
-        t.QWordValue:= t.QWordValue shl 8;
+        t:= t shl 8;
         z2.QWordValue:= z2.QWordValue shl 8
         end;
         
     if z2.Round > 0 then
-        inc(z.QWordValue, t.QWordValue div z2.Round);
+        inc(z.QWordValue, t div z2.Round);
     end
 end;