From a3735af278478657c1b431b316723cd39532dc8f Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Mon, 12 Dec 2016 19:18:40 +0000 Subject: [PATCH] Fix stringif. of Complex failing on negative zero in img. part A negative zero goes through <0e0 conditional, at which point it ends up as -0 via p6box_s, concatenated with a '+'. 1/-0e0 == -Inf, so use that knowledge to figure out the sign of the zero. The nqp::abs_n() op seemed to have no point in there to me (and is slower), so I removed it. Fixes RT#130329: https://rt.perl.org/Ticket/Display.html?id=130329 --- src/core/Complex.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/Complex.pm b/src/core/Complex.pm index 13875440a8c..f8a1e6b8e99 100644 --- a/src/core/Complex.pm +++ b/src/core/Complex.pm @@ -48,10 +48,14 @@ my class Complex is Cool does Numeric { method Complex() { self } multi method Str(Complex:D:) { - my Str $i = nqp::isnanorinf($!im) ?? '\\i' !! 'i'; - $!im < 0e0 - ?? nqp::p6box_s($!re) ~ '-' ~ nqp::p6box_s(nqp::abs_n($!im)) ~ $i - !! nqp::p6box_s($!re) ~ '+' ~ nqp::p6box_s($!im) ~ $i; + nqp::p6box_s($!re) # real part + ~ ( # sign ('-' will be automagically given by p6box_s) + # second part is true if we have a negative zero + $!im < 0e0 || ( + ! $!im && nqp::islt_n(nqp::div_n(1e0, $!im), 0e0) + ) ?? '' !! '+' + ) ~ nqp::p6box_s($!im) # imaginary part + ~ (nqp::isnanorinf($!im) ?? '\\i' !! 'i'); # separate NaN/Inf with \ } multi method perl(Complex:D:) {