public static IntegerNumber operator +(IntegerNumber a, IntegerNumber b) { if (!Functional.BothAreEqual(a, b, HierarchyLevel.INTEGER)) { return(Number.OpSum(a, b) as IntegerNumber); } return(new IntegerNumber(CtxAdd(a.Value, b.Value))); }
public static RationalNumber operator +(RationalNumber a, RationalNumber b) { if (!Functional.BothAreEqual(a, b, HierarchyLevel.RATIONAL)) { return(Number.OpSum(a, b) as RationalNumber); } var num = CtxAdd(CtxMultiply(a.Numerator, b.Denominator), CtxMultiply(b.Numerator, a.Denominator)); var den = CtxMultiply(a.Denominator, b.Denominator); return(Number.Functional.Downcast(new RationalNumber(num, den)) as RationalNumber); }
public static ComplexNumber operator +(ComplexNumber a, ComplexNumber b) { if (!Functional.BothAreEqual(a, b, HierarchyLevel.COMPLEX)) { return(Number.OpSum(a, b) as ComplexNumber); } var Re = a.Real + b.Real; var Im = a.Imaginary + b.Imaginary; return(Number.Functional.Downcast(new ComplexNumber(Re, Im)) as ComplexNumber); }
public static RealNumber operator +(RealNumber a, RealNumber b) { if (!a.IsDefinite() || !b.IsDefinite()) { return(UndefinedStateSuperSwitch.Switch( () => new RealNumber(UndefinedState.NEGATIVE_INFINITY), () => new RealNumber(UndefinedState.POSITIVE_INFINITY), () => new RealNumber(UndefinedState.NAN), () => new RealNumber(UndefinedState.NAN), () => new RealNumber(UndefinedState.POSITIVE_INFINITY), () => new RealNumber(UndefinedState.NEGATIVE_INFINITY), () => new RealNumber(UndefinedState.POSITIVE_INFINITY), () => new RealNumber(UndefinedState.NEGATIVE_INFINITY), a, b)); } if (!Functional.BothAreEqual(a, b, HierarchyLevel.REAL)) { return(Number.OpSum(a, b) as RealNumber); } return(Number.Functional.Downcast(new RealNumber(CtxAdd(a.Value, b.Value))) as RealNumber); }