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)
                }
     };
 }
 public static RationalNumber operator /(IntegerNumber a, IntegerNumber b)
 {
     if (!Functional.BothAreEqual(a, b, HierarchyLevel.INTEGER))
     {
         return(Number.OpDiv(a, b) as IntegerNumber);
     }
     return(Number.Functional.Downcast(new RationalNumber(a, b)) as RationalNumber);
 }
Beispiel #3
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);
            }
        }
Beispiel #5
0
        public static ComplexNumber operator /(ComplexNumber a, ComplexNumber b)
        {
            if (!Functional.BothAreEqual(a, b, HierarchyLevel.COMPLEX))
            {
                return(Number.OpDiv(a, b) as ComplexNumber);
            }

            /*
             * (a + ib) / (c + id) = (a + ib) * (1 / (c + id))
             * 1 / (c + id) = (c2 + d2) / (c + id) / (c2 + d2) = (c - id) / (c2 + d2)
             * => ans = (a + ib) * (c - id) / (c2 + d2)
             */
            var conj = b.Conjugate();
            var bAbs = b.Abs();
            var abs2 = bAbs * bAbs;
            var Re   = conj.Real / abs2;
            var Im   = conj.Imaginary / abs2;
            var c    = new ComplexNumber(Re, Im);

            return(Number.Functional.Downcast(a * c) as ComplexNumber);
        }