packaging: add 64bit libs on 32bit build env
[platform/upstream/linaro-glibc.git] / math / test-fenv.c
1 /* Copyright (C) 1997-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Andreas Jaeger <aj@suse.de> and
4    Ulrich Drepper <drepper@cygnus.com>, 1997.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <http://www.gnu.org/licenses/>.  */
19
20 /* Tests for ISO C99 7.6: Floating-point environment  */
21
22 #ifndef _GNU_SOURCE
23 # define _GNU_SOURCE
24 #endif
25
26 #include <complex.h>
27 #include <math.h>
28 #include <float.h>
29 #include <fenv.h>
30
31 #include <errno.h>
32 #include <signal.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <sys/wait.h>
38 #include <sys/resource.h>
39 #include <math-tests.h>
40
41 /*
42   Since not all architectures might define all exceptions, we define
43   a private set and map accordingly.
44 */
45 #define NO_EXC 0
46 #define INEXACT_EXC 0x1
47 #define DIVBYZERO_EXC 0x2
48 #define UNDERFLOW_EXC 0x04
49 #define OVERFLOW_EXC 0x08
50 #define INVALID_EXC 0x10
51 #define ALL_EXC \
52         (INEXACT_EXC | DIVBYZERO_EXC | UNDERFLOW_EXC | OVERFLOW_EXC | \
53          INVALID_EXC)
54
55 static int count_errors;
56
57 /* Test whether a given exception was raised.  */
58 static void
59 test_single_exception (short int exception,
60                        short int exc_flag,
61                        fexcept_t fe_flag,
62                        const char *flag_name)
63 {
64   if (exception & exc_flag)
65     {
66       if (fetestexcept (fe_flag))
67         printf ("  Pass: Exception \"%s\" is set\n", flag_name);
68       else
69         {
70           printf ("  Fail: Exception \"%s\" is not set\n", flag_name);
71           ++count_errors;
72         }
73     }
74   else
75     {
76       if (fetestexcept (fe_flag))
77         {
78           printf ("  Fail: Exception \"%s\" is set\n", flag_name);
79           ++count_errors;
80         }
81       else
82         {
83           printf ("  Pass: Exception \"%s\" is not set\n", flag_name);
84         }
85     }
86 }
87
88 static void
89 test_exceptions (const char *test_name, short int exception,
90                  int ignore_inexact)
91 {
92   printf ("Test: %s\n", test_name);
93 #ifdef FE_DIVBYZERO
94   test_single_exception (exception, DIVBYZERO_EXC, FE_DIVBYZERO,
95                          "DIVBYZERO");
96 #endif
97 #ifdef FE_INVALID
98   test_single_exception (exception, INVALID_EXC, FE_INVALID,
99                          "INVALID");
100 #endif
101 #ifdef FE_INEXACT
102   if (!ignore_inexact)
103     test_single_exception (exception, INEXACT_EXC, FE_INEXACT,
104                            "INEXACT");
105 #endif
106 #ifdef FE_UNDERFLOW
107   test_single_exception (exception, UNDERFLOW_EXC, FE_UNDERFLOW,
108                          "UNDERFLOW");
109 #endif
110 #ifdef FE_OVERFLOW
111   test_single_exception (exception, OVERFLOW_EXC, FE_OVERFLOW,
112                          "OVERFLOW");
113 #endif
114 }
115
116 static void
117 print_rounding (int rounding)
118 {
119
120   switch (rounding)
121     {
122 #ifdef FE_TONEAREST
123     case FE_TONEAREST:
124       printf ("TONEAREST");
125       break;
126 #endif
127 #ifdef FE_UPWARD
128     case FE_UPWARD:
129       printf ("UPWARD");
130       break;
131 #endif
132 #ifdef FE_DOWNWARD
133     case FE_DOWNWARD:
134       printf ("DOWNWARD");
135       break;
136 #endif
137 #ifdef FE_TOWARDZERO
138     case FE_TOWARDZERO:
139       printf ("TOWARDZERO");
140       break;
141 #endif
142     }
143   printf (".\n");
144 }
145
146
147 static void
148 test_rounding (const char *test_name, int rounding_mode)
149 {
150   int curr_rounding = fegetround ();
151
152   printf ("Test: %s\n", test_name);
153   if (curr_rounding == rounding_mode)
154     {
155       printf ("  Pass: Rounding mode is ");
156       print_rounding (curr_rounding);
157     }
158   else
159     {
160       ++count_errors;
161       printf ("  Fail: Rounding mode is ");
162       print_rounding (curr_rounding);
163     }
164 }
165
166
167 static void
168 set_single_exc (const char *test_name, int fe_exc, fexcept_t exception)
169 {
170   char str[200];
171   /* The standard allows the inexact exception to be set together with the
172      underflow and overflow exceptions.  So ignore the inexact flag if the
173      others are raised.  */
174   int ignore_inexact = (fe_exc & (UNDERFLOW_EXC | OVERFLOW_EXC)) != 0;
175
176   strcpy (str, test_name);
177   strcat (str, ": set flag, with rest not set");
178   feclearexcept (FE_ALL_EXCEPT);
179   feraiseexcept (exception);
180   test_exceptions (str, fe_exc, ignore_inexact);
181
182   strcpy (str, test_name);
183   strcat (str, ": clear flag, rest also unset");
184   feclearexcept (exception);
185   test_exceptions (str, NO_EXC, ignore_inexact);
186
187   strcpy (str, test_name);
188   strcat (str, ": set flag, with rest set");
189   feraiseexcept (FE_ALL_EXCEPT ^ exception);
190   feraiseexcept (exception);
191   test_exceptions (str, ALL_EXC, 0);
192
193   strcpy (str, test_name);
194   strcat (str, ": clear flag, leave rest set");
195   feclearexcept (exception);
196   test_exceptions (str, ALL_EXC ^ fe_exc, 0);
197 }
198
199 static void
200 fe_tests (void)
201 {
202   /* clear all exceptions and test if all are cleared */
203   feclearexcept (FE_ALL_EXCEPT);
204   test_exceptions ("feclearexcept (FE_ALL_EXCEPT) clears all exceptions",
205                    NO_EXC, 0);
206
207   /* raise all exceptions and test if all are raised */
208   feraiseexcept (FE_ALL_EXCEPT);
209   test_exceptions ("feraiseexcept (FE_ALL_EXCEPT) raises all exceptions",
210                    ALL_EXC, 0);
211   feclearexcept (FE_ALL_EXCEPT);
212
213 #ifdef FE_DIVBYZERO
214   set_single_exc ("Set/Clear FE_DIVBYZERO", DIVBYZERO_EXC, FE_DIVBYZERO);
215 #endif
216 #ifdef FE_INVALID
217   set_single_exc ("Set/Clear FE_INVALID", INVALID_EXC, FE_INVALID);
218 #endif
219 #ifdef FE_INEXACT
220   set_single_exc ("Set/Clear FE_INEXACT", INEXACT_EXC, FE_INEXACT);
221 #endif
222 #ifdef FE_UNDERFLOW
223   set_single_exc ("Set/Clear FE_UNDERFLOW", UNDERFLOW_EXC, FE_UNDERFLOW);
224 #endif
225 #ifdef FE_OVERFLOW
226   set_single_exc ("Set/Clear FE_OVERFLOW", OVERFLOW_EXC, FE_OVERFLOW);
227 #endif
228 }
229
230 /* Test that program aborts with no masked interrupts */
231 static void
232 feenv_nomask_test (const char *flag_name, int fe_exc)
233 {
234 #if defined FE_NOMASK_ENV
235   int status;
236   pid_t pid;
237
238   if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT)
239       && fesetenv (FE_NOMASK_ENV) != 0)
240     {
241       printf ("Test: not testing FE_NOMASK_ENV, it isn't implemented.\n");
242       return;
243     }
244
245   printf ("Test: after fesetenv (FE_NOMASK_ENV) processes will abort\n");
246   printf ("      when feraiseexcept (%s) is called.\n", flag_name);
247   pid = fork ();
248   if (pid == 0)
249     {
250 #ifdef RLIMIT_CORE
251       /* Try to avoid dumping core.  */
252       struct rlimit core_limit;
253       core_limit.rlim_cur = 0;
254       core_limit.rlim_max = 0;
255       setrlimit (RLIMIT_CORE, &core_limit);
256 #endif
257
258       fesetenv (FE_NOMASK_ENV);
259       feraiseexcept (fe_exc);
260       exit (2);
261     }
262   else if (pid < 0)
263     {
264       if (errno != ENOSYS)
265         {
266           printf ("  Fail: Could not fork.\n");
267           ++count_errors;
268         }
269       else
270         printf ("  `fork' not implemented, test ignored.\n");
271     }
272   else {
273     if (waitpid (pid, &status, 0) != pid)
274       {
275         printf ("  Fail: waitpid call failed.\n");
276         ++count_errors;
277       }
278     else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGFPE)
279       printf ("  Pass: Process received SIGFPE.\n");
280     else
281       {
282         printf ("  Fail: Process didn't receive signal and exited with status %d.\n",
283                 status);
284         ++count_errors;
285       }
286   }
287 #endif
288 }
289
290 /* Test that program doesn't abort with default environment */
291 static void
292 feenv_mask_test (const char *flag_name, int fe_exc)
293 {
294   int status;
295   pid_t pid;
296
297   printf ("Test: after fesetenv (FE_DFL_ENV) processes will not abort\n");
298   printf ("      when feraiseexcept (%s) is called.\n", flag_name);
299   pid = fork ();
300   if (pid == 0)
301     {
302 #ifdef RLIMIT_CORE
303       /* Try to avoid dumping core.  */
304       struct rlimit core_limit;
305       core_limit.rlim_cur = 0;
306       core_limit.rlim_max = 0;
307       setrlimit (RLIMIT_CORE, &core_limit);
308 #endif
309
310       fesetenv (FE_DFL_ENV);
311       feraiseexcept (fe_exc);
312       exit (2);
313     }
314   else if (pid < 0)
315     {
316       if (errno != ENOSYS)
317         {
318           printf ("  Fail: Could not fork.\n");
319           ++count_errors;
320         }
321       else
322         printf ("  `fork' not implemented, test ignored.\n");
323     }
324   else {
325     if (waitpid (pid, &status, 0) != pid)
326       {
327         printf ("  Fail: waitpid call failed.\n");
328         ++count_errors;
329       }
330     else if (WIFEXITED (status) && WEXITSTATUS (status) == 2)
331       printf ("  Pass: Process exited normally.\n");
332     else
333       {
334         printf ("  Fail: Process exited abnormally with status %d.\n",
335                 status);
336         ++count_errors;
337       }
338   }
339 }
340
341 /* Test that program aborts with no masked interrupts */
342 static void
343 feexcp_nomask_test (const char *flag_name, int fe_exc)
344 {
345   int status;
346   pid_t pid;
347
348   if (!EXCEPTION_ENABLE_SUPPORTED (fe_exc) && feenableexcept (fe_exc) == -1)
349     {
350       printf ("Test: not testing feenableexcept, it isn't implemented.\n");
351       return;
352     }
353
354   printf ("Test: after feenableexcept (%s) processes will abort\n",
355           flag_name);
356   printf ("      when feraiseexcept (%s) is called.\n", flag_name);
357   pid = fork ();
358   if (pid == 0)
359     {
360 #ifdef RLIMIT_CORE
361       /* Try to avoid dumping core.  */
362       struct rlimit core_limit;
363       core_limit.rlim_cur = 0;
364       core_limit.rlim_max = 0;
365       setrlimit (RLIMIT_CORE, &core_limit);
366 #endif
367
368       fedisableexcept (FE_ALL_EXCEPT);
369       feenableexcept (fe_exc);
370       feraiseexcept (fe_exc);
371       exit (2);
372     }
373   else if (pid < 0)
374     {
375       if (errno != ENOSYS)
376         {
377           printf ("  Fail: Could not fork.\n");
378           ++count_errors;
379         }
380       else
381         printf ("  `fork' not implemented, test ignored.\n");
382     }
383   else {
384     if (waitpid (pid, &status, 0) != pid)
385       {
386         printf ("  Fail: waitpid call failed.\n");
387         ++count_errors;
388       }
389     else if (WIFSIGNALED (status) && WTERMSIG (status) == SIGFPE)
390       printf ("  Pass: Process received SIGFPE.\n");
391     else
392       {
393         printf ("  Fail: Process didn't receive signal and exited with status %d.\n",
394                 status);
395         ++count_errors;
396       }
397   }
398 }
399
400 /* Test that program doesn't abort with exception.  */
401 static void
402 feexcp_mask_test (const char *flag_name, int fe_exc)
403 {
404   int status;
405   int exception;
406   pid_t pid;
407
408   printf ("Test: after fedisableexcept (%s) processes will not abort\n",
409           flag_name);
410   printf ("      when feraiseexcept (%s) is called.\n", flag_name);
411   pid = fork ();
412   if (pid == 0)
413     {
414 #ifdef RLIMIT_CORE
415       /* Try to avoid dumping core.  */
416       struct rlimit core_limit;
417       core_limit.rlim_cur = 0;
418       core_limit.rlim_max = 0;
419       setrlimit (RLIMIT_CORE, &core_limit);
420 #endif
421       feenableexcept (FE_ALL_EXCEPT);
422       exception = fe_exc;
423 #ifdef FE_INEXACT
424       /* The standard allows the inexact exception to be set together with the
425          underflow and overflow exceptions.  So add FE_INEXACT to the set of
426          exceptions to be disabled if we will be raising underflow or
427          overflow.  */
428 # ifdef FE_OVERFLOW
429       if (fe_exc & FE_OVERFLOW)
430         exception |= FE_INEXACT;
431 # endif
432 # ifdef FE_UNDERFLOW
433       if (fe_exc & FE_UNDERFLOW)
434         exception |= FE_INEXACT;
435 # endif
436 #endif
437       fedisableexcept (exception);
438       feraiseexcept (fe_exc);
439       exit (2);
440     }
441   else if (pid < 0)
442     {
443       if (errno != ENOSYS)
444         {
445           printf ("  Fail: Could not fork.\n");
446           ++count_errors;
447         }
448       else
449         printf ("  `fork' not implemented, test ignored.\n");
450     }
451   else {
452     if (waitpid (pid, &status, 0) != pid)
453       {
454         printf ("  Fail: waitpid call failed.\n");
455         ++count_errors;
456       }
457     else if (WIFEXITED (status) && WEXITSTATUS (status) == 2)
458       printf ("  Pass: Process exited normally.\n");
459     else
460       {
461         printf ("  Fail: Process exited abnormally with status %d.\n",
462                 status);
463         ++count_errors;
464       }
465   }
466 }
467
468
469 /* Tests for feenableexcept/fedisableexcept/fegetexcept.  */
470 static void
471 feenable_test (const char *flag_name, int fe_exc)
472 {
473   int excepts;
474
475   printf ("Tests for feenableexcepts etc. with flag %s\n", flag_name);
476
477   /* First disable all exceptions.  */
478   if (fedisableexcept (FE_ALL_EXCEPT) == -1)
479     {
480       printf ("Test: fedisableexcept (FE_ALL_EXCEPT) failed\n");
481       ++count_errors;
482       /* If this fails, the other tests don't make sense.  */
483       return;
484     }
485   excepts = fegetexcept ();
486   if (excepts != 0)
487     {
488       printf ("Test: fegetexcept (%s) failed, return should be 0, is %d\n",
489               flag_name, excepts);
490       ++count_errors;
491     }
492   excepts = feenableexcept (fe_exc);
493   if (!EXCEPTION_ENABLE_SUPPORTED (fe_exc) && excepts == -1)
494     {
495       printf ("Test: not testing feenableexcept, it isn't implemented.\n");
496       return;
497     }
498   if (excepts == -1)
499     {
500       printf ("Test: feenableexcept (%s) failed\n", flag_name);
501       ++count_errors;
502       return;
503     }
504   if (excepts != 0)
505     {
506       printf ("Test: feenableexcept (%s) failed, return should be 0, is %x\n",
507               flag_name, excepts);
508       ++count_errors;
509     }
510
511   excepts = fegetexcept ();
512   if (excepts != fe_exc)
513     {
514       printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
515               flag_name, fe_exc, excepts);
516       ++count_errors;
517     }
518
519   /* And now disable the exception again.  */
520   excepts = fedisableexcept (fe_exc);
521   if (excepts == -1)
522     {
523       printf ("Test: fedisableexcept (%s) failed\n", flag_name);
524       ++count_errors;
525       return;
526     }
527   if (excepts != fe_exc)
528     {
529       printf ("Test: fedisableexcept (%s) failed, return should be 0x%x, is 0x%x\n",
530               flag_name, fe_exc, excepts);
531       ++count_errors;
532     }
533
534   excepts = fegetexcept ();
535   if (excepts != 0)
536     {
537       printf ("Test: fegetexcept (%s) failed, return should be 0, is 0x%x\n",
538               flag_name, excepts);
539       ++count_errors;
540     }
541
542   /* Now the other way round: Enable all exceptions and disable just this one.  */
543   if (feenableexcept (FE_ALL_EXCEPT) == -1)
544     {
545       printf ("Test: feenableexcept (FE_ALL_EXCEPT) failed\n");
546       ++count_errors;
547       /* If this fails, the other tests don't make sense.  */
548       return;
549     }
550
551   excepts = fegetexcept ();
552   if (excepts != FE_ALL_EXCEPT)
553     {
554       printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
555               flag_name, FE_ALL_EXCEPT, excepts);
556       ++count_errors;
557     }
558
559   excepts = fedisableexcept (fe_exc);
560   if (excepts == -1)
561     {
562       printf ("Test: fedisableexcept (%s) failed\n", flag_name);
563       ++count_errors;
564       return;
565     }
566   if (excepts != FE_ALL_EXCEPT)
567     {
568       printf ("Test: fedisableexcept (%s) failed, return should be 0, is 0x%x\n",
569               flag_name, excepts);
570       ++count_errors;
571     }
572
573   excepts = fegetexcept ();
574   if (excepts != (FE_ALL_EXCEPT & ~fe_exc))
575     {
576       printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
577               flag_name, (FE_ALL_EXCEPT & ~fe_exc), excepts);
578       ++count_errors;
579     }
580
581   /* And now enable the exception again.  */
582   excepts = feenableexcept (fe_exc);
583   if (excepts == -1)
584     {
585       printf ("Test: feenableexcept (%s) failed\n", flag_name);
586       ++count_errors;
587       return;
588     }
589   if (excepts != (FE_ALL_EXCEPT & ~fe_exc))
590     {
591       printf ("Test: feenableexcept (%s) failed, return should be 0, is 0x%x\n",
592               flag_name, excepts);
593       ++count_errors;
594     }
595
596   excepts = fegetexcept ();
597   if (excepts != FE_ALL_EXCEPT)
598     {
599       printf ("Test: fegetexcept (%s) failed, return should be 0x%x, is 0x%x\n",
600               flag_name, FE_ALL_EXCEPT, excepts);
601       ++count_errors;
602     }
603   feexcp_nomask_test (flag_name, fe_exc);
604   feexcp_mask_test (flag_name, fe_exc);
605
606 }
607
608
609 static void
610 fe_single_test (const char *flag_name, int fe_exc)
611 {
612   feenv_nomask_test (flag_name, fe_exc);
613   feenv_mask_test (flag_name, fe_exc);
614   feenable_test (flag_name, fe_exc);
615 }
616
617
618 static void
619 feenv_tests (void)
620 {
621   /* We might have some exceptions still set.  */
622   feclearexcept (FE_ALL_EXCEPT);
623
624 #ifdef FE_DIVBYZERO
625   fe_single_test ("FE_DIVBYZERO", FE_DIVBYZERO);
626 #endif
627 #ifdef FE_INVALID
628   fe_single_test ("FE_INVALID", FE_INVALID);
629 #endif
630 #ifdef FE_INEXACT
631   fe_single_test ("FE_INEXACT", FE_INEXACT);
632 #endif
633 #ifdef FE_UNDERFLOW
634   fe_single_test ("FE_UNDERFLOW", FE_UNDERFLOW);
635 #endif
636 #ifdef FE_OVERFLOW
637   fe_single_test ("FE_OVERFLOW", FE_OVERFLOW);
638 #endif
639   fesetenv (FE_DFL_ENV);
640 }
641
642
643 static void
644 feholdexcept_tests (void)
645 {
646   fenv_t saved, saved2;
647   int res;
648
649   feclearexcept (FE_ALL_EXCEPT);
650   fedisableexcept (FE_ALL_EXCEPT);
651 #ifdef FE_DIVBYZERO
652   feraiseexcept (FE_DIVBYZERO);
653 #endif
654   test_exceptions ("feholdexcept_tests FE_DIVBYZERO test",
655                    DIVBYZERO_EXC, 0);
656   res = feholdexcept (&saved);
657   if (res != 0)
658     {
659       printf ("feholdexcept failed: %d\n", res);
660       ++count_errors;
661     }
662 #if defined FE_TONEAREST && defined FE_TOWARDZERO
663   res = fesetround (FE_TOWARDZERO);
664   if (res != 0)
665     {
666       printf ("fesetround failed: %d\n", res);
667       ++count_errors;
668     }
669 #endif
670   test_exceptions ("feholdexcept_tests 0 test", NO_EXC, 0);
671 #ifdef FE_INVALID
672   feraiseexcept (FE_INVALID);
673   test_exceptions ("feholdexcept_tests FE_INVALID test",
674                    INVALID_EXC, 0);
675 #endif
676   res = feupdateenv (&saved);
677   if (res != 0)
678     {
679       printf ("feupdateenv failed: %d\n", res);
680       ++count_errors;
681     }
682 #if defined FE_TONEAREST && defined FE_TOWARDZERO
683   res = fegetround ();
684   if (res != FE_TONEAREST)
685     {
686       printf ("feupdateenv didn't restore rounding mode: %d\n", res);
687       ++count_errors;
688     }
689 #endif
690   test_exceptions ("feholdexcept_tests FE_DIVBYZERO|FE_INVALID test",
691                    DIVBYZERO_EXC | INVALID_EXC, 0);
692   feclearexcept (FE_ALL_EXCEPT);
693 #ifdef FE_INVALID
694   feraiseexcept (FE_INVALID);
695 #endif
696 #if defined FE_TONEAREST && defined FE_UPWARD
697   res = fesetround (FE_UPWARD);
698   if (res != 0)
699     {
700       printf ("fesetround failed: %d\n", res);
701       ++count_errors;
702     }
703 #endif
704   res = feholdexcept (&saved2);
705   if (res != 0)
706     {
707       printf ("feholdexcept failed: %d\n", res);
708       ++count_errors;
709     }
710 #if defined FE_TONEAREST && defined FE_UPWARD
711   res = fesetround (FE_TONEAREST);
712   if (res != 0)
713     {
714       printf ("fesetround failed: %d\n", res);
715       ++count_errors;
716     }
717 #endif
718   test_exceptions ("feholdexcept_tests 0 2nd test", NO_EXC, 0);
719 #ifdef FE_INEXACT
720   feraiseexcept (FE_INEXACT);
721   test_exceptions ("feholdexcept_tests FE_INEXACT test",
722                    INEXACT_EXC, 0);
723 #endif
724   res = feupdateenv (&saved2);
725   if (res != 0)
726     {
727       printf ("feupdateenv failed: %d\n", res);
728       ++count_errors;
729     }
730 #if defined FE_TONEAREST && defined FE_UPWARD
731   res = fegetround ();
732   if (res != FE_UPWARD)
733     {
734       printf ("feupdateenv didn't restore rounding mode: %d\n", res);
735       ++count_errors;
736     }
737   fesetround (FE_TONEAREST);
738 #endif
739   test_exceptions ("feholdexcept_tests FE_INEXACT|FE_INVALID test",
740                    INVALID_EXC | INEXACT_EXC, 0);
741   feclearexcept (FE_ALL_EXCEPT);
742 }
743
744
745 /* IEC 559 and ISO C99 define a default startup environment */
746 static void
747 initial_tests (void)
748 {
749   test_exceptions ("Initially all exceptions should be cleared",
750                    NO_EXC, 0);
751 #ifdef FE_TONEAREST
752   test_rounding ("Rounding direction should be initalized to nearest",
753                  FE_TONEAREST);
754 #endif
755 }
756
757 int
758 main (void)
759 {
760   initial_tests ();
761   fe_tests ();
762   feenv_tests ();
763   feholdexcept_tests ();
764
765   if (count_errors)
766     {
767       printf ("\n%d errors occurred.\n", count_errors);
768       exit (1);
769     }
770   printf ("\n All tests passed successfully.\n");
771   return 0;
772 }