Francois Gouget : oleaut32/tests: Fix the EQ_DOUBLE() and EQ_FLOAT() macros so they work no matter how large the values to compare are.

Alexandre Julliard julliard at wine.codeweavers.com
Thu May 31 08:33:43 CDT 2007


Module: wine
Branch: master
Commit: fbb892c604c3dfcf92c6946a2b9b8730333ca3fc
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=fbb892c604c3dfcf92c6946a2b9b8730333ca3fc

Author: Francois Gouget <fgouget at free.fr>
Date:   Thu May 31 14:02:19 2007 +0200

oleaut32/tests: Fix the EQ_DOUBLE() and EQ_FLOAT() macros so they work no matter how large the values to compare are.

Use them everywhere.

---

 dlls/oleaut32/tests/vartest.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/dlls/oleaut32/tests/vartest.c b/dlls/oleaut32/tests/vartest.c
index f7c2b04..d75b4fa 100644
--- a/dlls/oleaut32/tests/vartest.c
+++ b/dlls/oleaut32/tests/vartest.c
@@ -66,8 +66,8 @@ static INT (WINAPI *pVariantTimeToDosDateTime)(double,USHORT*,USHORT *);
 /* When comparing floating point values we cannot expect an exact match
  * because the rounding errors depend on the exact algorithm.
  */
-#define EQ_DOUBLE(a,b)     (fabs((a)-(b))<1e-14)
-#define EQ_FLOAT(a,b)      (fabs((a)-(b))<1e-7)
+#define EQ_DOUBLE(a,b)     (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-14)
+#define EQ_FLOAT(a,b)      (fabs((a)-(b)) / (1.0+fabs(a)+fabs(b)) < 1e-7)
 
 #define SKIPTESTS(a)  if((a > VT_CLSID+10) && (a < VT_BSTR_BLOB-10)) continue
 
@@ -1627,7 +1627,7 @@ static void test_DateFromUDate( int line, WORD d, WORD m, WORD y, WORD h, WORD m
     ud.st.wDayOfWeek = dw;
     ud.wDayOfYear = dy;
     res = pVarDateFromUdate(&ud, flags, &out);
-    ok_(__FILE__,line)(r == res && (FAILED(r) || fabs(out-dt) < 1.0e-11),
+    ok_(__FILE__,line)(r == res && (FAILED(r) || EQ_DOUBLE(out, dt)),
                        "expected %x, %.16g, got %x, %.16g\n", r, dt, res, out);
 }
 #define UD2T(d,m,y,h,mn,s,ms,dw,dy,flags,r,dt) test_DateFromUDate(__LINE__,d,m,y,h,mn,s,ms,dw,dy,flags,r,dt)
@@ -1654,7 +1654,7 @@ static void test_VarDateFromUdate(void)
   st.wYear = y; st.wMonth = m; st.wDay = d; st.wHour = h; st.wMinute = mn; \
   st.wSecond = s; st.wMilliseconds = ms; st.wDayOfWeek = 0; \
   res = pSystemTimeToVariantTime(&st, &out); \
-  ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
+  ok(r == res && (!r || EQ_DOUBLE(out, dt)),        \
      "expected %d, %.16g, got %d, %.16g\n", r, dt, res, out)
 
 static void test_SystemTimeToVariantTime(void)
@@ -1699,7 +1699,7 @@ static const char *szDosDateToVarTimeFail = "expected %d, %.16g, got %d, %.16g\n
   dosDate = MKDOSDATE(d,m,y); \
   dosTime = MKDOSTIME(h,mn,s); \
   res = pDosDateTimeToVariantTime(dosDate, dosTime, &out); \
-  ok(r == res && (!r || fabs(out-dt) < 1.0e-11), \
+  ok(r == res && (!r || EQ_DOUBLE(out, dt)),   \
      szDosDateToVarTimeFail, r, dt, res, out)
 
 static void test_DosDateTimeToVariantTime(void)




More information about the wine-cvs mailing list