* as/hc08/lkaomf51.c (OutputName),
[fw/sdcc] / support / regression / tests / simplefloat.c
index c5dc5f25d0d46cec8066765890f0133aee031f2d..49ae5101f5a660ebaf40782e786ca479814e6aeb 100644 (file)
@@ -1,6 +1,17 @@
 /** Simple set of tests for floating pt.
  */
 #include <testfwk.h>
+#include <math.h>
+
+#if (PORT_HOST)
+#  define FCOMP(a,b) (fabsf((a) - (b)) < ((b) * 1e-7))
+#else
+   /* Testing floats for equality is normally a bug,
+      but too keep this test simple we dare it. And
+      it works with the exception of the division on
+      the host port. */
+#  define FCOMP(a,b) ((a) == (b))
+#endif
 
 void
 testCmp(void)
@@ -19,8 +30,7 @@ testCmp(void)
 void
 testDiv(void)
 {
-#if !PORT_HOST
-#if defined __mcs51 && !defined (SDCC_STACK_AUTO)
+#if defined (__mcs51) && !defined (SDCC_STACK_AUTO)
   idata at 0xd0
 #endif
   volatile float left;
@@ -29,12 +39,11 @@ testDiv(void)
   left = 17;
   right = 343;
 
-  ASSERT(left/right == (17.0/343.0));
-  ASSERT(right/left == (343.0/17.0));
+  ASSERT(FCOMP(left/right, (17.0/343.0)));
+  ASSERT(FCOMP(right/left, (343.0/17.0)));
 
   right = 17;
-  ASSERT(left/right == 1.0);
-#endif
+  ASSERT(FCOMP(left/right, 1.0));
 }
 
 void