Updated for libbid move.
[official-gcc.git] / libdecnumber / decRound.c
blob6e51eb6b5bac4a52c8a9e06c4dd5a6fbd4d423aa
1 /* Internal testing support for rounding for decimal float.
3 Copyright (C) 2005, 2006 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 2, or (at your option)
10 any later version.
12 In addition to the permissions in the GNU General Public License,
13 the Free Software Foundation gives you unlimited permission to link
14 the compiled version of this file into combinations with other
15 programs, and to distribute those combinations without any
16 restriction coming from the use of this file. (The General Public
17 License restrictions do apply in other respects; for example, they
18 cover modification of the file, and distribution when not linked
19 into a combine executable.)
21 GCC is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
24 License for more details.
26 You should have received a copy of the GNU General Public License
27 along with GCC; see the file COPYING. If not, write to the Free
28 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29 02110-1301, USA. */
31 #include "config.h"
32 #include "decContext.h"
33 #include "decRound.h"
35 /* Internal, non-documented functions for testing libgcc functions.
36 This support is not sufficient for application use. */
38 #define FE_DEC_DOWNWARD 0
39 #define FE_DEC_TONEAREST 1
40 #define FE_DEC_TONEARESTFROMZERO 2
41 #define FE_DEC_TOWARDZERO 3
42 #define FE_DEC_UPWARD 4
43 #define FE_DEC_MAX 5
45 static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
47 /* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */
49 void
50 __dfp_set_round (int mode)
52 switch (mode)
54 case FE_DEC_DOWNWARD:
55 __dfp_rounding_mode = DEC_ROUND_FLOOR; break;
56 case FE_DEC_TONEAREST:
57 __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
58 case FE_DEC_TONEARESTFROMZERO:
59 __dfp_rounding_mode = DEC_ROUND_HALF_UP; break;
60 case FE_DEC_TOWARDZERO:
61 __dfp_rounding_mode = DEC_ROUND_DOWN; break;
62 case FE_DEC_UPWARD:
63 __dfp_rounding_mode = DEC_ROUND_CEILING; break;
64 default:
65 /* We can't use assert in libgcc, so just return the default mode. */
66 __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break;
70 /* Return the decNumber rounding mode as an FE_DEC_* value. */
72 int
73 __dfp_get_round (void)
75 int mode;
77 switch (__dfp_rounding_mode)
79 case DEC_ROUND_FLOOR:
80 mode = FE_DEC_DOWNWARD; break;
81 case DEC_ROUND_HALF_EVEN:
82 mode = FE_DEC_TONEAREST; break;
83 case DEC_ROUND_HALF_UP:
84 mode = FE_DEC_TONEARESTFROMZERO; break;
85 case DEC_ROUND_DOWN:
86 mode = FE_DEC_TOWARDZERO; break;
87 case DEC_ROUND_CEILING:
88 mode = FE_DEC_UPWARD; break;
89 default:
90 /* We shouldn't get here, but can't use assert in libgcc. */
91 mode = -1;
93 return mode;
96 /* Return the decNumber version of the current rounding mode. */
98 enum rounding
99 __decGetRound (void)
101 return __dfp_rounding_mode;