public int CompareTo(BigNum that) { if (this.val == that.val) { return(0); } if (this.val < that.val) { return(-1); } return(1); }
public static bool TryParse(string v, out BigNum res) { try { res = BigNum.FromString(v); return(true); } catch (FormatException) { res = ZERO; return(false); } }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (!(obj is BigNum)) { return(false); } BigNum other = (BigNum)obj; return(this.val == other.val); }
public BigNum Max(BigNum that) { return(new BigNum(this.val >= that.val ? this.val : that.val)); }
public BigNum Min(BigNum that) { return(new BigNum(this.val <= that.val ? this.val : that.val)); }
public static Rational FromInts(int num, int den) { return(FromBignums(BigNum.FromInt(num), BigNum.FromInt(den))); }
public static Rational FromBignum(BigNum n) { return(new Rational(n, BigNum.ONE)); }
// int numerator; // int denominator; // invariant: 0 < denominator || (numerator == 0 && denominator == 0); // invariant: numerator != 0 ==> gcd(abs(numerator),denominator) == 1; // invariant: numerator == 0 ==> denominator == 1 || denominator == 0; public static Rational FromInt(int x) { return(FromBignum(BigNum.FromInt(x))); }