This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
hexfp: printf %a for negative zero.
authorJarkko Hietaniemi <jhi@iki.fi>
Sat, 28 Nov 2015 22:45:19 +0000 (17:45 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 29 Nov 2015 03:05:34 +0000 (22:05 -0500)
sv.c
t/op/sprintf2.t

diff --git a/sv.c b/sv.c
index 8fad8be..53133b9 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12363,7 +12363,9 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
 #  endif
 #endif
 
-                if (fv < 0)
+                if (fv < 0
+                    || Perl_signbit(fv)
+                  )
                     *p++ = '-';
                 else if (plus)
                     *p++ = plus;
index a898df1..6aa994c 100644 (file)
@@ -243,7 +243,7 @@ if ($Config{nvsize} == 8 &&
     print "# no hexfloat tests\n";
 }
 
-plan tests => 1408 + ($Q ? 0 : 12) + @hexfloat + 6;
+plan tests => 1408 + ($Q ? 0 : 12) + @hexfloat + 8;
 
 use strict;
 use Config;
@@ -677,3 +677,10 @@ SKIP: {
     like(sprintf("%La\n", (2**1023) + (2**-1074)),
          qr/^0x1.0{524}8p\+1023$/);
 }
+
+SKIP: {
+    skip("negative zero not available\n", 2)
+        unless sprintf('%+f', -0.0) =~ /^-0/;
+    is(sprintf("%a", -0.0), "-0x0p+0", "negative zero");
+    is(sprintf("%+a", -0.0), "-0x0p+0", "negative zero");
+}