ulps: Fix long lines
[mathlib.git] / etc / testrand2.c
CommitLineData
73ad20d6
SK
1#include <assert.h>
2#include <math.h>
93f0b80b 3#include <mytypes.h>
73ad20d6
SK
4#include <stdio.h>
5#include <string.h>
6
7#include "subr_random.h"
8
9struct
10stats {
11 const char *st_type;
12 size_t st_normals;
93f0b80b 13 size_t st_subnormals;
73ad20d6
SK
14 size_t st_nans;
15 size_t st_inf;
16 size_t st_zero;
17 size_t st_invalid;
18};
19
20#define DECL(type) \
21static void \
22probe_##type(struct stats *st, size_t N) \
23{ \
24 type x; \
25 size_t i; \
26 \
27 assert(st); \
28 memset(st, 0, sizeof(*st)); \
29 \
30 st->st_type = #type; \
31 \
32 for (i = 0; i < N; i++) { \
93f0b80b 33 x = random_##type(1); \
73ad20d6
SK
34 switch (fpclassify(x)) { \
35 case FP_NORMAL: \
93f0b80b 36 ++st->st_normals; \
73ad20d6
SK
37 break; \
38 case FP_SUBNORMAL: \
93f0b80b 39 ++st->st_subnormals; \
73ad20d6
SK
40 break; \
41 case FP_NAN: \
93f0b80b 42 ++st->st_nans; \
73ad20d6
SK
43 break; \
44 case FP_INFINITE: \
93f0b80b 45 ++st->st_inf; \
73ad20d6
SK
46 break; \
47 case FP_ZERO: \
93f0b80b 48 ++st->st_zero; \
73ad20d6
SK
49 break; \
50 default: \
51 /* invalid floating-point number */ \
93f0b80b 52 ++st->st_invalid; \
73ad20d6
SK
53 break; \
54 } \
55 } \
56}
57
58typedef long double long_double;
59DECL(float);
60DECL(double);
61DECL(long_double);
62
63static void
64print_stats(const struct stats *st)
65{
66 assert(st);
67
68 printf("---------- %s ----------\n", st->st_type);
69 printf(" Normals: %u\n", st->st_normals);
93f0b80b 70 printf("Subnormals: %u\n", st->st_subnormals);
73ad20d6
SK
71 printf(" NaNs: %u\n", st->st_nans);
72 printf(" Inf: %u\n", st->st_inf);
73 printf(" Zero: %u\n", st->st_zero);
74 printf(" Invalid: %u\n", st->st_invalid);
75 fflush(stdout);
76}
77
78int
79main(void)
80{
81 struct stats s;
93f0b80b 82 const size_t N = 100*1000*1000;
73ad20d6 83
93f0b80b 84 init_randgen();
85#if 0
73ad20d6
SK
86 /* floats */
87 probe_float(&s, N);
88 print_stats(&s);
9881f59d 89
73ad20d6
SK
90 /* double */
91 probe_double(&s, N);
92 print_stats(&s);
93f0b80b 93#endif
73ad20d6
SK
94
95 /* long double */
96 probe_long_double(&s, N);
97 print_stats(&s);
9881f59d 98
73ad20d6
SK
99 return 0;
100}