Re: sprintf %.g broken in bleadperl
by Rafael Garcia-Suarez other posts by this author
Nov 28 2003 11:59PM messages near this date
Re: sprintf %.g broken in bleadperl
|
Re: sprintf %.g broken in bleadperl
Enache Adrian wrote:
> On Mon, Nov 24, 2003 a.d., Yitzchak Scott-Thoennes wrote:
> > If NV is long double, Gconvert is supposed to take long doubles if
> > Configure can figure out how (e.g. qgcvt or sprintf "%.*llg"). If
> > sprintf is not used, it is possible that whatever is used end up
> > converting differently than sprintf would have. Would this explain
> > the results here? What is perl -V:d_Gconvert?
>
> No Gconvert is just fine. (it's qgcvt() here).
> The bug is:
>
> 1. classical cast & punch.
> Gconvert((double)nv, digits, 0, ebuf);
> nv is a long double, and Gconvert takes a long double argument too.
>
> 2. the new %.g special case avoids all the stuff in sv.c:9227 and
> below, which is setting the correct size to use.
>
> I don't see how to fix 2) in the new patch :-)
/me neither. I've thus applied the fix below : (but better tuits welcome)
Change 21800 by rgs@rgs-home on 2003/11/28 22:38:40
Fix a regression introduced by change #21694 on sprintf()
with long doubles, by disabling the specific optimisation
path in this case ; remove a unnecessary cast ; add a new
test file for miscellaneous sprintf() test that don't fit
in the t/op/sprintf.t framework.
Affected files ...
... //depot/perl/MANIFEST#1110 edit
... //depot/perl/sv.c#697 edit
... //depot/perl/t/op/sprintf2.t#1 add
Differences ...
==== //depot/perl/MANIFEST#1110 (text) ====
@@ -2796,6 +2796,7 @@
t/op/splice.t See if splice works
t/op/split.t See if split works
t/op/sprintf.t See if sprintf works
+t/op/sprintf2.t See if sprintf works
t/op/srand.t See if srand works
t/op/stash.t See if %:: stashes work
t/op/stat.t See if stat works
==== //depot/perl/sv.c#697 (text) ====
@@ -8630,6 +8630,7 @@
}
}
+#ifndef USE_LONG_DOUBLE
/* special-case "%.<number> [gf]" */
if ( patlen <= 5 && pat[0] == '%' && pat[1] == '.'
&& (pat[patlen-1] == 'g' || pat[patlen-1] == 'f') ) {
@@ -8650,7 +8651,7 @@
return;
if (*pp == 'g') {
if (digits < sizeof(ebuf) - NV_DIG - 10) { /* 0, point, slack */
- Gconvert((double)nv, digits, 0, ebuf);
+ Gconvert(nv, digits, 0, ebuf);
sv_catpv(sv, ebuf);
if (*ebuf) /* May return an empty string for digits==0 */
return;
@@ -8665,6 +8666,7 @@
}
}
}
+#endif /* !USE_LONG_DOUBLE */
if (!args && svix < svmax && DO_UTF8(*svargs))
has_utf8 = TRUE;
@@ -9359,7 +9361,7 @@
if ( !(width || left || plus || alt) && fill != '0'
&& has_precis && intsize != 'q' ) { /* Shortcuts */
if ( c == 'g') {
- Gconvert((double)nv, precis, 0, PL_efloatbuf);
+ Gconvert(nv, precis, 0, PL_efloatbuf);
if (*PL_efloatbuf) /* May return an empty string for digits==0 */
goto float_converted;
} else if ( c == 'f' && !precis) {
Thread:
Enache Adrian
Rafael Garcia-Suarez
Ilya Zakharevich
Yitzchak Scott-Thoennes
Enache Adrian
Rafael Garcia-Suarez
Ilya Zakharevich
Yitzchak Scott-Thoennes
Ilya Zakharevich
Andy Lester
|