Esempio n. 1
0
 /// <summary>
 /// Use Number.Copy(Number) or this.Copy() instead
 /// </summary>
 /// <param name="number"></param>
 internal RationalNumber(Number number)
 {
     number = Functional.Downcast(number);
     if (number.Is(HierarchyLevel.RATIONAL))
     {
         InitClass((number as RationalNumber).Numerator, (number as RationalNumber).Denominator);
     }
     else
     {
         throw new InvalidNumberCastException(number.Type, HierarchyLevel.RATIONAL);
     }
 }
 /// <summary>
 /// Use Number.Copy(Number) or this.Copy()
 /// </summary>
 /// <param name="number"></param>
 internal IntegerNumber(Number number)
 {
     number = Functional.Downcast(number);
     if (number.Is(HierarchyLevel.INTEGER))
     {
         InitClass((number as IntegerNumber).Value, (number as RealNumber).State);
     }
     else
     {
         throw new InvalidNumberCastException(number.Type, HierarchyLevel.INTEGER);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Can be only called if num is in type's set of numbers, e. g.
 /// we can upcast longeger to real, but we cannot upcast complex to real
 /// </summary>
 /// <param name="num">
 /// Number to upcast
 /// </param>
 /// <param name="type">
 /// The level the Number to upcast to
 /// </param>
 /// <returns></returns>
 internal static Number UpCastTo(Number num, Number.HierarchyLevel type)
 {
     if (num.Type == type)
     {
         return(num);
     }
     if (!num.Is(type))
     {
         throw new InvalidNumberCastException(num.Type, type);
     }
     return(Number.SuperSwitch(
                num => new IntegerNumber(num[0] as Number),
                num => new RationalNumber(num[0]),
                num => new RealNumber(num[0] as Number),
                num => new ComplexNumber(num[0]),
                type,
                num
                ));
 }