/* 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)); }
public override Numeric mulReversed(Numeric x) { if (!(x is RatNum)) { throw new ArgumentException(); } return(RatNum.times((RatNum)x, this)); }
public override Numeric addReversed(Numeric x, int k) { if (!(x is RatNum)) { throw new ArgumentException(); } return(RatNum.add((RatNum)x, this, k)); }
public override int CompareTo(object obj) { if (obj is RatNum) { return(RatNum.compare(this, (RatNum)obj)); } return(((RealNum)obj).compareReversed(this)); }
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)); }
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)); }
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)); }
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)); }
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))); }
/** 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); }
/** 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)); }
/* 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())); }
public static int compare(RatNum x, RatNum y) { return(IntNum.compare(IntNum.times(x.numerator(), y.denominator()), IntNum.times(y.numerator(), x.denominator()))); }
public Number(RatNum value) { this.value = value; kind = false; }
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; } }
public override int compareReversed(Numeric x) { return(RatNum.compare((RatNum)x, this)); }
public static RatNum divide(RatNum x, RatNum y) { return(RatNum.make(IntNum.times(x.numerator(), y.denominator()), IntNum.times(x.denominator(), y.numerator()))); }
public static int compare(RatNum x, RatNum y) { return IntNum.compare (IntNum.times (x.numerator (), y.denominator ()), IntNum.times (y.numerator (), x.denominator ())); }
public static Decimal CreateDecimal(RatNum val) { return new Decimal(new BigDecimal(val.longValue())); }
/* 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()); }
private Number() { this.value = IntNum.make(0); kind = true; }
public static RatNum times(RatNum x, RatNum y) { return RatNum.make (IntNum.times (x.numerator(), y.numerator()), IntNum.times (x.denominator(), y.denominator())); }