etc/testrand2: Cleanup a bit
authorstathis <stathis@solaris.(none)>
Wed, 2 Feb 2011 20:53:30 +0000 (22:53 +0200)
committerstathis <stathis@solaris.(none)>
Wed, 2 Feb 2011 20:53:30 +0000 (22:53 +0200)
etc/Makefile
etc/testrand2.c
include/mytypes.h
subr_random.c

index 10f8621..bb90fe8 100644 (file)
@@ -1,4 +1,4 @@
-PROGS=proffenv profmath realgen testrand
+PROGS=proffenv profmath realgen testrand testrand2
 ALL: $(PROGS)
 
 # -Wstrict-prototypes
@@ -33,8 +33,12 @@ realgen: realgen.c ../ulps/basic-complex.c ../ulps/gen.c ../subr_random.c
 testrand: testrand.c ../subr_random.c
        $(CC99) $(CCFLAGS) $(INCLUDE)                           \
                testrand.c ../subr_random.c                     \
-       -o testrand                                             \
-       $(LIB)
+       -o testrand -lm
+
+testrand2: testrand2.c ../subr_random.c
+       $(CC99) $(CCFLAGS) $(INCLUDE)                           \
+               testrand2.c ../subr_random.c                    \
+       -o testrand2 -lm
 
 gen-csv: profmath
 
index 2d0c9b7..65b49f4 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <math.h>
+#include <mytypes.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -9,7 +10,7 @@ struct
 stats {
        const char *st_type;
        size_t st_normals;
-       size_t st_denormals;
+       size_t st_subnormals;
        size_t st_nans;
        size_t st_inf;
        size_t st_zero;
@@ -29,27 +30,26 @@ probe_##type(struct stats *st, size_t N)                    \
        st->st_type = #type;                                    \
                                                                \
        for (i = 0; i < N; i++) {                               \
-               x = random_##type(0);                           \
-                                                               \
+               x = random_##type(1);                           \
                switch (fpclassify(x)) {                        \
                case FP_NORMAL:                                 \
-                       st->st_normals++;                       \
+                       ++st->st_normals;                       \
                        break;                                  \
                case FP_SUBNORMAL:                              \
-                       st->st_denormals++;                     \
+                       ++st->st_subnormals;                    \
                        break;                                  \
                case FP_NAN:                                    \
-                       st->st_nans++;                          \
+                       ++st->st_nans;                          \
                        break;                                  \
                case FP_INFINITE:                               \
-                       st->st_inf++;                           \
+                       ++st->st_inf;                           \
                        break;                                  \
                case FP_ZERO:                                   \
-                       st->st_zero++;                          \
+                       ++st->st_zero;                          \
                        break;                                  \
                default:                                        \
                        /* invalid floating-point number */     \
-                       st->st_invalid++;                       \
+                       ++st->st_invalid;                       \
                        break;                                  \
                }                                               \
        }                                                       \
@@ -67,7 +67,7 @@ print_stats(const struct stats *st)
 
        printf("---------- %s ----------\n", st->st_type);
        printf("  Normals: %u\n", st->st_normals);
-        printf("Denormals: %u\n", st->st_denormals);
+        printf("Subnormals: %u\n", st->st_subnormals);
         printf("     NaNs: %u\n", st->st_nans);
         printf("      Inf: %u\n", st->st_inf);
         printf("     Zero: %u\n", st->st_zero);
@@ -79,8 +79,10 @@ int
 main(void)
 {
        struct stats s;
-       const size_t N = 1*1000*1000;
+       const size_t N = 100*1000*1000;
 
+       init_randgen();
+#if 0
        /* floats */
        probe_float(&s, N);
        print_stats(&s);
@@ -88,6 +90,7 @@ main(void)
        /* double */
         probe_double(&s, N);
         print_stats(&s);
+#endif
 
        /* long double */
         probe_long_double(&s, N);
index 3527833..ca72d9e 100644 (file)
@@ -58,5 +58,7 @@ typedef union {
 #define        MY_FP_ZERO      0x10
 
 #define        MY_FP_REAL (MY_FP_NORMAL | MY_FP_SUBNORMAL | MY_FP_ZERO)
+#define MY_FP_ALL  (MY_FP_NORMAL | MY_FP_SUBNORMAL | MY_FP_ZERO \
+                   | MY_FP_INFINITE | MY_FP_ZERO)
 
 #endif /* ! __MY_TYPES__ */
index 0a0a966..6c49022 100644 (file)
@@ -157,7 +157,7 @@ random_long_double(int fpclass)
        do {
                for (i = 0; i < NQUADS; i++)
                        u.y[i] = MY_RANDOM();
-       } while (!ISVALIDFP(u.y) || ((fpclassify(u.x)) != fpclass));
+       } while (!ISVALIDFP(u.y));
 
        return (u.x);
 }