diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-12-02 11:44:35 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-12-02 11:44:35 +0000 |
commit | 9652b7ef69a3f7576f757fb65e4086861e30e33c (patch) | |
tree | bc6c8dc81b56f48fa92654891cf1682865bd69fe /tests | |
parent | b1b5b3aa85ae38edef7330c34712b8f2a2f0dbfc (diff) | |
download | mpfr-9652b7ef69a3f7576f757fb65e4086861e30e33c.tar.gz |
Fix rnd_mode.c (again).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2107 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/rnd_mode.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/tests/rnd_mode.c b/tests/rnd_mode.c index 3497fe858..94f5981e5 100644 --- a/tests/rnd_mode.c +++ b/tests/rnd_mode.c @@ -19,26 +19,61 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <stdio.h> -#include <stdlib.h> #include "gmp.h" -#include "gmp-impl.h" /* for MPFR_HAVE_FESETROUND when building within gmp */ +#include "gmp-impl.h" #include "mpfr.h" +#include "mpfr-test.h" + +/* Note: "gmp-impl.h" must be included because MPFR_HAVE_FESETROUND + may be defined from it (if MPFR is built with GMP). */ #ifdef MPFR_HAVE_FESETROUND #include <fenv.h> +#endif + +/* It is important to test each FE_* macro -- see the ISO C99 standard. + For instance, with some ARM implementations, only FE_TONEAREST may + be defined. */ /* sets the machine rounding mode to the value rnd_mode */ -void +int mpfr_set_machine_rnd_mode (mp_rnd_t rnd_mode) { - switch (rnd_mode) { - case GMP_RNDN: fesetround(FE_TONEAREST); break; - case GMP_RNDZ: fesetround(FE_TOWARDZERO); break; - case GMP_RNDU: fesetround(FE_UPWARD); break; - case GMP_RNDD: fesetround(FE_DOWNWARD); break; - default: fprintf(stderr, "invalid rounding mode\n"); exit(1); - } -} - + switch (rnd_mode) + { + case GMP_RNDN: + return +#if defined (MPFR_HAVE_FESETROUND) && defined (FE_TONEAREST) + fesetround(FE_TONEAREST) +#else + -1 #endif + ; + case GMP_RNDZ: + return +#if defined (MPFR_HAVE_FESETROUND) && defined (FE_TOWARDZERO) + fesetround(FE_TOWARDZERO) +#else + -1 +#endif + ; + case GMP_RNDU: + return +#if defined (MPFR_HAVE_FESETROUND) && defined (FE_UPWARD) + fesetround(FE_UPWARD) +#else + -1 +#endif + ; + case GMP_RNDD: + return +#if defined (MPFR_HAVE_FESETROUND) && defined (FE_DOWNWARD) + fesetround(FE_DOWNWARD) +#else + -1 +#endif + ; + default: + return -1; + } +} |