rint.c revision 1.6
1/* $OpenBSD: rint.c,v 1.6 2005/11/17 20:16:26 otto Exp $ */ 2 3/* Written by Michael Shalayeff, 2003, Public domain. */ 4 5#include <err.h> 6#include <stdio.h> 7#include <stdlib.h> 8#include <string.h> 9#include <signal.h> 10#include <unistd.h> 11#include <math.h> 12 13static void 14sigfpe(int sig, siginfo_t *si, void *v) 15{ 16 char buf[132]; 17 18 if (si) { 19 snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", 20 si->si_addr, si->si_code); 21 write(1, buf, strlen(buf)); 22 } 23 _exit(1); 24} 25 26int 27main(int argc, char *argv[]) 28{ 29 struct sigaction sa; 30 31 memset(&sa, 0, sizeof(sa)); 32 sa.sa_sigaction = sigfpe; 33 sa.sa_flags = SA_SIGINFO; 34 sigaction(SIGFPE, &sa, NULL); 35 36 if (rint(8.6) != 9.) 37 errx(1, "rint"); 38 if (rintf(8.6F) != 9) 39 errx(1, "rintf"); 40 if (lrint(8.6) != 9L) 41 errx(1, "lrint"); 42 if (lrintf(8.6F) != 9L) 43 errx(1, "lrintf"); 44 if (llrint(8.6) != 9LL) 45 errx(1, "llrint"); 46 if (llrintf(8.6F) != 9LL) 47 errx(1, "llrintf"); 48 49 exit(0); 50} 51