@Override public int complexSign() { return sign(); }
public int complexSign() { return sign(); }
@Override public IInteger[] nthRootSplit(int n) throws ArithmeticException { IInteger[] result = new IInteger[2]; if (sign() == 0) { result[0] = F.C0; result[1] = F.C1; return result; } else if (sign() < 0) { if (n % 2 == 0) { // even exponent n throw new ArithmeticException(); } else { // odd exponent n result = negate().nthRootSplit(n); result[1] = result[1].negate(); return result; } } long b = fIntValue; long[] nthRoot = Primality.countRoot1021(b, n); result[0] = AbstractIntegerSym.valueOf(nthRoot[0]); result[1] = AbstractIntegerSym.valueOf(nthRoot[1]); return result; }
/** * Get the highest exponent of <code>base</code> that divides <code>this</code> * * @return the exponent */ @Override public IExpr exponent(IInteger base) { IInteger b = this; if (sign() < 0) { b = b.negate(); } else if (b.isZero()) { return F.CInfinity; } else if (b.isOne()) { return F.C0; } if (b.equals(base)) { return F.C1; } BigInteger rest = Primality.countExponent(b.toBigNumerator(), base.toBigNumerator()); return valueOf(rest); }
/** * Returns the nth-root of this integer. * * @return <code>k<code> such as <code>k^n <= this < (k + 1)^n</code> * @throws ArithmeticException * if this integer is negative and n is even. */ public IInteger nthRoot(int n) throws ArithmeticException { if (sign() == 0) { return IntegerSym.valueOf(0); } else if (sign() < 0) { if (n % 2 == 0) { // even exponent n throw new ArithmeticException(); } else { // odd exponent n return (IntegerSym) ((IntegerSym) negate()).nthRoot(n).negate(); } } else { IntegerSym result; IntegerSym temp = this; do { result = temp; temp = divideAndRemainder(temp.pow(n - 1))[0].add(temp.multiply(IntegerSym.valueOf(n - 1))).divideAndRemainder( IntegerSym.valueOf(n))[0]; } while (temp.compareTo(result) < 0); return result; } }