1 /* Test that exact underflow in __float128 signals the underflow
2    exception if trapping is enabled, but does not raise the flag
3    otherwise.  */
4 
5 /* { dg-do run { target i?86-*-*gnu* x86_64-*-*gnu* ia64-*-*gnu* } } */
6 /* { dg-options "-D_GNU_SOURCE" } */
7 /* { dg-require-effective-target fenv_exceptions } */
8 
9 #include <fenv.h>
10 #include <setjmp.h>
11 #include <signal.h>
12 #include <stdlib.h>
13 
14 volatile sig_atomic_t caught_sigfpe;
15 sigjmp_buf buf;
16 
17 static void
handle_sigfpe(int sig)18 handle_sigfpe (int sig)
19 {
20   caught_sigfpe = 1;
21   siglongjmp (buf, 1);
22 }
23 
24 int
main(void)25 main (void)
26 {
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);
41 }
42