2017-01-01 07:50:51 +01:00
|
|
|
# Copyright (C) 2007-2017 Free Software Foundation, Inc.
|
2007-10-25 20:09:45 +02:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
|
|
|
|
|
|
|
|
# This file is part of the gdb testsuite. It contains test for evaluating
|
|
|
|
# simple decimal floating point (DFP) expression.
|
|
|
|
|
|
|
|
proc test_dfp_literals_accepted {} {
|
|
|
|
|
|
|
|
# Test various dfp values, covering 32-bit, 64-bit and 128-bit ones
|
|
|
|
|
|
|
|
# _Decimal32 constants, which can support up to 7 digits
|
|
|
|
gdb_test "p 1.2df" " = 1.2"
|
|
|
|
gdb_test "p -1.2df" " = -1.2"
|
|
|
|
gdb_test "p 1.234567df" " = 1.234567"
|
|
|
|
gdb_test "p -1.234567df" " = -1.234567"
|
|
|
|
gdb_test "p 1234567.df" " = 1234567"
|
|
|
|
gdb_test "p -1234567.df" " = -1234567"
|
|
|
|
|
|
|
|
gdb_test "p 1.2E1df" " = 12"
|
|
|
|
gdb_test "p 1.2E10df" " = 1.2E\\+10"
|
|
|
|
gdb_test "p 1.2E-10df" " = 1.2E-10"
|
|
|
|
|
|
|
|
# The largest exponent for 32-bit dfp value is 96.
|
|
|
|
gdb_test "p 1.2E96df" " = 1.200000E\\+96"
|
|
|
|
|
|
|
|
# _Decimal64 constants, which can support up to 16 digits
|
|
|
|
gdb_test "p 1.2dd" " = 1.2"
|
|
|
|
gdb_test "p -1.2dd" " = -1.2"
|
|
|
|
gdb_test "p 1.234567890123456dd" " = 1.234567890123456"
|
|
|
|
gdb_test "p -1.234567890123456dd" " = -1.234567890123456"
|
|
|
|
gdb_test "p 1234567890123456.dd" " = 1234567890123456"
|
|
|
|
gdb_test "p -1234567890123456.dd" " = -1234567890123456"
|
|
|
|
|
|
|
|
gdb_test "p 1.2E1dd" " = 12"
|
|
|
|
gdb_test "p 1.2E10dd" " = 1.2E\\+10"
|
|
|
|
gdb_test "p 1.2E-10dd" " = 1.2E-10"
|
|
|
|
|
|
|
|
# The largest exponent for 64-bit dfp value is 384.
|
|
|
|
gdb_test "p 1.2E384dd" " = 1.200000000000000E\\+384"
|
|
|
|
|
|
|
|
# _Decimal128 constants, which can support up to 34 digits
|
|
|
|
gdb_test "p 1.2dl" " = 1.2"
|
|
|
|
gdb_test "p -1.2dl" " = -1.2"
|
|
|
|
gdb_test "p 1.234567890123456789012345678901234dl" " = 1.234567890123456789012345678901234"
|
|
|
|
gdb_test "p -1.234567890123456789012345678901234dl" " = -1.234567890123456789012345678901234"
|
|
|
|
gdb_test "p 1234567890123456789012345678901234.dl" " = 1234567890123456789012345678901234"
|
|
|
|
gdb_test "p -1234567890123456789012345678901234.dl" " = -1234567890123456789012345678901234"
|
|
|
|
|
|
|
|
gdb_test "p 1.2E1dl" " = 12"
|
|
|
|
gdb_test "p 1.2E10dl" " = 1.2E\\+10"
|
|
|
|
gdb_test "p 1.2E-10dl" " = 1.2E-10"
|
|
|
|
|
|
|
|
# The largest exponent for 128-bit dfp value is 6144.
|
|
|
|
gdb_test "p 1.2E6144dl" " = 1.200000000000000000000000000000000E\\+6144"
|
|
|
|
}
|
|
|
|
|
|
|
|
proc test_dfp_arithmetic_expressions {} {
|
|
|
|
|
2008-01-07 23:34:49 +01:00
|
|
|
# _Decimal32 operands.
|
|
|
|
gdb_test "p 1.4df + 1.2df" " = 2.6"
|
|
|
|
gdb_test "p 1.4df - 1.2df" " = 0.2"
|
|
|
|
gdb_test "p 1.4df * 1.2df" " = 1.68"
|
|
|
|
gdb_test "p 1.4df / 1.2df" " = 1.166667"
|
|
|
|
|
|
|
|
# _Decimal64 operands.
|
|
|
|
gdb_test "p 1.4dd + 1.2dd" " = 2.6"
|
|
|
|
gdb_test "p 1.4dd - 1.2dd" " = 0.2"
|
|
|
|
gdb_test "p 1.4dd * 1.2dd" " = 1.68"
|
|
|
|
gdb_test "p 1.4dd / 1.2dd" " = 1.166666666666667"
|
|
|
|
|
|
|
|
# _Decimal128 operands.
|
|
|
|
gdb_test "p 1.4dl + 1.2dl" " = 2.6"
|
|
|
|
gdb_test "p 1.4dl - 1.2dl" " = 0.2"
|
|
|
|
gdb_test "p 1.4dl * 1.2dl" " = 1.68"
|
|
|
|
gdb_test "p 1.4dl / 1.2dl" " = 1.166666666666666666666666666666667"
|
|
|
|
|
|
|
|
# Test type of operation result.
|
|
|
|
gdb_test "ptype 2.df + 2.df" "= _Decimal32"
|
|
|
|
gdb_test "ptype 2.dd + 2.dd" "= _Decimal64"
|
|
|
|
gdb_test "ptype 2.dl + 2.dl" "= _Decimal128"
|
|
|
|
|
|
|
|
# Mixture of different _Decimal sizes.
|
|
|
|
gdb_test "p 2.1df + 2.7dd" "= 4.8"
|
|
|
|
gdb_test "p 2.1dd + 2.7df" "= 4.8"
|
|
|
|
gdb_test "p 2.6df + 2.7dl" "= 5.3"
|
|
|
|
gdb_test "p 2.6dl + 2.7df" "= 5.3"
|
|
|
|
gdb_test "p 2.3dd + 2.2dl" "= 4.5"
|
|
|
|
gdb_test "p 2.3dl + 2.2dd" "= 4.5"
|
|
|
|
gdb_test "ptype 2.df + 2.dd" "= _Decimal64"
|
|
|
|
gdb_test "ptype 2.df + 2.dl" "= _Decimal128"
|
|
|
|
gdb_test "ptype 2.dd + 2.dl" "= _Decimal128"
|
|
|
|
|
|
|
|
# Mixture of Decimal and integral operands
|
|
|
|
gdb_test "p 1.2df + 1" " = 2.2"
|
|
|
|
gdb_test "p 2 + 1.7dd" " = 3.7"
|
|
|
|
gdb_test "p 3 + 2.1dl" " = 5.1"
|
|
|
|
gdb_test "ptype 1.2df + 1" " = _Decimal32"
|
|
|
|
gdb_test "ptype 2 + 1.7dd" " = _Decimal64"
|
|
|
|
gdb_test "ptype 3 + 2.1dl" " = _Decimal128"
|
|
|
|
|
|
|
|
# Reject operation with integral larger than 32-bits
|
Clean up some DFP interfaces
This cleans up a number of interfaces in dfp.c / dfp.h. Specifically:
- The decimal_from_string / decimal_to_string routines are C++-ified
to operate on std::string instead of character buffers. In the
decimal_from_string, the boolean return value now actually is bool
instead of an int.
- The decimal_from_integral and decimal_from_doublest routines take
an struct value as input. This is not really appropriate at the low
level the DFP routines sit, so this replaced them with new routines
decimal_from_longest / decimal_from_ulongest / decimal_from_doublest
that operate on contents instead.
- To mirror the decimal_from_[u]longest, a new decimal_to_longest
routine is added as well, which can be used in unpack_long to
avoid an unnecessary conversion via DOUBLEST.
Note that the decimal_from_longest / decimal_from_ulongest routines
are actually more powerful than decimal_from_integral: the old routine
would only accept integer *types* of at most four bytes size, while
the new routines accept all integer *values* that fit in an [u]int32_t,
no matter which type they came from. The DFP tests are updated to
allow for this larger range of integers that can be converted.
gdb/ChangeLog:
2017-10-05 Ulrich Weigand <uweigand@de.ibm.com>
* dfp.h (MAX_DECIMAL_STRING): Move to dfp.c.
(decimal_to_string): Return std::string object.
(decimal_from_string): Accept std::string object. Return bool.
(decimal_from_integral, decimal_from_doublest): Remove.
(decimal_from_longest): Add prototype.
(decimal_from_ulongest): Likewise.
(decimal_to_longest): Likewise.
(decimal_from_doublest): Likewise.
* dfp.c: Do not include "gdbtypes.h" or "value.h".
(MAX_DECIMAL_STRING): Move here.
(decimal_to_string): Return std::string object.
(decimal_from_string): Accept std::string object. Return bool.
(decimal_from_integral): Remove, replace by ...
(decimal_from_longest, decimal_from_ulongest): ... these new functions.
(decimal_to_longest): New function.
(decimal_from_floating): Remove, replace by ...
(decimal_from_doublest): ... this new function.
(decimal_to_doublest): Update to new decimal_to_string interface.
* value.c (unpack_long): Use decimal_to_longest.
* valops.c (value_cast): Use decimal_from_doublest instead of
decimal_from_floating. Use decimal_from_[u]longest isntead of
decimal_from_integral.
* valarith.c (value_args_as_decimal): Likewise.
* valprint.c (print_decimal_floating): Update to new
decimal_to_string interface.
* printcmd.c (printf_decfloat): Likewise.
* c-exp.y (parse_number): Update to new decimal_from_string interface.
gdb/testsuite/ChangeLog:
2017-10-05 Ulrich Weigand <uweigand@de.ibm.com>
* gdb.base/dfp-exprs.exp: Update tests to larger range of supported
integer-to-dfp conversion.
* gdb.base/dfp-test.exp: Likewise.
2017-10-05 19:14:08 +02:00
|
|
|
gdb_test "p 1.2dd + 2ll" "= 3.2"
|
|
|
|
gdb_test "p 1.2dd + 2147483648ll" "Conversion of large integer to a decimal floating type is not supported."
|
|
|
|
gdb_test "p 1.2dd + 2147483648ull" "= 2147483649.2"
|
|
|
|
gdb_test "p 1.2dd + 4294967296ull" "Conversion of large integer to a decimal floating type is not supported."
|
2008-01-07 23:34:49 +01:00
|
|
|
|
|
|
|
# Reject operation with DFP and Binary FP
|
|
|
|
gdb_test "p 1.2df + 1.2f" "Mixing decimal floating types with other floating types is not allowed."
|
|
|
|
|
|
|
|
# Test other operations with DFP operands
|
|
|
|
gdb_test "p !0.df" " = 1"
|
|
|
|
gdb_test "p !0.dd" " = 1"
|
|
|
|
gdb_test "p !0.dl" " = 1"
|
|
|
|
gdb_test "p !0.5df" " = 0"
|
|
|
|
gdb_test "p !0.5dd" " = 0"
|
|
|
|
gdb_test "p !0.5dl" " = 0"
|
|
|
|
|
|
|
|
gdb_test "p 1.2df == 1.2df" " = 1"
|
|
|
|
gdb_test "p 1.2df == 1.2dd" " = 1"
|
|
|
|
gdb_test "p 1.2df == 1.2dl" " = 1"
|
|
|
|
gdb_test "p 1.2dd == 1.2df" " = 1"
|
|
|
|
gdb_test "p 1.2dd == 1.2dl" " = 1"
|
|
|
|
gdb_test "p 1.2dl == 1.2df" " = 1"
|
|
|
|
gdb_test "p 1.2dl == 1.2dd" " = 1"
|
|
|
|
gdb_test "p 1.2df == 1.3df" " = 0"
|
|
|
|
gdb_test "p 1.2df == 1.3dd" " = 0"
|
|
|
|
gdb_test "p 1.2df == 1.3dl" " = 0"
|
|
|
|
gdb_test "p 1.2dd == 1.3df" " = 0"
|
|
|
|
gdb_test "p 1.2dd == 1.3dl" " = 0"
|
|
|
|
gdb_test "p 1.2dl == 1.3df" " = 0"
|
|
|
|
gdb_test "p 1.2dl == 1.3dd" " = 0"
|
|
|
|
|
|
|
|
gdb_test "p +1.2df" " = 1.2"
|
|
|
|
gdb_test "p +1.2dd" " = 1.2"
|
|
|
|
gdb_test "p +1.2dl" " = 1.2"
|
|
|
|
|
|
|
|
gdb_test "p 1.2df < 1.3df" " = 1"
|
|
|
|
gdb_test "p 1.2df < 1.3dd" " = 1"
|
|
|
|
gdb_test "p 1.2dl < 1.3df" " = 1"
|
|
|
|
gdb_test "p 1.2dd < 1.3dd" " = 1"
|
|
|
|
gdb_test "p 1.2dd < 1.3dl" " = 1"
|
|
|
|
gdb_test "p 1.2dl < 1.3dl" " = 1"
|
|
|
|
gdb_test "p 1.2dl < 1.3df" " = 1"
|
|
|
|
gdb_test "p 1.2df > 1" " = 1"
|
|
|
|
gdb_test "p 1.2dl > 2" " = 0"
|
|
|
|
gdb_test "p 2 > 1.2dd" " = 1"
|
|
|
|
gdb_test "p 2 > 3.1dl" " = 0"
|
|
|
|
}
|
2007-10-25 20:09:45 +02:00
|
|
|
|
2008-01-07 23:34:49 +01:00
|
|
|
proc test_dfp_conversions {} {
|
|
|
|
# Test cast to and from DFP values, and between DFPs of different sizes
|
2007-10-25 20:09:45 +02:00
|
|
|
|
2008-01-07 23:34:49 +01:00
|
|
|
gdb_test "p (float) -0.1df" " = -0.(0999.*|1000.*)"
|
|
|
|
gdb_test "p (int) 8.3dd" " = 8"
|
|
|
|
gdb_test "p (_Decimal64) 3.1" " = 3.(0999.*|1000.*)"
|
|
|
|
gdb_test "p (_Decimal128) 3.7df" " = 3.7"
|
|
|
|
gdb_test "p (_Decimal32) 4" " = 4"
|
2007-10-25 20:09:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Start with a fresh gdb.
|
|
|
|
|
|
|
|
gdb_exit
|
|
|
|
gdb_start
|
|
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
|
|
|
|
|
|
|
test_dfp_literals_accepted
|
|
|
|
test_dfp_arithmetic_expressions
|
2008-01-07 23:34:49 +01:00
|
|
|
test_dfp_conversions
|