ulps: Fix long lines
[mathlib.git] / ulps / main.c
CommitLineData
4be0a29b 1#include <stdio.h>
2#include <stdlib.h>
1437b786 3#include <string.h>
4be0a29b 4
4be0a29b 5#include "gen.h"
2026577c 6#include "subr_random.h"
a95d68a2 7#include "ulp.h"
4be0a29b 8
330191d4 9static int isbanned(const char *fname, int argc, char *argv[]);
c36ce6a8 10static void usage(void);
11
4be0a29b 12int
b9284fd1 13main(int argc, char *argv[])
4be0a29b 14{
b9284fd1 15 struct ulp u;
24d04885 16 struct ulp_complex uc;
fbb83d03 17 int i, total, all, realonly, complexonly, ban, list;
1437b786 18 const char *target;
e75639fd 19 const struct fentry *f;
b9284fd1 20
21 /* Skip program name */
22 argv++;
23 argc--;
24
a95d68a2 25 /*
8a710f61 26 * Parse command line arguments
27 * all = probe all supported functions
28 * list = list all supported functions
a95d68a2
SK
29 */
30 all = 0;
693125f7 31 realonly = 0;
32 complexonly = 0;
8a710f61 33 list = 0;
c36ce6a8 34 if (argc == 0) {
35 usage();
36 /* never reached */
37 } else if (argc == 1 && !strcmp(argv[0], "all")) {
38 all = 1;
39 argv++; argc--;
693125f7 40 } else if (argc == 1 && !strcmp(argv[0], "real")) {
41 all = realonly = 1;
42 argv++; argc--;
43 } else if (argc == 1 && !strcmp(argv[0], "complex")) {
44 all = complexonly = 1;
45 argv++; argc--;
fbb83d03 46 } else if (argc > 1 && !strcmp(argv[0], "ban")) {
47 all = ban = 1;
48 argv++; argc--;
c36ce6a8 49 } else if (argc == 1 && !strcmp(argv[0], "list")) {
50 list = 1;
51 argv++; argc--;
1437b786 52 }
53
8a710f61 54 if (list)
55 printfunctions();
b9284fd1 56
c36ce6a8 57 /* Initialize random number generator */
58 init_randgen();
59
60 /* Print header */
61 if (!list)
8a710f61 62 printf("\tFUNCTION Max ULP Min ULP Avg ULP "
c36ce6a8 63 "skipped\n");
31a95504 64
c36ce6a8 65 total = all ? fsize : argc;
1437b786 66
c36ce6a8 67 for (i = 0; i < total; i++) {
68 if (all) {
21fb7272 69 f = getfunctionbyidx(i);
f3b64054 70 if ((realonly && !f->f_mpfr) ||
71 (complexonly && f->f_mpfr))
693125f7 72 continue;
fbb83d03 73
74 if (ban) {
75 if (isbanned(f->f_name, argc, argv)) {
330191d4 76 printf("[%2u/%2u] %-12s %s\n",
77 i+1, total, f->f_name,
78 "\t\t--- banned ---");
fbb83d03 79 continue;
80 }
81 }
82
21fb7272 83 target = f->f_name;
132d50d8 84 } else {
c36ce6a8 85 target = argv[i];
86 }
dedfed29 87
c36ce6a8 88 /* Is it real or complex value function ? */
89 f = getfunctionbyname(target);
90 if (f == NULL) {
91 fprintf(stderr, "function: %s not found\n",
92 argv[i]);
93 continue;
21fb7272 94 }
dedfed29 95
c36ce6a8 96 /* Calculate ulp */
97 if (f->f_mpfr)
4565678c 98 getfunctionulp_real(f, &u);
21fb7272 99 else
100 getfunctionulp_complex(f, &uc);
dedfed29 101
c36ce6a8 102 if (f->f_mpfr) {
103 printf("[%2u/%2u] %-12s ", i+1, total, target);
104 printulps_double(u);
105 if (all && f->f_libml_real) {
106 printf(" %-12s ", f->f_namel);
107 printulps_long_double(u);
0d3e05c6 108 }
c36ce6a8 109 } else {
110 printf("[%2u/%2u] %-12s ", i+1, total, target);
111 printulps_double_complex(uc);
b9284fd1 112 }
113 }
4be0a29b 114
b9284fd1 115 return EXIT_SUCCESS;
4be0a29b 116}
c36ce6a8 117
fbb83d03 118static int
119isbanned(const char *fname, int argc, char *argv[])
120{
121 int i;
122
123 for (i = 0; i < argc; i++) {
124 if (!strcmp(fname, argv[i])) {
125 return 1;
126 }
127 }
128
129 return 0;
130}
131
c36ce6a8 132static void
133usage(void)
134{
693125f7 135 fprintf(stderr,
fbb83d03 136 "ulps: [list | all | real | complex | "
137 "ban <function1> <function2> ...] | "
138 "<function1> <function2> ... \n");
c36ce6a8 139 exit(EXIT_FAILURE);
140}