public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30992] New: Scaling error in decimal floating-point arithmetic blows conversions to integers
@ 2007-02-28 0:18 beebe at math dot utah dot edu
2007-03-02 3:42 ` [Bug middle-end/30992] " bje at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: beebe at math dot utah dot edu @ 2007-02-28 0:18 UTC (permalink / raw)
To: gcc-bugs
The function DFP_TO_INT() in gcc/config/dfp-bit.c has the job of converting
decimal floating point values to integers. It does this by calling the
decNumberFromString() function from the IBM decnumber library, but with an
incorrect argument. Fortunately, the patch is just one character:
% diff -c gcc-4.3-20070209/gcc/config/dfp-bit.c
/local/build/gcc/gcc-4.3-20070209/gcc/config
*** gcc-4.3-20070209/gcc/config/dfp-bit.c Mon Jan 29 16:01:35 2007
--- /local/build/gcc/gcc-4.3-20070209/gcc/config/dfp-bit.c Thu Feb 15
12:41:12 2007
***************
*** 450,456 ****
/* Rescale if the exponent is less than zero. */
decNumberToIntegralValue (&n2, &n1, &context);
/* Get a value to use for the quantize call. */
! decNumberFromString (&qval, (char *) "1.0", &context);
/* Force the exponent to zero. */
decNumberQuantize (&n1, &n2, &qval, &context);
/* Get a string, which at this point will not include an exponent. */
--- 450,456 ----
/* Rescale if the exponent is less than zero. */
decNumberToIntegralValue (&n2, &n1, &context);
/* Get a value to use for the quantize call. */
! decNumberFromString (&qval, (char *) "1.", &context);
/* Force the exponent to zero. */
decNumberQuantize (&n1, &n2, &qval, &context);
/* Get a string, which at this point will not include an exponent. */
Without this patch, the range of numbers that can be correctly converted
to integers is sharply reduced: most conversions of large values are
wrong. For example, the value x = 1048576.0DF is exactly representable
as a _Decimal32 value and as a 32-bit int, but the bad code converts it
to an int value of 2147483647, and a long int value of 9223372036854775807.
With the patch, integer conversions are now correct for all floating-point
values for which exact integer counterparts exist.
The bug exists in all versions of dfp-bit.c in gcc-4.2 and gcc-4.3
distributions.
As an aside, I now have a complete C99 library for decimal arithmetic
working under gcc-4.2 and gcc-4.3 on AMD64, thanks to the prototype
support for decimal arithmetic in gcc. I look forward to the decimal
support working on other platforms.
--
Summary: Scaling error in decimal floating-point arithmetic blows
conversions to integers
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: beebe at math dot utah dot edu
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30992
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/30992] Scaling error in decimal floating-point arithmetic blows conversions to integers
2007-02-28 0:18 [Bug c/30992] New: Scaling error in decimal floating-point arithmetic blows conversions to integers beebe at math dot utah dot edu
@ 2007-03-02 3:42 ` bje at gcc dot gnu dot org
2007-03-02 5:28 ` bje at gcc dot gnu dot org
2007-03-02 5:29 ` bje at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: bje at gcc dot gnu dot org @ 2007-03-02 3:42 UTC (permalink / raw)
To: gcc-bugs
--
bje at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |bje at gcc dot gnu dot org
|dot org |
Status|UNCONFIRMED |ASSIGNED
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2007-03-02 03:42:39
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30992
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/30992] Scaling error in decimal floating-point arithmetic blows conversions to integers
2007-02-28 0:18 [Bug c/30992] New: Scaling error in decimal floating-point arithmetic blows conversions to integers beebe at math dot utah dot edu
2007-03-02 3:42 ` [Bug middle-end/30992] " bje at gcc dot gnu dot org
@ 2007-03-02 5:28 ` bje at gcc dot gnu dot org
2007-03-02 5:29 ` bje at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: bje at gcc dot gnu dot org @ 2007-03-02 5:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from bje at gcc dot gnu dot org 2007-03-02 05:28 -------
Subject: Bug 30992
Author: bje
Date: Fri Mar 2 05:28:06 2007
New Revision: 122469
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122469
Log:
2007-03-02 Ben Elliston <bje@au.ibm.com>
PR 30992
* config/dfp-bit.c (DFP_TO_INT): Initialise qval with "1.".
Modified:
trunk/gcc/ChangeLog
trunk/gcc/config/dfp-bit.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30992
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/30992] Scaling error in decimal floating-point arithmetic blows conversions to integers
2007-02-28 0:18 [Bug c/30992] New: Scaling error in decimal floating-point arithmetic blows conversions to integers beebe at math dot utah dot edu
2007-03-02 3:42 ` [Bug middle-end/30992] " bje at gcc dot gnu dot org
2007-03-02 5:28 ` bje at gcc dot gnu dot org
@ 2007-03-02 5:29 ` bje at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: bje at gcc dot gnu dot org @ 2007-03-02 5:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from bje at gcc dot gnu dot org 2007-03-02 05:29 -------
Thanks also for the report on the C99 library!
--
bje at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30992
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-02 5:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-28 0:18 [Bug c/30992] New: Scaling error in decimal floating-point arithmetic blows conversions to integers beebe at math dot utah dot edu
2007-03-02 3:42 ` [Bug middle-end/30992] " bje at gcc dot gnu dot org
2007-03-02 5:28 ` bje at gcc dot gnu dot org
2007-03-02 5:29 ` bje at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).