/** {@inheritDoc} */ @Override public int toIntDefault(int defaultValue) { try { return NumberUtil.toInt(fDouble); } catch (ArithmeticException ae) { return defaultValue; } }
/** * {@inheritDoc} */ public int toInt() throws ArithmeticException { return NumberUtil.toInt(fInteger); }
/** {@inheritDoc} */ @Override public int toInt() throws ArithmeticException { return NumberUtil.toInt(fBigIntValue); }
/** * {@inheritDoc} */ @Override public int toInt() throws ArithmeticException { return NumberUtil.toInt(fDouble); }
@Override public String internalFormString(boolean symbolsAsFactoryMethod, int depth) { int value = NumberUtil.toInt(fInteger); switch (value) { case -1: return "CN1"; case 0: return "C0"; case 1: return "C1"; case 2: return "C2"; case 3: return "C3"; case 4: return "C4"; case 5: return "C5"; } return "integer(" + value + "L)"; }
boolean noSymbolPrefix) { String prefix = usePrefix ? "F." : ""; int value = NumberUtil.toInt(fIntValue); switch (value) { case -1:
boolean noSymbolPrefix) { String prefix = usePrefix ? "F." : ""; int value = NumberUtil.toInt(fBigIntValue); switch (value) { case -1:
private BigInteger binomial(final BigInteger n, final BigInteger k) { // k>n : by definition --> 0 if (k.compareTo(n) > 0) { return BigInteger.ZERO; } if (k.equals(BigInteger.ZERO) || k.equals(n)) { return BigInteger.ONE; } try { int ni = NumberUtil.toInt(n); int ki = NumberUtil.toInt(k); if (ki > ni) { return BigInteger.ZERO; } return BigIntegerMath.binomial(ni, ki); } catch (ArithmeticException ae) { // } BigInteger bin = BigInteger.ONE; BigInteger i = BigInteger.ONE; while (!(i.compareTo(k) > 0)) { bin = bin.multiply(n.subtract(i).add(BigInteger.ONE)).divide(i); i = i.add(BigInteger.ONE); } return bin; } }
/** {@inheritDoc} */ @Override public int toInt() throws ArithmeticException { if (toBigDenominator().equals(BigInteger.ONE)) { return NumberUtil.toInt(toBigNumerator()); } if (toBigNumerator().equals(BigInteger.ZERO)) { return 0; } throw new ArithmeticException("toInt: denominator != 1"); }
/** {@inheritDoc} */ @Override public int toIntDefault(int defaultValue) { if (toBigDenominator().equals(BigInteger.ONE)) { return NumberUtil.toInt(toBigNumerator()); } if (toBigNumerator().equals(BigInteger.ZERO)) { return 0; } return defaultValue; }
@Override public String internalFormString(boolean symbolsAsFactoryMethod, int depth) { int real_numerator = NumberUtil.toInt(_real.getNumerator()); int real_denominator = NumberUtil.toInt(_real.getDenominator()); int imag_numerator = NumberUtil.toInt(_imaginary.getNumerator()); int imag_denominator = NumberUtil.toInt(_imaginary.getDenominator()); if (_real.equals(BigFraction.ZERO)) { if (_imaginary.equals(BigFraction.ONE)) { return "CI"; } if (_imaginary.equals(BigFraction.MINUS_ONE)) { return "CNI"; } } return "complex(" + real_numerator + "L," + real_denominator + "L," + imag_numerator + "L," + imag_denominator + "L)"; }
public static BigInteger factorial(final BigInteger biggi) { try { int ni = NumberUtil.toInt(biggi); BigInteger result; if (ni < 0) { result = BigIntegerMath.factorial(-1 * ni); if ((ni & 0x0001) == 0x0001) { // odd integer number result = result.multiply(BigInteger.valueOf(-1L)); } } else { result = BigIntegerMath.factorial(ni); } return result; } catch (ArithmeticException ae) { // } BigInteger result = BigInteger.ONE; if (biggi.compareTo(BigInteger.ZERO) == -1) { result = BigInteger.valueOf(-1); for (BigInteger i = BigInteger.valueOf(-2); i.compareTo(biggi) >= 0; i = i.add(BigInteger.valueOf(-1))) { result = result.multiply(i); } } else { for (BigInteger i = BigInteger.valueOf(2); i.compareTo(biggi) <= 0; i = i.add(BigInteger.ONE)) { result = result.multiply(i); } } return result; }
@Override public String internalJavaString(boolean symbolsAsFactoryMethod, int depth, boolean useOperators, boolean usePrefix, boolean noSymbolPrefix) { String prefix = usePrefix ? "F." : ""; if (fReal.isZero()) { if (fImaginary.isOne()) { return prefix + "CI"; } if (fImaginary.isMinusOne()) { return prefix + "CNI"; } } int realNumerator = NumberUtil.toInt(fReal.toBigNumerator()); int realDenominator = NumberUtil.toInt(fReal.toBigDenominator()); int imagNumerator = NumberUtil.toInt(fImaginary.toBigNumerator()); int imagDenominator = NumberUtil.toInt(fImaginary.toBigDenominator()); return prefix + "CC(" + realNumerator + "L," + realDenominator + "L," + imagNumerator + "L," + imagDenominator + "L)"; }
/** * Get the specified history line fro the <code>EvalEngine's</code> history list. <br /> * <b>Note</b> that the history maybe disabled in the <code>EvalEngine</code>. */ public IExpr e1DblArg(final double iNum) { try { // int i = iNum.toInt(); int i = NumberUtil.toInt(iNum); final LastCalculationsHistory list = EvalEngine.get().getOutList(); if (list != null) { return list.entry(i); } } catch (final Exception ae) { } return F.NIL; }