public static RealNumber operator /(RealNumber a, RealNumber b)
 {
     if (!a.IsDefinite() || !b.IsDefinite())
     {
         return(UndefinedStateSuperSwitch.Switch(
                    () => new RealNumber(UndefinedState.NAN),
                    () => new RealNumber(UndefinedState.NAN),
                    () => new RealNumber(UndefinedState.NAN),
                    () => new RealNumber(UndefinedState.NAN),
                    () => b.Value >= 0 ? new RealNumber(UndefinedState.POSITIVE_INFINITY) : new RealNumber(UndefinedState.NEGATIVE_INFINITY),
                    () => b.Value >= 0 ? new RealNumber(UndefinedState.NEGATIVE_INFINITY) : new RealNumber(UndefinedState.POSITIVE_INFINITY),
                    () => RealNumber.NaN(),
                    () => RealNumber.NaN(),
                    a, b));
     }
     if (!Functional.BothAreEqual(a, b, HierarchyLevel.REAL))
     {
         return(Number.OpDiv(a, b) as RealNumber);
     }
     if (b.Value != 0)
     {
         return(Number.Functional.Downcast(new RealNumber(a.Value / b.Value)) as RealNumber);
     }
     else
     {
         return a.Value switch
                {
                    var x when x > 0 => new RealNumber(UndefinedState.POSITIVE_INFINITY),
                    var x when x < 0 => new RealNumber(UndefinedState.NEGATIVE_INFINITY),
                    _ => new RealNumber(UndefinedState.NAN)
                }
     };
 }
Example #2
0
        /// <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));
            }
        }
 public static RealNumber operator /(RealNumber a, RealNumber b)
 {
     if (!a.IsDefinite() || !b.IsDefinite())
     {
         return(UndefinedStateSuperSwitch.Switch(
                    () => RealNumber.NaN(),
                    () => RealNumber.NaN(),
                    () => RealNumber.NaN(),
                    () => RealNumber.NaN(),
                    () => b.Value switch {
             var x when EDecimalWrapper.IsGreater(x, 0) => new RealNumber(UndefinedState.POSITIVE_INFINITY),
             var x when EDecimalWrapper.IsLess(x, 0) => new RealNumber(UndefinedState.NEGATIVE_INFINITY),
             var x when EDecimalWrapper.IsEqual(x, 0) => RealNumber.NaN()
         },
Example #5
0
 public static RealNumber operator /(IntegerNumber a, IntegerNumber b)
 {
     if (!Functional.BothAreEqual(a, b, HierarchyLevel.INTEGER))
     {
         return(Number.OpDiv(a, b) as IntegerNumber);
     }
     if (b == 0 && a == 0)
     {
         return(RealNumber.NaN());
     }
     if (b == 0)
     {
         return(a > 0
             ? RealNumber.PositiveInfinity()
             : RealNumber.NegativeInfinity());
     }
     return(Number.Functional.Downcast(new RationalNumber(a, b)) as RationalNumber);
 }
        public static RealNumber operator /(RationalNumber a, RationalNumber b)
        {
            if (!Functional.BothAreEqual(a, b, HierarchyLevel.RATIONAL))
            {
                return(Number.OpDiv(a, b) as RationalNumber);
            }
            var num = CtxMultiply(a.Numerator, b.Denominator);
            var den = CtxMultiply(a.Denominator, b.Numerator);

            if (EDecimalWrapper.IsEqual(den, 0))
            {
                return(RealNumber.NaN());
            }
            else
            {
                return(Number.Functional.Downcast(new RationalNumber(num, den)) as RationalNumber);
            }
        }
Example #7
0
 /// <summary>
 /// Calculates the exact value of arccotangent of num
 /// </summary>
 /// <param name="num"></param>
 /// <returns></returns>
 public static ComplexNumber Arccotan(Number num)
 => (num as ComplexNumber).IsDefinite()
         ? Functional.Downcast(Complex.Atan(1 / num.AsComplex())) as ComplexNumber
         : RealNumber.NaN();
Example #8
0
 /// <summary>
 /// Calculates the exact value of cosine of num
 /// </summary>
 /// <param name="num"></param>
 /// <returns></returns>
 public static ComplexNumber Cos(Number num)
 => (num as ComplexNumber).IsDefinite()
         ? Functional.Downcast(Complex.Cos(num.AsComplex())) as ComplexNumber
         : RealNumber.NaN();