コード例 #1
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
                ));
 }