]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/dfp-exprs.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / dfp-exprs.exp
CommitLineData
1d506c26 1# Copyright (C) 2007-2024 Free Software Foundation, Inc.
93004d61
TJB
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
17
18# This file is part of the gdb testsuite. It contains test for evaluating
19# simple decimal floating point (DFP) expression.
20
93004d61
TJB
21proc test_dfp_literals_accepted {} {
22
23 # Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
24
25 # _Decimal32 constants, which can support up to 7 digits
26 gdb_test "p 1.2df" " = 1.2"
27 gdb_test "p -1.2df" " = -1.2"
28 gdb_test "p 1.234567df" " = 1.234567"
29 gdb_test "p -1.234567df" " = -1.234567"
30 gdb_test "p 1234567.df" " = 1234567"
31 gdb_test "p -1234567.df" " = -1234567"
32
33 gdb_test "p 1.2E1df" " = 12"
34 gdb_test "p 1.2E10df" " = 1.2E\\+10"
35 gdb_test "p 1.2E-10df" " = 1.2E-10"
36
37 # The largest exponent for 32-bit dfp value is 96.
38 gdb_test "p 1.2E96df" " = 1.200000E\\+96"
39
40 # _Decimal64 constants, which can support up to 16 digits
41 gdb_test "p 1.2dd" " = 1.2"
42 gdb_test "p -1.2dd" " = -1.2"
43 gdb_test "p 1.234567890123456dd" " = 1.234567890123456"
44 gdb_test "p -1.234567890123456dd" " = -1.234567890123456"
45 gdb_test "p 1234567890123456.dd" " = 1234567890123456"
46 gdb_test "p -1234567890123456.dd" " = -1234567890123456"
47
48 gdb_test "p 1.2E1dd" " = 12"
49 gdb_test "p 1.2E10dd" " = 1.2E\\+10"
50 gdb_test "p 1.2E-10dd" " = 1.2E-10"
51
52 # The largest exponent for 64-bit dfp value is 384.
53 gdb_test "p 1.2E384dd" " = 1.200000000000000E\\+384"
54
55 # _Decimal128 constants, which can support up to 34 digits
56 gdb_test "p 1.2dl" " = 1.2"
57 gdb_test "p -1.2dl" " = -1.2"
58 gdb_test "p 1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
59 gdb_test "p -1.234567890123456789012345678901234dl" " = -1.234567890123456789012345678901234"
60 gdb_test "p 1234567890123456789012345678901234.dl" " = 1234567890123456789012345678901234"
61 gdb_test "p -1234567890123456789012345678901234.dl" " = -1234567890123456789012345678901234"
62
63 gdb_test "p 1.2E1dl" " = 12"
64 gdb_test "p 1.2E10dl" " = 1.2E\\+10"
65 gdb_test "p 1.2E-10dl" " = 1.2E-10"
66
67 # The largest exponent for 128-bit dfp value is 6144.
68 gdb_test "p 1.2E6144dl" " = 1.200000000000000000000000000000000E\\+6144"
69}
70
71proc test_dfp_arithmetic_expressions {} {
72
f6867ce0
TJB
73 # _Decimal32 operands.
74 gdb_test "p 1.4df + 1.2df" " = 2.6"
75 gdb_test "p 1.4df - 1.2df" " = 0.2"
76 gdb_test "p 1.4df * 1.2df" " = 1.68"
77 gdb_test "p 1.4df / 1.2df" " = 1.166667"
78
79 # _Decimal64 operands.
80 gdb_test "p 1.4dd + 1.2dd" " = 2.6"
81 gdb_test "p 1.4dd - 1.2dd" " = 0.2"
82 gdb_test "p 1.4dd * 1.2dd" " = 1.68"
83 gdb_test "p 1.4dd / 1.2dd" " = 1.166666666666667"
84
85 # _Decimal128 operands.
86 gdb_test "p 1.4dl + 1.2dl" " = 2.6"
87 gdb_test "p 1.4dl - 1.2dl" " = 0.2"
88 gdb_test "p 1.4dl * 1.2dl" " = 1.68"
89 gdb_test "p 1.4dl / 1.2dl" " = 1.166666666666666666666666666666667"
90
91 # Test type of operation result.
92 gdb_test "ptype 2.df + 2.df" "= _Decimal32"
93 gdb_test "ptype 2.dd + 2.dd" "= _Decimal64"
94 gdb_test "ptype 2.dl + 2.dl" "= _Decimal128"
95
96 # Mixture of different _Decimal sizes.
97 gdb_test "p 2.1df + 2.7dd" "= 4.8"
98 gdb_test "p 2.1dd + 2.7df" "= 4.8"
99 gdb_test "p 2.6df + 2.7dl" "= 5.3"
100 gdb_test "p 2.6dl + 2.7df" "= 5.3"
101 gdb_test "p 2.3dd + 2.2dl" "= 4.5"
102 gdb_test "p 2.3dl + 2.2dd" "= 4.5"
103 gdb_test "ptype 2.df + 2.dd" "= _Decimal64"
104 gdb_test "ptype 2.df + 2.dl" "= _Decimal128"
105 gdb_test "ptype 2.dd + 2.dl" "= _Decimal128"
106
107 # Mixture of Decimal and integral operands
108 gdb_test "p 1.2df + 1" " = 2.2"
109 gdb_test "p 2 + 1.7dd" " = 3.7"
110 gdb_test "p 3 + 2.1dl" " = 5.1"
111 gdb_test "ptype 1.2df + 1" " = _Decimal32"
112 gdb_test "ptype 2 + 1.7dd" " = _Decimal64"
113 gdb_test "ptype 3 + 2.1dl" " = _Decimal128"
114
115 # Reject operation with integral larger than 32-bits
3b4b2f16
UW
116 gdb_test "p 1.2dd + 2ll" "= 3.2"
117 gdb_test "p 1.2dd + 2147483648ll" "Conversion of large integer to a decimal floating type is not supported."
118 gdb_test "p 1.2dd + 2147483648ull" "= 2147483649.2"
119 gdb_test "p 1.2dd + 4294967296ull" "Conversion of large integer to a decimal floating type is not supported."
f6867ce0
TJB
120
121 # Reject operation with DFP and Binary FP
122 gdb_test "p 1.2df + 1.2f" "Mixing decimal floating types with other floating types is not allowed."
123
124 # Test other operations with DFP operands
ffd5d21a
PA
125
126 set dsuffix {"dd" "df" "dl"}
127
128 foreach l $dsuffix {
129 foreach r $dsuffix {
130 gdb_test "p 1.2${l} == 1.2${r}" " = 1"
131 gdb_test "p 1.2${l} == 1.3${r}" " = 0"
132
133 gdb_test "p 1.2${l} < 1.2${r}" " = 0"
134 gdb_test "p 1.2${l} < 1.3${r}" " = 1"
135 gdb_test "p 1.3${l} < 1.2${r}" " = 0"
136
137 gdb_test "p 1.2${l} > 1.2${r}" " = 0"
138 gdb_test "p 1.2${l} > 1.3${r}" " = 0"
139 gdb_test "p 1.3${l} > 1.2${r}" " = 1"
140
141 gdb_test "p 1.2${l} <= 1.2${r}" " = 1"
142 gdb_test "p 1.2${l} <= 1.3${r}" " = 1"
143 gdb_test "p 1.3${l} <= 1.2${r}" " = 0"
144
145 gdb_test "p 1.2${l} >= 1.2${r}" " = 1"
146 gdb_test "p 1.2${l} >= 1.3${r}" " = 0"
147 gdb_test "p 1.3${l} >= 1.2${r}" " = 1"
148 }
149
150 gdb_test "p !0.${l}" " = 1"
151 gdb_test "p !0.5${l}" " = 0"
152
153 gdb_test "p +1.2${l}" " = 1.2"
154
155 # This checks GDB doesn't convert to int and rounds up/down.
156 gdb_test "p 1.2${l} == 1" " = 0"
157 gdb_test "p 1.2${l} == 2" " = 0"
158
159 gdb_test "p 1.2${l} == 1.2" \
160 "Mixing decimal floating types with other floating types is not allowed\\."
161
162 gdb_test "p 1.2${l} > 1" " = 1"
163 gdb_test "p 1.2${l} > 2" " = 0"
164 gdb_test "p 1.2${l} >= 1" " = 1"
165 gdb_test "p 1.2${l} >= 2" " = 0"
166
167 gdb_test "p 1.2${l} < 1" " = 0"
168 gdb_test "p 1.2${l} < 2" " = 1"
169 gdb_test "p 1.2${l} <= 1" " = 0"
170 gdb_test "p 1.2${l} <= 2" " = 1"
171
172 gdb_test "p 1 < 1.2${l}" " = 1"
173 gdb_test "p 2 < 1.2${l}" " = 0"
174 gdb_test "p 1 <= 1.2${l}" " = 1"
175 gdb_test "p 2 <= 1.2${l}" " = 0"
176
177 gdb_test "p 1 > 1.2${l}" " = 0"
178 gdb_test "p 2 > 1.2${l}" " = 1"
179 gdb_test "p 1 >= 1.2${l}" " = 0"
180 gdb_test "p 2 >= 1.2${l}" " = 1"
181 }
f6867ce0 182}
93004d61 183
f6867ce0
TJB
184proc test_dfp_conversions {} {
185 # Test cast to and from DFP values, and between DFPs of different sizes
93004d61 186
f6867ce0
TJB
187 gdb_test "p (float) -0.1df" " = -0.(0999.*|1000.*)"
188 gdb_test "p (int) 8.3dd" " = 8"
189 gdb_test "p (_Decimal64) 3.1" " = 3.(0999.*|1000.*)"
190 gdb_test "p (_Decimal128) 3.7df" " = 3.7"
191 gdb_test "p (_Decimal32) 4" " = 4"
93004d61
TJB
192}
193
c95d486d 194clean_restart
93004d61
TJB
195
196test_dfp_literals_accepted
197test_dfp_arithmetic_expressions
f6867ce0 198test_dfp_conversions