if( (expression1 instanceof jscicalc.Error) ||
(expression2 instanceof jscicalc.Error) ){
return new jscicalc.Error( "Power error" );
}
if( expression1 instanceof Complex ){
Complex v = (Complex)expression1;
if( expression2 instanceof Complex ){
Complex w = (Complex)expression2;
return v.pow( w ); // Complex power of Complex
}
Long l = v.isInteger();
if( l != null ){
long i = l;
if( i == 0 ){
return new jscicalc.Error( "Power error" );
} else if( i == 1 ){
return new Complex( 1 );
} else {
// integer expression1 as i
}
}
}
if( expression2 instanceof Complex ){
Complex w = (Complex)expression2;
Long m = w.isInteger();
if( m != null ){
long n = m;
// An integer power.
// Complex values of expression1 should be dealt with separately
if( n == 0 ) return new Complex( 1 );
else if( n == 1 ) return expression1;
else if( expression1 instanceof Power ){
Power q = (Power)expression1;
OObject o = null;
if( q.expression2 instanceof Expression ){
Product p = new Product( (Expression)(q.expression2), false );
o = p.multiply( new Complex( n ) );
} else if( q.expression2 instanceof Complex ){
o = q.expression2.multiply( new Complex( n ) );
} else
return new jscicalc.Error( "Power error" );
return new Power( q.expression1, o );
} else if( expression1 instanceof Product ){
Product p =(Product)expression1;