1 /* $OpenBSD: floor.c,v 1.2 2011/07/09 03:33:07 martynas Exp $ */
2
3 /* Written by Michael Shalayeff, 2003, Public domain. */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <signal.h>
9 #include <unistd.h>
10 #include <math.h>
11
12 static void
sigfpe(int sig,siginfo_t * si,void * v)13 sigfpe(int sig, siginfo_t *si, void *v)
14 {
15 char buf[132];
16
17 if (si) {
18 snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n",
19 si->si_addr, si->si_code);
20 write(1, buf, strlen(buf));
21 }
22 _exit(1);
23 }
24
25 int
main(int argc,char * argv[])26 main(int argc, char *argv[])
27 {
28 struct sigaction sa;
29
30 memset(&sa, 0, sizeof(sa));
31 sa.sa_sigaction = sigfpe;
32 sa.sa_flags = SA_SIGINFO;
33 sigaction(SIGFPE, &sa, NULL);
34
35 if (floor(4294967295.7) != 4294967295.)
36 exit(1);
37 if (floorl(4294967295.7L) != 4294967295.L)
38 exit(1);
39
40 exit(0);
41 }
42