]> www.ginac.de Git - ginac.git/commitdiff
- matrix::pow(): omit last big multiplication if it's not needed.
authorRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Thu, 7 Jun 2001 22:26:16 +0000 (22:26 +0000)
committerRichard Kreckel <Richard.Kreckel@uni-mainz.de>
Thu, 7 Jun 2001 22:26:16 +0000 (22:26 +0000)
ginac/matrix.cpp

index 9998a3918ab7d50eb3c4685aad29b952db04c392..872b8e006012c3a4ecf6279cf315ed8c34e5f793 100644 (file)
@@ -638,8 +638,8 @@ matrix matrix::pow(const ex & expn) const
                        for (unsigned r=0; r<row; ++r)
                                result(r,r) = _ex1();
                        numeric b(1);
                        for (unsigned r=0; r<row; ++r)
                                result(r,r) = _ex1();
                        numeric b(1);
-                       // this loop computes the representation of k in base 2 and multiplies
-                       // the factors whenever needed:
+                       // this loop computes the representation of k in base 2 and
+                       // multiplies the factors whenever needed:
                        while (b.compare(k)<=0) {
                                b *= numeric(2);
                                numeric r(mod(k,b));
                        while (b.compare(k)<=0) {
                                b *= numeric(2);
                                numeric r(mod(k,b));
@@ -647,7 +647,8 @@ matrix matrix::pow(const ex & expn) const
                                        k -= r;
                                        result = result.mul(prod);
                                }
                                        k -= r;
                                        result = result.mul(prod);
                                }
-                               prod = prod.mul(prod);
+                               if (b.compare(k)<=0)
+                                       prod = prod.mul(prod);
                        }
                        return result;
                }
                        }
                        return result;
                }