[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #16 from Jerry DeLisle 2011-05-02 19:05:51 UTC --- Yes and we are honing in on it now. I suspected the RD on negatives. Just did not have time to check it yet. Thansk for continued examples.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 Thomas Henlich changed: What|Removed |Added Attachment #24138|0 |1 is obsolete|| Attachment #24164|0 |1 is obsolete|| --- Comment #15 from Thomas Henlich 2011-05-02 13:48:02 UTC --- Created attachment 24165 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24165 More examples of up/down rounding bug. There is another issue here where rounding goes wrong: It seems all values greater than 0.0 and smaller than 0.1 are rounded incorrectly with ROUND=UP; all values smaller than 0.0 and greater than -0.1 are rounded incorrectly with ROUND=DOWN.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #14 from Thomas Henlich 2011-05-02 13:24:27 UTC --- Created attachment 24164 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24164 Revised patch including rounding down negative numbers Sorry, my bug report should have been more precisely: Invalid UP rounding of positive and DOWN rounding of negative numbers. The current patch does not address the second case.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #13 from Jerry DeLisle 2011-05-02 03:29:49 UTC --- Fixed on trunk
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #11 from Jerry DeLisle 2011-05-01 12:32:20 UTC --- Author: jvdelisle Date: Sun May 1 12:32:18 2011 New Revision: 173231 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173231 Log: 2011-05-01 Jerry DeLisle PR libgfortran/48787 * io/write_float.def (output_float): Gather up integer declarations and add new 'p' for scale factor. Use 'p' in place of the 'dtp' reference everywhere. For ROUND_UP scan the digit string and only perform rounding if something other than '0' is found. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/write_float.def
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #12 from Jerry DeLisle 2011-05-01 12:37:07 UTC --- Author: jvdelisle Date: Sun May 1 12:37:05 2011 New Revision: 173233 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173233 Log: 2011-05-01 Jerry DeLisle PR libgfortran/48787 * gfortran.dg/round_3.f08: Add more checks. Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/round_3.f08
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #10 from Thomas Henlich 2011-04-30 15:56:35 UTC --- The start to scan is the digit corresponding to d+1. e.g. PRINT "(RU,F0.4)", .162548148 -> .1626 because48148 > 0 PRINT "(RU,F0.4)", 3.1415926536 -> 3.1416 because926536 > 0 PRINT "(RU,F0.1)", 2.50 -> 2.5 because0 = 0
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #9 from Jerry DeLisle 2011-04-30 12:43:47 UTC --- The trick here is figuring out the limits of the scan on the left end of the string. We can have things like. 2345638418 ^ and we want to start or stop the scan right after the '6'. Other cases may want to set the limit at the third position. We know where the right end of the scan starts.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #8 from Thomas Henlich 2011-04-30 11:58:36 UTC --- > I think for rounding up we need to test if ALL the cut off digits are zeros. One more thought: It might be (statistically) faster to scan the digits from last to first than vice versa. There are many more internal values which don't have an exact decimal representation than those that have. The quantization error will show itself in the last digits. E.g. print "(f0.40)", 0.1_16 !> .10048148
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #7 from jvdelisle at frontier dot com 2011-04-29 15:55:14 UTC --- On 04/29/2011 12:14 AM, thenlich at users dot sourceforge.net wrote: ---snip--- > > The suggested patch fails on examples in this test where d>0. > > I think for rounding up we need to test if ALL the cut off digits are zeros. > I have committed the whole ball of wax. I really needed to do this because things were stacking up. I considered that there may be a need to test for all zeros. That will be easy to do. So a follow-on patch can be done soon. Thanks for the test cases I will will keep working these off as best I can.
Re: [Bug libfortran/48787] Invalid UP rounding with F editing
On 04/29/2011 12:14 AM, thenlich at users dot sourceforge.net wrote: ---snip--- The suggested patch fails on examples in this test where d>0. I think for rounding up we need to test if ALL the cut off digits are zeros. I have committed the whole ball of wax. I really needed to do this because things were stacking up. I considered that there may be a need to test for all zeros. That will be easy to do. So a follow-on patch can be done soon. Thanks for the test cases I will will keep working these off as best I can.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #6 from Jerry DeLisle 2011-04-29 15:09:03 UTC --- Author: jvdelisle Date: Fri Apr 29 15:08:57 2011 New Revision: 173168 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173168 Log: 2011-04-29 Jerry DeLisle PR libgfortran/48488 PR libgfortran/48602 PR libgfortran/48615 PR libgfortran/48684 PR libgfortran/48787 * gfortran.dg/fmt_g.f: Adjust test. * gfortran.dg/fmt_g0_1.f08: Adjust test. * gfortran.dg/round_3.f08: New test. * gfortran.dg/namelist_print_1.f: Adjust test. * gfortran.dg/char4_iunit_1.f03: Adjust test. * gfortran.dg/f2003_io_5.f03: Adjust test. * gfortran.dg/coarray_15.f90: Adjust test. * gfortran.dg/namelist_65.f90: Adjust test. * gfortran.dg/fmt_cache_1.f: Adjust test. * gfortran.dg/char4_iunit_2.f03: Adjust test. * gfortran.dg/real_const_3.f90: Adjust test. Added: trunk/gcc/testsuite/gfortran.dg/round_3.f08 Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/char4_iunit_1.f03 trunk/gcc/testsuite/gfortran.dg/char4_iunit_2.f03 trunk/gcc/testsuite/gfortran.dg/coarray_15.f90 trunk/gcc/testsuite/gfortran.dg/f2003_io_5.f03 trunk/gcc/testsuite/gfortran.dg/fmt_cache_1.f trunk/gcc/testsuite/gfortran.dg/fmt_g.f trunk/gcc/testsuite/gfortran.dg/fmt_g0_1.f08 trunk/gcc/testsuite/gfortran.dg/namelist_65.f90 trunk/gcc/testsuite/gfortran.dg/namelist_print_1.f trunk/gcc/testsuite/gfortran.dg/real_const_3.f90
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #5 from Jerry DeLisle 2011-04-29 14:56:08 UTC --- Author: jvdelisle Date: Fri Apr 29 14:56:02 2011 New Revision: 173166 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=173166 Log: 2011-04-29 Jerry DeLisle Janne Blomqvist PR libgfortran/48488 PR libgfortran/48602 PR libgfortran/48615 PR libgfortran/48684 PR libgfortran/48787 * io/write.c (write_d, write_e, write_f, write_en, write_es): Add precision compemsation parameter to call. (set_fnode_default): Adjust default widths to assure round trip on write and read. (write_real): Adjust call to write_float. (write_real_g0): Calculate compensation for extra precision and adjust call to write_float. * io/write_float.def (output_float_FMT_G_): Use volatile rather than asm volatile to avoid optimization issue. Correctly calculate the number of blanks (nb) to be appended and simplify calculation logic. (write_float): Increase MIN_FIELD_WIDTH by one to accomodate the new default widths. Eliminate the code that attempted to reduce the the precision used in later sprintf functions. Add call parameter to compensate for extra precision. Modified: trunk/libgfortran/ChangeLog trunk/libgfortran/io/write.c trunk/libgfortran/io/write_float.def
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 Thomas Henlich changed: What|Removed |Added Attachment #24120|0 |1 is obsolete|| --- Comment #4 from Thomas Henlich 2011-04-29 07:12:10 UTC --- Created attachment 24138 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24138 Updated test for cases where d>0 The suggested patch fails on examples in this test where d>0. I think for rounding up we need to test if ALL the cut off digits are zeros.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #3 from Jerry DeLisle 2011-04-29 05:59:45 UTC --- A tentative patch: Index: write_float.def === --- write_float.def(revision 172909) +++ write_float.def(working copy) @@ -289,8 +289,9 @@ } else if (nbefore + nafter < ndigits) { - ndigits = nbefore + nafter; - i = ndigits; + i = ndigits = nbefore + nafter; + if (d == 0 && digits[1] == '0') +goto skip; if (digits[i] >= rchar) { /* Propagate the carry. */
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 --- Comment #2 from Thomas Henlich 2011-04-28 06:41:27 UTC --- Created attachment 24120 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24120 Testcase for F, E, G editing Bug also applies to E and G editing with non-zero scale factor.
[Bug libfortran/48787] Invalid UP rounding with F editing
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48787 Jerry DeLisle changed: What|Removed |Added AssignedTo|unassigned at gcc dot |jvdelisle at gcc dot |gnu.org |gnu.org --- Comment #1 from Jerry DeLisle 2011-04-28 04:09:10 UTC --- Found the spot, thanks for report. I should have a fix soon.