/// <summary> /// e. g. Pow(2, 5) = 32 /// </summary> /// <param name="base"> /// The base of the exponential, base^power /// </param> /// <param name="power"> /// The power of the exponential, base^power /// </param> /// <returns></returns> public static ComplexNumber Pow(ComplexNumber @base, ComplexNumber power) { // TODO: make it more detailed (e. g. +oo ^ +oo = +oo) if (power.IsInteger()) { return(Functional.Downcast(Functional.BinaryIntPow(@base as ComplexNumber, power.AsInt())) as ComplexNumber); } if (power.IsRational() && ((power as RationalNumber).Denominator.Value).Abs() < 10) // there should be a minimal threshold to avoid long searches { return(Number.Pow(FindGoodRoot(@base, (power as RationalNumber).Denominator), (power as RationalNumber).Numerator)); } var baseCom = @base.AsComplexNumber(); var powerCom = power.AsComplexNumber(); if (baseCom.IsDefinite() && powerCom.IsDefinite()) { try { return(Functional.Downcast( Complex.Pow(baseCom.AsComplex(), powerCom.AsComplex()) ) as ComplexNumber); } catch (OverflowException) { return(RealNumber.NaN()); } } else { return(ComplexNumber.Indefinite(RealNumber.UndefinedState.NAN)); } }
/// <summary> /// e. g. Pow(2, 5) = 32 /// </summary> /// <param name="base"> /// The base of the exponential, base^power /// </param> /// <param name="power"> /// The power of the exponential, base^power /// </param> /// <returns></returns> public static ComplexNumber Pow(Number @base, Number power) { // TODO: make it more detailed (e. g. +oo ^ +oo = +oo) if (power.IsInteger()) { return(Functional.Downcast(Functional.BinaryIntPow(@base as ComplexNumber, power.AsInt())) as ComplexNumber); } var baseCom = @base.AsComplexNumber(); var powerCom = power.AsComplexNumber(); if (baseCom.IsDefinite() && powerCom.IsDefinite()) { try { return(Functional.Downcast( Complex.Pow(baseCom.AsComplex(), powerCom.AsComplex()) ) as ComplexNumber); } catch (OverflowException) { return(RealNumber.NaN()); } } else { return(ComplexNumber.Indefinite(RealNumber.UndefinedState.NAN)); } }
/// <summary> /// e. g. Log(2, 32) = 5 /// </summary> /// <param name="base"> /// Log's base, log(base, x) is a number y such that base^y = x /// </param> /// <param name="x"> /// The number of which we want to get its base power /// </param> /// <returns></returns> public static ComplexNumber Log(RealNumber @base, Number x) { var baseCom = @base.AsComplexNumber(); var poweredCom = x.AsComplexNumber(); if (baseCom.IsDefinite() && poweredCom.IsDefinite()) { return(Functional.Downcast( Complex.Log(x.AsComplex(), @base.AsDouble()) ) as ComplexNumber); } else { return(ComplexNumber.Indefinite(RealNumber.UndefinedState.NAN)); } }