Changeset 7e0aa3 in git


Ignore:
Timestamp:
Dec 9, 2005, 10:12:53 AM (18 years ago)
Author:
Wilfred Pohl <pohl@…>
Branches:
(u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
Children:
f0d1e8ff9bbee3ecdc215a126853bef13df180db
Parents:
5282ba08768ae8313d001b2e19108ef82902d2a9
Message:
power


git-svn-id: file:///usr/local/Singular/svn/trunk@8838 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/canonicalform.cc

    r5282ba r7e0aa3  
    11/* emacs edit mode for this file is -*- C++ -*- */
    2 /* $Id: canonicalform.cc,v 1.36 2005-12-09 08:35:37 Singular Exp $ */
     2/* $Id: canonicalform.cc,v 1.37 2005-12-09 09:12:53 pohl Exp $ */
    33
    44#include <config.h>
     
    16931693{
    16941694    ASSERT( n >= 0, "illegal exponent" );
    1695     if ( f == 0 )
    1696         return 0;
    1697     else  if ( f == 1 )
     1695    if ( f.isZero() || f.isOne() )
    16981696        return f;
    1699     else  if ( f == -1 ) {
     1697    else  if ( (-f).isOne() ) {
    17001698        if ( n % 2 == 0 )
    1701             return 1;
     1699            return -f;
    17021700        else
    1703             return -1;
     1701            return f;
    17041702    }
    17051703    else  if ( n == 0 )
    1706         return 1;
     1704        return f.genOne();
    17071705    //else if (f.inGF())
    17081706    //{
    17091707    //}
    17101708    else {
    1711         CanonicalForm result = f;
    1712         for ( int i = 1; i < n; i++ )
    1713             result *= f;
    1714         return result;
     1709        CanonicalForm g,h;
     1710        h=f;
     1711        while(n%2==0)
     1712        {
     1713          h*=h;
     1714          n/=2;
     1715        }
     1716        g=h;
     1717        while(1)
     1718        {
     1719          n/=2;
     1720          if(n==0)
     1721            return g;
     1722          h*=h;
     1723          if(n%2!=0) g*=h;
     1724        }
    17151725    }
    17161726}
Note: See TracChangeset for help on using the changeset viewer.