c++: Skip unnamed bit-fields more
[official-gcc.git] / libdecnumber / decRound.c
blob67805150248f39c63e5f02090e93b9d3e199e533
1 /* Internal testing support for rounding for decimal float.
3 Copyright (C) 2005-2021 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #include "dconfig.h"
27 #include "decContext.h"
28 #include "decRound.h"
30 /* Internal, non-documented functions for testing libgcc functions.
31 This support is not sufficient for application use. */
33 #define FE_DEC_DOWNWARD 0
34 #define FE_DEC_TONEAREST 1
35 #define FE_DEC_TONEARESTFROMZERO 2
36 #define FE_DEC_TOWARDZERO 3
37 #define FE_DEC_UPWARD 4
38 #define FE_DEC_MAX 5
40 static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
42 /* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */
44 void
45 __dfp_set_round (int mode)
47 switch (mode)
49 case FE_DEC_DOWNWARD:
50 __dfp_rounding_mode = DEC_ROUND_FLOOR; break;
51 case FE_DEC_TONEAREST:
52 __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
53 case FE_DEC_TONEARESTFROMZERO:
54 __dfp_rounding_mode = DEC_ROUND_HALF_UP; break;
55 case FE_DEC_TOWARDZERO:
56 __dfp_rounding_mode = DEC_ROUND_DOWN; break;
57 case FE_DEC_UPWARD:
58 __dfp_rounding_mode = DEC_ROUND_CEILING; break;
59 default:
60 /* We can't use assert in libgcc, so just return the default mode. */
61 __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
65 /* Return the decNumber rounding mode as an FE_DEC_* value. */
67 int
68 __dfp_get_round (void)
70 int mode;
72 switch (__dfp_rounding_mode)
74 case DEC_ROUND_FLOOR:
75 mode = FE_DEC_DOWNWARD; break;
76 case DEC_ROUND_HALF_EVEN:
77 mode = FE_DEC_TONEAREST; break;
78 case DEC_ROUND_HALF_UP:
79 mode = FE_DEC_TONEARESTFROMZERO; break;
80 case DEC_ROUND_DOWN:
81 mode = FE_DEC_TOWARDZERO; break;
82 case DEC_ROUND_CEILING:
83 mode = FE_DEC_UPWARD; break;
84 default:
85 /* We shouldn't get here, but can't use assert in libgcc. */
86 mode = -1;
88 return mode;
91 /* Return the decNumber version of the current rounding mode. */
93 enum rounding
94 __decGetRound (void)
96 return __dfp_rounding_mode;