Radar 8710868: Build a separate version of libcc_kext.a for each ARM slice.
[llvm-gcc-4.2.git] / libdecnumber / decRound.c
blob3749ecb384d5f96fc042064c78c3e97032eac2ac
1 /* Temporary support for a libc-like fp environment for decimal float.
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 In addition to the permissions in the GNU General Public License,
12 the Free Software Foundation gives you unlimited permission to link
13 the compiled version of this file into combinations with other
14 programs, and to distribute those combinations without any
15 restriction coming from the use of this file. (The General Public
16 License restrictions do apply in other respects; for example, they
17 cover modification of the file, and distribution when not linked
18 into a combine executable.)
20 GCC is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
23 License for more details.
25 You should have received a copy of the GNU General Public License
26 along with GCC; see the file COPYING. If not, write to the Free
27 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28 02110-1301, USA. */
30 #include "config.h"
31 #include "decContext.h"
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 extern void __dfp_set_round (int);
41 extern int __dfp_get_round (void);
42 extern enum rounding __decGetRound (void);
44 /* FIXME: these should be in thread-local storage for runtime support. */
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;