ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl5-porters
perl5-porters
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved