Fix a regression introduced by change #21694 on sprintf()
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 28 Nov 2003 22:38:40 +0000 (22:38 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Fri, 28 Nov 2003 22:38:40 +0000 (22:38 +0000)
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.
p4raw-link: @21694 on //depot/perl: 4151a5feffa8bdd67c09edf6ade78431e8079f67

p4raw-id: //depot/perl@21800

MANIFEST
sv.c
t/op/sprintf2.t [new file with mode: 0644]

index cd3c05a..7dd4edf 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -2796,6 +2796,7 @@ t/op/sort.t                       See if sort works
 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
diff --git a/sv.c b/sv.c
index 3ff4bb0..16c7bbc 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -8630,6 +8630,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
        }
     }
 
+#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 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
                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 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
            }
        }
     }
+#endif /* !USE_LONG_DOUBLE */
 
     if (!args && svix < svmax && DO_UTF8(*svargs))
        has_utf8 = TRUE;
@@ -9359,7 +9361,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
            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) {
diff --git a/t/op/sprintf2.t b/t/op/sprintf2.t
new file mode 100644 (file)
index 0000000..fef25f1
--- /dev/null
@@ -0,0 +1,20 @@
+#!./perl -w
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+    require './test.pl';
+}   
+
+plan tests => 2;
+
+is(
+    sprintf("%.40g ",0.01),
+    sprintf("%.40g", 0.01)." ",
+    q(the sprintf "%.<number>g" optimization)
+);
+is(
+    sprintf("%.40f ",0.01),
+    sprintf("%.40f", 0.01)." ",
+    q(the sprintf "%.<number>f" optimization)
+);