2013-05-10 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libquadmath / quadmath-rounding-mode.h
bloba806794835a5da2ee572dc2e25f9bfe9baec01a2
1 /* GCC Quad-Precision Math Library
2 Copyright (C) 2012 Free Software Foundation, Inc.
4 This file is part of the libquadmath library.
5 Libquadmath is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 Libquadmath is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with libquadmath; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18 Boston, MA 02110-1301, USA. */
21 #ifndef QUADMATH_ROUNDING_MODE_H
22 #define QUADMATH_ROUNDING_MODE_H
24 #include <stdbool.h>
27 #if defined(HAVE_FENV_H)
28 # include <fenv.h>
29 #endif /* HAVE_FENV_H */
31 static inline int
32 get_rounding_mode (void)
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
42 static inline bool
43 round_away (bool negative, bool last_digit_odd, bool half_bit, bool more_bits,
44 int mode)
46 switch (mode)
48 #ifdef FE_DOWNWARD
49 case FE_DOWNWARD:
50 return negative && (half_bit || more_bits);
51 #endif
53 #ifdef FE_DOWNWARD
54 case FE_TONEAREST:
55 return half_bit && (last_digit_odd || more_bits);
56 #endif
58 #ifdef FE_TOWARDZERO
59 case FE_TOWARDZERO:
60 return false;
61 #endif
64 #ifdef FE_UPWARD
65 case FE_UPWARD:
66 return !negative && (half_bit || more_bits);
67 #endif
69 default:
70 return false;
74 #endif /* QUADMATH_ROUNDING_MODE_H */