1/* GCC Quad-Precision Math Library 2 Copyright (C) 2012 Free Software Foundation, Inc. 3 4This file is part of the libquadmath library. 5Libquadmath is free software; you can redistribute it and/or 6modify it under the terms of the GNU Library General Public 7License as published by the Free Software Foundation; either 8version 2 of the License, or (at your option) any later version. 9 10Libquadmath is distributed in the hope that it will be useful, 11but WITHOUT ANY WARRANTY; without even the implied warranty of 12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13Library General Public License for more details. 14 15You should have received a copy of the GNU Library General Public 16License along with libquadmath; see the file COPYING.LIB. If 17not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 18Boston, MA 02110-1301, USA. */ 19 20 21#ifndef QUADMATH_ROUNDING_MODE_H 22#define QUADMATH_ROUNDING_MODE_H 23 24#include <stdbool.h> 25 26 27#if defined(HAVE_FENV_H) 28# include <fenv.h> 29#endif /* HAVE_FENV_H */ 30 31static inline int 32get_rounding_mode (void) 33{ 34#if defined(HAVE_FENV_H) && (defined(FE_DOWNWARD) || defined(FE_TONEAREST) \ 35 || defined(FE_TOWARDZERO) || defined(FE_UPWARD)) 36 return fegetround (); 37#else 38 return 0; 39#endif 40} 41 42static inline bool 43round_away (bool negative, bool last_digit_odd, bool half_bit, bool more_bits, 44 int mode) 45{ 46 switch (mode) 47 { 48#ifdef FE_DOWNWARD 49 case FE_DOWNWARD: 50 return negative && (half_bit || more_bits); 51#endif 52 53#ifdef FE_DOWNWARD 54 case FE_TONEAREST: 55 return half_bit && (last_digit_odd || more_bits); 56#endif 57 58#ifdef FE_TOWARDZERO 59 case FE_TOWARDZERO: 60 return false; 61#endif 62 63 64#ifdef FE_UPWARD 65 case FE_UPWARD: 66 return !negative && (half_bit || more_bits); 67#endif 68 69 default: 70 return false; 71 } 72} 73 74#endif /* QUADMATH_ROUNDING_MODE_H */ 75