Home | History | Annotate | Line # | Download | only in tests
      1      1.1  mrg /* mpfr_set_machine_rnd_mode -- set the rounding mode for machine floats
      2      1.1  mrg 
      3  1.1.1.6  mrg Copyright 1999, 2001-2002, 2006-2023 Free Software Foundation, Inc.
      4  1.1.1.3  mrg Contributed by the AriC and Caramba projects, INRIA.
      5      1.1  mrg 
      6      1.1  mrg This file is part of the GNU MPFR Library.
      7      1.1  mrg 
      8      1.1  mrg The GNU MPFR Library is free software; you can redistribute it and/or modify
      9      1.1  mrg it under the terms of the GNU Lesser General Public License as published by
     10      1.1  mrg the Free Software Foundation; either version 3 of the License, or (at your
     11      1.1  mrg option) any later version.
     12      1.1  mrg 
     13      1.1  mrg The GNU MPFR Library is distributed in the hope that it will be useful, but
     14      1.1  mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     15      1.1  mrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     16      1.1  mrg License for more details.
     17      1.1  mrg 
     18      1.1  mrg You should have received a copy of the GNU Lesser General Public License
     19      1.1  mrg along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
     20  1.1.1.5  mrg https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
     21      1.1  mrg 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
     22      1.1  mrg 
     23      1.1  mrg #include "mpfr-test.h"
     24      1.1  mrg 
     25      1.1  mrg /* It is important to test each FE_* macro -- see the ISO C99 standard.
     26      1.1  mrg    For instance, with some ARM implementations, only FE_TONEAREST may
     27      1.1  mrg    be defined. */
     28      1.1  mrg 
     29      1.1  mrg /* sets the machine rounding mode to the value rnd_mode */
     30      1.1  mrg int
     31      1.1  mrg mpfr_set_machine_rnd_mode (mpfr_rnd_t rnd_mode)
     32      1.1  mrg {
     33      1.1  mrg   switch (rnd_mode)
     34      1.1  mrg     {
     35      1.1  mrg     case MPFR_RNDN:
     36      1.1  mrg       return
     37      1.1  mrg #if defined (MPFR_HAVE_FESETROUND) && defined (FE_TONEAREST)
     38      1.1  mrg         fesetround(FE_TONEAREST)
     39      1.1  mrg #else
     40      1.1  mrg         -1
     41      1.1  mrg #endif
     42      1.1  mrg         ;
     43      1.1  mrg     case MPFR_RNDZ:
     44      1.1  mrg       return
     45      1.1  mrg #if defined (MPFR_HAVE_FESETROUND) && defined (FE_TOWARDZERO)
     46      1.1  mrg         fesetround(FE_TOWARDZERO)
     47      1.1  mrg #else
     48      1.1  mrg         -1
     49      1.1  mrg #endif
     50      1.1  mrg         ;
     51      1.1  mrg     case MPFR_RNDU:
     52      1.1  mrg       return
     53      1.1  mrg #if defined (MPFR_HAVE_FESETROUND) && defined (FE_UPWARD)
     54      1.1  mrg         fesetround(FE_UPWARD)
     55      1.1  mrg #else
     56      1.1  mrg         -1
     57      1.1  mrg #endif
     58      1.1  mrg         ;
     59      1.1  mrg     case MPFR_RNDD:
     60      1.1  mrg       return
     61      1.1  mrg #if defined (MPFR_HAVE_FESETROUND) && defined (FE_DOWNWARD)
     62      1.1  mrg         fesetround(FE_DOWNWARD)
     63      1.1  mrg #else
     64      1.1  mrg         -1
     65      1.1  mrg #endif
     66      1.1  mrg         ;
     67      1.1  mrg     default:
     68      1.1  mrg       return -1;
     69      1.1  mrg     }
     70      1.1  mrg }
     71