Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "test.h"
  5.  
  6. /* r = place to store result
  7.  * f = function call to test (or any expression)
  8.  * x = expected result
  9.  * m = message to print on failure (with formats for r & x)
  10.  */
  11.  
  12. #define TEST(r, f, x, m) ( \
  13.         ((r) = (f)) == (x) || \
  14.         (t_error("%s failed (" m ")\n", #f, r, x, r-x), 0) )
  15.  
  16. int main(void)
  17. {
  18.         int i;
  19.         double d, d2;
  20.         char buf[1000];
  21.  
  22.         for (i=0; i<100; i++) {
  23.                 d = sin(i);
  24.                 snprintf(buf, sizeof buf, "%.300f", d);
  25.                 TEST(d2, strtod(buf, 0), d, "round trip fail %a != %a (%a)");
  26.         }
  27.  
  28.         TEST(d, strtod("0x1p4", 0), 16.0, "hex float %a != %a");
  29.         TEST(d, strtod("0x1.1p4", 0), 17.0, "hex float %a != %a");
  30.  
  31.         printf("%s finished\n", __FILE__);
  32.         return t_status;
  33. }
  34.  
  35.