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)
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/>. */
27 #include "decContext.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
40 static enum rounding __dfp_rounding_mode
= DEC_ROUND_HALF_EVEN
;
42 /* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */
45 __dfp_set_round (int mode
)
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;
58 __dfp_rounding_mode
= DEC_ROUND_CEILING
; break;
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. */
68 __dfp_get_round (void)
72 switch (__dfp_rounding_mode
)
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;
81 mode
= FE_DEC_TOWARDZERO
; break;
82 case DEC_ROUND_CEILING
:
83 mode
= FE_DEC_UPWARD
; break;
85 /* We shouldn't get here, but can't use assert in libgcc. */
91 /* Return the decNumber version of the current rounding mode. */
96 return __dfp_rounding_mode
;