aboutsummaryrefslogtreecommitdiff
path: root/gcc/dfp.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-03-11 09:33:52 +0100
committerJakub Jelinek <jakub@redhat.com>2020-03-11 09:33:52 +0100
commit312992f5a07ca25f94d538b08401789c2c764293 (patch)
tree5a36177be134d3b68ae168cd0c6f05442a373e7d /gcc/dfp.c
parent05ac4d9c7b336e30413dd80c3630981151499f9e (diff)
downloadgcc-312992f5a07ca25f94d538b08401789c2c764293.zip
gcc-312992f5a07ca25f94d538b08401789c2c764293.tar.gz
gcc-312992f5a07ca25f94d538b08401789c2c764293.tar.bz2
dfp: Fix decimal_to_binary [PR94111]
As e.g. decimal_from_decnumber shows, the REAL_VALUE_TYPE representation contains a decimal128 embedded in ->sig only if it is rvc_normal, for other kinds like rvc_inf or rvc_nan, ->sig is ignored and everything is contained in the REAL_VALUE_TYPE flags (cl, sign, signalling and decimal). decimal_to_binary which is used when folding a decimal{32,64,128} constant to a binary floating point type ignores this and thus folds infinities and NaNs into +0.0. The following patch fixes that by only doing that for rvc_normal. Similarly to the binary to decimal folding, it goes through a string, in order to e.g. deal with canonical NaN mantissas, or binary float formats that don't support infinities and/or NaNs. 2020-03-11 Jakub Jelinek <jakub@redhat.com> PR middle-end/94111 * dfp.c (decimal_to_binary): Only use decimal128ToString if from->cl is rvc_normal, otherwise use real_to_decimal to print the number to string. * gcc.dg/dfp/pr94111.c: New test.
Diffstat (limited to 'gcc/dfp.c')
-rw-r--r--gcc/dfp.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/dfp.c b/gcc/dfp.c
index 688fab4..fef39a5 100644
--- a/gcc/dfp.c
+++ b/gcc/dfp.c
@@ -342,9 +342,13 @@ decimal_to_binary (REAL_VALUE_TYPE *to, const REAL_VALUE_TYPE *from,
const real_format *fmt)
{
char string[256];
- const decimal128 *const d128 = (const decimal128 *) from->sig;
-
- decimal128ToString (d128, string);
+ if (from->cl == rvc_normal)
+ {
+ const decimal128 *const d128 = (const decimal128 *) from->sig;
+ decimal128ToString (d128, string);
+ }
+ else
+ real_to_decimal (string, from, sizeof (string), 0, 1);
real_from_string3 (to, string, fmt);
}