Merge branches/gcc-4_8-branch rev 216856
[official-gcc.git] / gcc-4_8-branch / gcc / testsuite / gcc.dg / torture / float128-exact-underflow.c
blobea11f26e22d00d35707631bcc53fd3208d77e523
1 /* Test that exact underflow in __float128 signals the underflow
2 exception if trapping is enabled, but does not raise the flag
3 otherwise. */
5 /* { dg-do run { target i?86-*-*gnu* x86_64-*-*gnu* } } */
6 /* { dg-options "-D_GNU_SOURCE" } */
7 /* { dg-require-effective-target fenv_exceptions } */
9 #include <fenv.h>
10 #include <setjmp.h>
11 #include <signal.h>
12 #include <stdlib.h>
14 volatile sig_atomic_t caught_sigfpe;
15 sigjmp_buf buf;
17 static void
18 handle_sigfpe (int sig)
20 caught_sigfpe = 1;
21 siglongjmp (buf, 1);
24 int
25 main (void)
27 volatile __float128 a = 0x1p-16382q, b = 0x1p-2q;
28 volatile __float128 r;
29 r = a * b;
30 if (fetestexcept (FE_UNDERFLOW))
31 abort ();
32 if (r != 0x1p-16384q)
33 abort ();
34 feenableexcept (FE_UNDERFLOW);
35 signal (SIGFPE, handle_sigfpe);
36 if (sigsetjmp (buf, 1) == 0)
37 r = a * b;
38 if (!caught_sigfpe)
39 abort ();
40 exit (0);