-
Notifications
You must be signed in to change notification settings - Fork 8
/
fp1.c
72 lines (60 loc) · 1.27 KB
/
fp1.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
67
68
69
70
71
72
#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
static void do_fp(pid_t pid, int sig)
{
unsigned int i;
long int a, b;
double c, d;
a = rand() % 1000000;
b = rand() % 1000000;
for (i = 0; i < 10000000; i++) {
a++;
b++;
c = a;
d = b;
if (!(i % 10000000)) {
putchar('0' + pid % 10);
fflush(stdout);
}
if (a + b != (long)(c + d))
printf("\n%u %u %u %6ld + %6ld = %7ld != %7ld = %7.0F = %6.0F + %6.0F\n",
i, pid, sig,
a, b, a + b, (long)(c + d), c + d, c, d);
if (a * b != (long)(c * d))
printf("\n%u %u %u %6ld * %6ld = %7ld != %7ld = %7.0F = %6.0F * %6.0F\n",
i, pid, sig,
a, b, a * b, (long)(c * d), c * d, c, d);
double rad = (double)(a % 180) / 180 * M_PI / 2;
if (fabs(asin(sin(rad)) - rad) > 0.00001)
printf("\n%u %u %u asin(sin(%3ld = %5.3F)) = %7.2F != %7.2F (sin = %5.2F)\n",
i, pid, sig,
a % 180,
rad, asin(sin(rad)), rad, sin(rad));
}
}
static void child(void)
{
pid_t pid = getpid();
srand(pid);
while (1)
do_fp(pid, 0);
}
static void sig(int)
{
// do_fp(getpid(), 1);
}
int main(void)
{
unsigned int a;
signal(SIGUSR1, sig);
for (a = 0; a < 10; a++)
if (!fork())
child();
wait(NULL);
return 0;
}