From: Gurusamy Sarathy Date: Fri, 17 Dec 1999 05:37:51 +0000 (+0000) Subject: fix bug when one of the operands is +0E+0 (from Ronald J Kimball X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5dce09b1b12bc4dff9713d5dbb5291ac967ccf63;p=p5sagit%2Fp5-mst-13.2.git fix bug when one of the operands is +0E+0 (from Ronald J Kimball ) p4raw-id: //depot/perl@4685 --- diff --git a/lib/Math/BigFloat.pm b/lib/Math/BigFloat.pm index 8aa6a66..1a9195e 100644 --- a/lib/Math/BigFloat.pm +++ b/lib/Math/BigFloat.pm @@ -240,12 +240,13 @@ sub fcmp #(fnum_str, fnum_str) return cond_code if ($x eq "NaN" || $y eq "NaN") { undef; } else { + local($xm,$xe,$ym,$ye) = split('E', $x."E$y"); + if ($xm eq '+0' || $ym eq '+0') { + return $xm <=> $ym; + } ord($y) <=> ord($x) - || - ( local($xm,$xe,$ym,$ye) = split('E', $x."E$y"), - (($xe <=> $ye) * (substr($x,$[,1).'1') - || Math::BigInt::cmp($xm,$ym)) - ); + || ($xe <=> $ye) * (substr($x,$[,1).'1') + || Math::BigInt::cmp($xm,$ym); } } diff --git a/t/lib/bigfltpm.t b/t/lib/bigfltpm.t index 42cd958..4cfd36e 100755 --- a/t/lib/bigfltpm.t +++ b/t/lib/bigfltpm.t @@ -9,7 +9,7 @@ use Math::BigFloat; $test = 0; $| = 1; -print "1..358\n"; +print "1..362\n"; while () { chop; if (s/^&//) { @@ -41,15 +41,15 @@ while () { $try .= "0+\$x->fsqrt;"; } else { $try .= "\$y = new Math::BigFloat \"$args[1]\";"; - if ($f eq fcmp){ + if ($f eq "fcmp") { $try .= "\$x <=> \$y;"; - }elsif ($f eq fadd){ + } elsif ($f eq "fadd") { $try .= "\$x + \$y;"; - }elsif ($f eq fsub){ + } elsif ($f eq "fsub") { $try .= "\$x - \$y;"; - }elsif ($f eq fmul){ + } elsif ($f eq "fmul") { $try .= "\$x * \$y;"; - }elsif ($f eq fdiv){ + } elsif ($f eq "fdiv") { $try .= "\$x / \$y;"; } else { warn "Unknown op"; } } @@ -271,6 +271,10 @@ abc:+0: +1:-1:1 -1:-1:0 +1:+1:0 +-1.1:0:-1 ++0:-1.1:1 ++1.1:+0:1 ++0:+1.1:-1 +123:+123:0 +123:+12:1 +12:+123:-1