-
Notifications
You must be signed in to change notification settings - Fork 6
/
exptst.c
67 lines (60 loc) · 1.25 KB
/
exptst.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Test speed of single precision exp(),
double precision exp()
quadruple precision exp()
Elmar Klausmeier, 05-May-2020
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
long i, rep=1024, n=65000;
int c, precision='d';
float sf = 0;
double sd = 0;
long double sq = 0;
while ((c = getopt(argc,argv,"dfqn:r:")) != -1) {
switch (c) {
case 'd':
precision = 'd';
break;
case 'f':
precision = 'f';
break;
case 'n':
n = atoi(optarg);
break;
case 'q':
precision = 'q';
break;
case 'r':
rep = atoi(optarg);
if (rep <= 0) return 2;
break;
default:
printf("%s: unknown flag %c\n", argv[0], c);
return 1;
}
}
switch(precision) {
case 'd':
while (rep-- > 0)
for (i=0; i<n; ++i)
sd += exp(i % 53) - exp((i+1) % 43) - exp((i+2) % 47) - exp((i+3) % 37);
printf("sd = %f\n",sd);
break;
case 'f':
while (rep-- > 0)
for (i=0; i<n; ++i)
sf += expf(i % 53) - expf((i+1) % 43) - expf((i+2) % 47) - expf((i+3) % 37);
printf("sf = %f\n",sf);
break;
case 'q':
while (rep-- > 0)
for (i=0; i<n; ++i)
sq += expl(i % 53) - expl((i+1) % 43) - expl((i+2) % 47) - expl((i+3) % 37);
printf("sq = %Lf\n",sq);
break;
}
return 0;
}