示例#1
0
文件: RatNum.cs 项目: tspring/ioke
 /* Assumes this and obj are both canonicalized. */
 public override bool Equals(object obj)
 {
     if (obj == null || !(obj is RatNum))
     {
         return(false);
     }
     return(RatNum.equals(this, (RatNum)obj));
 }
示例#2
0
 public override Numeric mulReversed(Numeric x)
 {
     if (!(x is RatNum))
     {
         throw new ArgumentException();
     }
     return(RatNum.times((RatNum)x, this));
 }
示例#3
0
 public override Numeric addReversed(Numeric x, int k)
 {
     if (!(x is RatNum))
     {
         throw new ArgumentException();
     }
     return(RatNum.add((RatNum)x, this, k));
 }
示例#4
0
 public override int CompareTo(object obj)
 {
     if (obj is RatNum)
     {
         return(RatNum.compare(this, (RatNum)obj));
     }
     return(((RealNum)obj).compareReversed(this));
 }
示例#5
0
 public static RatNum add(RatNum x, RatNum y, int k)
 {
     IntNum x_num = x.numerator();
     IntNum x_den = x.denominator();
     IntNum y_num = y.numerator();
     IntNum y_den = y.denominator();
     if (IntNum.equals (x_den, y_den))
         return RatNum.make (IntNum.add (x_num, y_num, k), x_den);
     return RatNum.make (IntNum.add (IntNum.times (y_den, x_num),
                                     IntNum.times (y_num, x_den), k),
                         IntNum.times (x_den, y_den));
 }
示例#6
0
 public override Numeric div(object y)
 {
     if (y is RatNum)
     {
         return(RatNum.divide(this, (RatNum)y));
     }
     if (!(y is Numeric))
     {
         throw new ArgumentException();
     }
     return(((Numeric)y).divReversed(this));
 }
示例#7
0
 public override Numeric mul(object y)
 {
     if (y is RatNum)
     {
         return(RatNum.times(this, (RatNum)y));
     }
     if (!(y is Numeric))
     {
         throw new ArgumentException();
     }
     return(((Numeric)y).mulReversed(this));
 }
示例#8
0
 public override Numeric add(object y, int k)
 {
     if (y is RatNum)
     {
         return(RatNum.add(this, (RatNum)y, k));
     }
     if (!(y is Numeric))
     {
         throw new ArgumentException();
     }
     return(((Numeric)y).addReversed(this, k));
 }
示例#9
0
文件: RatNum.cs 项目: tspring/ioke
        public static RatNum add(RatNum x, RatNum y, int k)
        {
            IntNum x_num = x.numerator();
            IntNum x_den = x.denominator();
            IntNum y_num = y.numerator();
            IntNum y_den = y.denominator();

            if (IntNum.equals(x_den, y_den))
            {
                return(RatNum.make(IntNum.add(x_num, y_num, k), x_den));
            }
            return(RatNum.make(IntNum.add(IntNum.times(y_den, x_num),
                                          IntNum.times(y_num, x_den), k),
                               IntNum.times(x_den, y_den)));
        }
示例#10
0
文件: RealNum.cs 项目: vic/ioke
 /** Convert rational to (rounded) integer, after multiplying by 10**k. */
 public static IntNum toScaledInt(RatNum r, int k)
 {
     if (k != 0)
         {
             IntNum power = IntNum.power(IntNum.ten(), k < 0 ? -k : k);
             IntNum num = r.numerator();
             IntNum den = r.denominator();
             if (k >= 0)
                 num = IntNum.times(num, power);
             else
                 den = IntNum.times(den, power);
             r = RatNum.make(num, den);
         }
     return r.toExactInt(ROUND);
 }
示例#11
0
 /** Convert rational to (rounded) integer, after multiplying by 10**k. */
 public static IntNum toScaledInt(RatNum r, int k)
 {
     if (k != 0)
     {
         IntNum power = IntNum.power(IntNum.ten(), k < 0 ? -k : k);
         IntNum num   = r.numerator();
         IntNum den   = r.denominator();
         if (k >= 0)
         {
             num = IntNum.times(num, power);
         }
         else
         {
             den = IntNum.times(den, power);
         }
         r = RatNum.make(num, den);
     }
     return(r.toExactInt(ROUND));
 }
示例#12
0
文件: RatNum.cs 项目: tspring/ioke
 /* Assumes x and y are both canonicalized. */
 public static bool equals(RatNum x, RatNum y)
 {
     return(IntNum.equals(x.numerator(), y.numerator()) &&
            IntNum.equals(x.denominator(), y.denominator()));
 }
示例#13
0
文件: RatNum.cs 项目: tspring/ioke
 public static int compare(RatNum x, RatNum y)
 {
     return(IntNum.compare(IntNum.times(x.numerator(), y.denominator()),
                           IntNum.times(y.numerator(), x.denominator())));
 }
示例#14
0
文件: Number.cs 项目: nope/ioke
 public Number(RatNum value)
 {
     this.value = value;
     kind = false;
 }
示例#15
0
文件: Runtime.cs 项目: goking/ioke
 public IokeObject NewNumber(RatNum number)
 {
     if(number is IntNum) {
         return NewNumber((IntNum)number);
     } else {
         IokeObject obj = this.Ratio.AllocateCopy(null, null);
         obj.MimicsWithoutCheck(this.Ratio);
         obj.Data = Ioke.Lang.Number.Ratio((IntFraction)number);
         return obj;
     }
 }
示例#16
0
 public override int compareReversed(Numeric x)
 {
     return(RatNum.compare((RatNum)x, this));
 }
示例#17
0
文件: RatNum.cs 项目: tspring/ioke
 public static RatNum divide(RatNum x, RatNum y)
 {
     return(RatNum.make(IntNum.times(x.numerator(), y.denominator()),
                        IntNum.times(x.denominator(), y.numerator())));
 }
示例#18
0
 public static int compare(RatNum x, RatNum y)
 {
     return IntNum.compare (IntNum.times (x.numerator (), y.denominator ()),
                            IntNum.times (y.numerator (), x.denominator ()));
 }
示例#19
0
 public static Decimal CreateDecimal(RatNum val)
 {
     return new Decimal(new BigDecimal(val.longValue()));
 }
示例#20
0
 /* Assumes x and y are both canonicalized. */
 public static bool equals(RatNum x, RatNum y)
 {
     return IntNum.equals (x.numerator(), y.numerator())
         && IntNum.equals (x.denominator(), y.denominator());
 }
示例#21
0
文件: Number.cs 项目: nope/ioke
 private Number()
 {
     this.value = IntNum.make(0);
     kind = true;
 }
示例#22
0
 public static RatNum times(RatNum x, RatNum y)
 {
     return RatNum.make (IntNum.times (x.numerator(), y.numerator()),
                         IntNum.times (x.denominator(), y.denominator()));
 }