Exemplo n.º 1
0
 public static object Power(double x, object other)
 {
     if (other is int)
     {
         return(Power(x, ((int)other)));
     }
     if (other is long)
     {
         return(Power(x, ((long)other)));
     }
     if (other is Complex64)
     {
         return(ComplexOps.Power(x, ((Complex64)other)));
     }
     if (other is double)
     {
         return(Power(x, ((double)other)));
     }
     if (other is BigInteger)
     {
         return(Power(x, ((BigInteger)other)));
     }
     if (other is bool)
     {
         return(Power(x, (bool)other ? 1 : 0));
     }
     if (other is float)
     {
         return(Power(x, ((float)other)));
     }
     if (other is ExtensibleFloat)
     {
         return(Power(x, ((ExtensibleFloat)other).value));
     }
     if (other is ExtensibleInt)
     {
         return(Power(x, ((ExtensibleInt)other).value));
     }
     if (other is ExtensibleComplex)
     {
         return(ComplexOps.Power(x, ((ExtensibleComplex)other).value));
     }
     if (other is byte)
     {
         return(Power(x, (int)((byte)other)));
     }
     return(Ops.NotImplemented);
 }
Exemplo n.º 2
0
 public static object Power(int x, object other)
 {
     if (other is int)
     {
         return(Power(x, (int)other));
     }
     else if (other is BigInteger)
     {
         BigInteger lexp = (BigInteger)other;
         int        iexp;
         if (lexp.AsInt32(out iexp))
         {
             return(Power(x, iexp));
         }
         else
         {
             if (x == 0)
             {
                 return(0);
             }
             if (x == 1)
             {
                 return(1);
             }
             throw Ops.ValueError("number too big");
         }
     }
     else if (other is long)
     {
         long lexp = (long)other;
         int  iexp = (int)lexp;
         if (lexp == iexp)
         {
             return(Power(x, iexp));
         }
         else
         {
             if (x == 0)
             {
                 return(0);
             }
             if (x == 1)
             {
                 return(1);
             }
             throw Ops.ValueError("Number too big");
         }
     }
     else if (other is double)
     {
         return(FloatOps.Power(x, (double)other));
     }
     else if (other is bool)
     {
         return(Power(x, (bool)other ? 1 : 0));
     }
     else if (other is float)
     {
         return(FloatOps.Power(x, (float)other));
     }
     else if (other is Complex64)
     {
         return(ComplexOps.Power(x, other));
     }
     else if (other is byte)
     {
         return(Power(x, (int)(byte)other));
     }
     else if (other is ExtensibleInt)
     {
         return(Power(x, ((ExtensibleInt)other).value));
     }
     else if (other is ExtensibleFloat)
     {
         return(FloatOps.Power(x, ((ExtensibleFloat)other).value));
     }
     else if (other is ExtensibleComplex)
     {
         return(ComplexOps.Power(x, ((ExtensibleComplex)other).value));
     }
     return(Ops.NotImplemented);
 }