]>
Commit | Line | Data |
---|---|---|
e3f15eef | 1 | /* Temporary support for a libc-like fp environment for decimal float. |
2 | Copyright (C) 2005 Free Software Foundation, Inc. | |
3 | ||
84d7eab9 | 4 | This file is part of GCC. |
5 | ||
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. | |
10 | ||
11 | GCC is distributed in the hope that it will be useful, but WITHOUT | |
12 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
13 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public | |
14 | License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GCC; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA | |
19 | 02110-1301, USA. */ | |
e3f15eef | 20 | |
f98cf5a9 | 21 | #include "config.h" |
e3f15eef | 22 | #include "decContext.h" |
23 | ||
24 | #define FE_DEC_DOWNWARD 0 | |
25 | #define FE_DEC_TONEAREST 1 | |
26 | #define FE_DEC_TONEARESTFROMZERO 2 | |
27 | #define FE_DEC_TOWARDZERO 3 | |
28 | #define FE_DEC_UPWARD 4 | |
29 | #define FE_DEC_MAX 5 | |
30 | ||
31 | extern void __dfp_set_round (int); | |
32 | extern int __dfp_get_round (void); | |
33 | extern enum rounding __decGetRound (void); | |
34 | ||
35 | /* FIXME: these should be in thread-local storage for runtime support. */ | |
36 | static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; | |
37 | ||
38 | /* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */ | |
39 | ||
40 | void | |
41 | __dfp_set_round (int mode) | |
42 | { | |
43 | switch (mode) | |
44 | { | |
45 | case FE_DEC_DOWNWARD: | |
46 | __dfp_rounding_mode = DEC_ROUND_FLOOR; break; | |
47 | case FE_DEC_TONEAREST: | |
48 | __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break; | |
49 | case FE_DEC_TONEARESTFROMZERO: | |
50 | __dfp_rounding_mode = DEC_ROUND_HALF_UP; break; | |
51 | case FE_DEC_TOWARDZERO: | |
52 | __dfp_rounding_mode = DEC_ROUND_DOWN; break; | |
53 | case FE_DEC_UPWARD: | |
54 | __dfp_rounding_mode = DEC_ROUND_CEILING; break; | |
55 | default: | |
56 | /* We can't use assert in libgcc, so just return the default mode. */ | |
57 | __dfp_rounding_mode = DEC_ROUND_HALF_EVEN; break; | |
58 | } | |
59 | } | |
60 | ||
61 | /* Return the decNumber rounding mode as an FE_DEC_* value. */ | |
62 | ||
63 | int | |
64 | __dfp_get_round (void) | |
65 | { | |
66 | int mode; | |
67 | ||
68 | switch (__dfp_rounding_mode) | |
69 | { | |
70 | case DEC_ROUND_FLOOR: | |
71 | mode = FE_DEC_DOWNWARD; break; | |
72 | case DEC_ROUND_HALF_EVEN: | |
73 | mode = FE_DEC_TONEAREST; break; | |
74 | case DEC_ROUND_HALF_UP: | |
75 | mode = FE_DEC_TONEARESTFROMZERO; break; | |
76 | case DEC_ROUND_DOWN: | |
77 | mode = FE_DEC_TOWARDZERO; break; | |
78 | case DEC_ROUND_CEILING: | |
79 | mode = FE_DEC_UPWARD; break; | |
80 | default: | |
81 | /* We shouldn't get here, but can't use assert in libgcc. */ | |
82 | mode = -1; | |
83 | } | |
84 | return mode; | |
85 | } | |
86 | ||
87 | /* Return the decNumber version of the current rounding mode. */ | |
88 | ||
89 | enum rounding | |
90 | __decGetRound (void) | |
91 | { | |
92 | return __dfp_rounding_mode; | |
93 | } |