blob: 26740bf69c2ad0130c14787c186bcb4e5d694db7 [file] [log] [blame]
Janis Johnson240e6b62006-11-29 18:34:56 +00001/* Internal testing support for rounding for decimal float.
2
3 Copyright (C) 2005, 2006 Free Software Foundation, Inc.
Ben Elliston473a74b2005-11-28 22:30:30 +00004
Ben Ellistonc0173132005-12-04 23:50:48 +00005 This file is part of GCC.
Ben Elliston473a74b2005-11-28 22:30:30 +00006
Ben Ellistonc0173132005-12-04 23:50:48 +00007 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.
Ben Elliston473a74b2005-11-28 22:30:30 +000011
Ben Elliston9d1d1cd2007-03-08 22:23:15 +000012 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.)
20
Ben Ellistonc0173132005-12-04 23:50:48 +000021 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.
Ben Elliston473a74b2005-11-28 22:30:30 +000025
Ben Ellistonc0173132005-12-04 23:50:48 +000026 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. */
Ben Elliston473a74b2005-11-28 22:30:30 +000030
Joseph Myersbc6d4c32008-06-11 00:43:09 +010031#include "dconfig.h"
Ben Elliston473a74b2005-11-28 22:30:30 +000032#include "decContext.h"
Janis Johnson240e6b62006-11-29 18:34:56 +000033#include "decRound.h"
34
35/* Internal, non-documented functions for testing libgcc functions.
36 This support is not sufficient for application use. */
Ben Elliston473a74b2005-11-28 22:30:30 +000037
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
44
Ben Elliston473a74b2005-11-28 22:30:30 +000045static enum rounding __dfp_rounding_mode = DEC_ROUND_HALF_EVEN;
46
47/* Set the decNumber rounding mode from the FE_DEC_* value in MODE. */
48
49void
50__dfp_set_round (int mode)
51{
52 switch (mode)
53 {
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;
67 }
68}
69
70/* Return the decNumber rounding mode as an FE_DEC_* value. */
71
72int
73__dfp_get_round (void)
74{
75 int mode;
76
77 switch (__dfp_rounding_mode)
78 {
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;
92 }
93 return mode;
94}
95
96/* Return the decNumber version of the current rounding mode. */
97
98enum rounding
99__decGetRound (void)
100{
101 return __dfp_rounding_mode;
102}