/** Do one the the 16 possible bit-wise operations of two IntNums. */ public static IntNum bitOp(int op, IntNum x, IntNum y) { switch (op) { case 0: return(IntNum.zero()); case 1: return(and(x, y)); case 3: return(x); case 5: return(y); case 15: return(IntNum.minusOne()); } IntNum result = new IntNum(); setBitOp(result, op, x, y); return(result.canonicalize()); }
public override double doubleValue() { bool neg = num.isNegative(); if (den.isZero()) { return(neg ? Double.NegativeInfinity : num.isZero() ? Double.NaN : Double.PositiveInfinity); } IntNum n = num; if (neg) { n = IntNum.neg(n); } int num_len = n.intLength(); int den_len = den.intLength(); int exp = 0; if (num_len < den_len + 54) { exp = den_len + 54 - num_len; n = IntNum.shift(n, exp); exp = -exp; } // Divide n (which is shifted num) by den, using truncating division, // and return quot and remainder. IntNum quot = new IntNum(); IntNum remainder = new IntNum(); IntNum.divide(n, den, quot, remainder, TRUNCATE); quot = quot.canonicalize(); remainder = remainder.canonicalize(); return(quot.roundToDouble(exp, neg, !remainder.isZero())); }
/** Do one the the 16 possible bit-wise operations of two IntNums. */ public static IntNum bitOp(int op, IntNum x, IntNum y) { switch (op) { case 0: return IntNum.zero(); case 1: return and (x, y); case 3: return x; case 5: return y; case 15: return IntNum.minusOne(); } IntNum result = new IntNum (); setBitOp (result, op, x, y); return result.canonicalize (); }