This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

New ieee comparison testcase for testsuite (Version 2)


[ This version checks for __STDC_IEC_559__ per Zack's
  recommendation in order to decide if fesetenv should
  be used instead of checking for __linux__. ]

This testcase trips in situations not caught by fp-cmp-1.
fpsetmask (fesetenv) is used to disable floating point
exceptions caused by NaN comparisons so that the result
of the actual comparison can be checked.  The fesetenv
solution is based on email from Zack and Richard ... I
don't have access to an iso c9x (i.e. glibc 2.1) machine
so I can't confirm that it's correct.

ChangeLog:

Sun Apr 25 20:21:07 EDT 1999  John Wehle  (john@feith.com)

	* fp-cmp-2.c: New testcase.

Enjoy!

-- John Wehle
------------------8<------------------------8<------------------------
*** /dev/null	Sun Apr 25 20:21:04 1999
--- gcc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-2.c	Sun Apr 25 20:15:10 1999
***************
*** 0 ****
--- 1,56 ----
+ #include <math.h>
+ #if defined(__FreeBSD__)
+ #  include <floatingpoint.h>
+ #elif defined(__svr4__)
+ #  include <ieeefp.h>
+ #elif defined(__STDC_IEC_559__)
+ #  include <fenv.h>
+ #else
+ #  include <signal.h>
+ #endif
+ 
+ volatile double nan = 1.0/0.0 - 1.0/0.0;
+ volatile double x = 1.0;
+ 
+ void leave ()
+ {
+   exit (0);
+ }
+ 
+ main ()
+ {
+ #if ! defined (__vax__) && ! defined (_CRAY)
+   /* Move this line earlier, for architectures (like alpha) that issue 
+      SIGFPE on the first comparisons. */
+ #if defined(__FreeBSD__) || defined(__svr4__)
+   fpsetmask (~FP_X_INV);
+ #elif defined(__STDC_IEC_559__)
+   fesetenv (FP_NOMASK_ENV);
+ #else
+ #  ifndef SIGNAL_SUPPRESS
+   /* Some machines catches a SIGFPE when a NaN is compared.
+      Let this test succeed o such machines.  */
+ signal (SIGFPE, leave);
+ #  endif
+ #endif
+   /* NaN is an IEEE unordered operand.  All these test should be false.  */
+   if (nan == nan)
+     abort ();
+   if (nan != x)
+     x = 1.0;
+   else
+     abort ();
+ 
+   if (nan < x)
+     abort ();
+   if (nan > x)
+     abort ();
+   if (nan <= x)
+     abort ();
+   if (nan >= x)
+     abort ();
+   if (nan == x)
+     abort ();
+ #endif
+   exit (0);
+ }
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]