annotate libquadmath/quadmath-rounding-mode.h @ 158:494b0b89df80 default tip

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