diff mbox

[libgfortran] PR47567 Wrong output for small absolute values with F editing

Message ID 4D4D773F.6030703@frontier.com
State New
Headers show

Commit Message

Jerry DeLisle Feb. 5, 2011, 4:13 p.m. UTC
Hi folks,

The attached patch fixes the concerns with where and where not to emit "*" with 
small values and no width or small width specified.

Regression tested on x86-64.

I will dejagnu the test case attached.

OK for Trunk?

Regards,

Jerry

2011-02-05  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR libgfortran/47567
	* io/write_float.def (output_float): Eliminate some redundant code.
	Adjust width for case of F0.X for values of zero and all other values.
	Expand cases where '*' is set to give cleaner results.

Comments

Janne Blomqvist Feb. 5, 2011, 5:33 p.m. UTC | #1
On Sat, Feb 5, 2011 at 18:13, Jerry DeLisle <jvdelisle@frontier.com> wrote:
> Hi folks,
>
> The attached patch fixes the concerns with where and where not to emit "*"
> with small values and no width or small width specified.
>
> Regression tested on x86-64.
>
> I will dejagnu the test case attached.
>
> OK for Trunk?
>
> Regards,
>
> Jerry
>
> 2011-02-05  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
>
>        PR libgfortran/47567
>        * io/write_float.def (output_float): Eliminate some redundant code.
>        Adjust width for case of F0.X for values of zero and all other
> values.
>        Expand cases where '*' is set to give cleaner results.
>

Ok, thanks. I suppose it could be argued that F1.0 should always print
*, if one wanted to be really picky.
diff mbox

Patch

Index: write_float.def
===================================================================
--- write_float.def	(revision 169821)
+++ write_float.def	(working copy)
@@ -111,14 +111,12 @@  output_float (st_parameter_dt *dtp, const fnode *f
   if (zero_flag)
     {
       e = 0;
-      if (compile_options.sign_zero == 1)
-	sign = calculate_sign (dtp, sign_bit);
-      else
+      if (compile_options.sign_zero != 1)
 	sign = calculate_sign (dtp, 0);
 
       /* Handle special cases.  */
       if (w == 0)
-	w = d + 2;
+	w = d + 1;
 
       /* For this one we choose to not output a decimal point.
 	 F95 10.5.1.2.1  */
@@ -138,7 +136,6 @@  output_float (st_parameter_dt *dtp, const fnode *f
 	  *out = '0';
 	  return SUCCESS;
 	}
-	      
     }
 
   /* Normalize the fractional component.  */
@@ -417,7 +414,10 @@  output_float (st_parameter_dt *dtp, const fnode *f
 
   /* Pick a field size if none was specified.  */
   if (w <= 0)
-    w = nbefore + nzero + nafter + (sign != S_NONE ? 2 : 1);
+    {
+      w = nbefore + nzero + nafter + (sign != S_NONE ? 2 : 1);
+      w = w == 1 ? 2 : w;
+    }
   
   /* Work out how much padding is needed.  */
   nblanks = w - (nbefore + nzero + nafter + edigits + 1);
@@ -436,7 +436,7 @@  output_float (st_parameter_dt *dtp, const fnode *f
     return FAILURE;
 
   /* Check the value fits in the specified field width.  */
-  if (nblanks < 0 || edigits == -1)
+  if (nblanks < 0 || edigits == -1 || w == 1 || (w == 2 && sign != S_NONE))
     {
       if (unlikely (is_char4_unit (dtp)))
 	{