or1k: RTEMS target support and simplify matching
[deliverable/binutils-gdb.git] / libdecnumber / decRound.c
CommitLineData
f5bc1778
DJ
1/* Internal testing support for rounding for decimal float.
2
0f5f799a 3 Copyright (C) 2005-2013 Free Software Foundation, Inc.
f5bc1778
DJ
4
5 This file is part of GCC.
6
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
168a2f77 9 the Free Software Foundation; either version 3, or (at your option)
f5bc1778
DJ
10 any later version.
11
f5bc1778
DJ
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.
16
168a2f77
DD
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
f5bc1778 25
5f5dfcbe 26#include "dconfig.h"
f5bc1778
DJ
27#include "decContext.h"
28#include "decRound.h"
29
30/* Internal, non-documented functions for testing libgcc functions.
31 This support is not sufficient for application use. */
32
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
39
40static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
41
42/* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */
43
44void
45__dfp_set_round (int mode)
46{
47 switch (mode)
48 {
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;
62 }
63}
64
65/* Return the decNumber rounding mode as an FE_DEC_* value. */
66
67int
68__dfp_get_round (void)
69{
70 int mode;
71
72 switch (__dfp_rounding_mode)
73 {
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;
87 }
88 return mode;
89}
90
91/* Return the decNumber version of the current rounding mode. */
92
93enum rounding
94__decGetRound (void)
95{
96 return __dfp_rounding_mode;
97}
This page took 0.28026 seconds and 4 git commands to generate.