fix bug when one of the operands is +0E+0 (from Ronald J Kimball
Gurusamy Sarathy [Fri, 17 Dec 1999 05:37:51 +0000 (05:37 +0000)]
<rjk@linguist.dartmouth.edu>)

p4raw-id: //depot/perl@4685

lib/Math/BigFloat.pm
t/lib/bigfltpm.t

index 8aa6a66..1a9195e 100644 (file)
@@ -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);
     }
 }
 
index 42cd958..4cfd36e 100755 (executable)
@@ -9,7 +9,7 @@ use Math::BigFloat;
 
 $test = 0;
 $| = 1;
-print "1..358\n";
+print "1..362\n";
 while (<DATA>) {
        chop;
        if (s/^&//) {
@@ -41,15 +41,15 @@ while (<DATA>) {
                    $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