/** * {@inheritDoc} */ @Override public long toLong() throws ArithmeticException { return NumberUtil.toLong(fBigIntValue); }
/** * {@inheritDoc} */ @Override public long toLong() throws ArithmeticException { return NumberUtil.toLong(fDouble); }
public long toLong() throws ArithmeticException { return NumberUtil.toLong(fInteger); }
/** {@inheritDoc} */ @Override public IInteger floorFraction() { return F.integer(NumberUtil.toLong(Math.floor(fDouble))); }
/** {@inheritDoc} */ @Override public IInteger ceilFraction() { return F.integer(NumberUtil.toLong(Math.ceil(fDouble))); }
/** * Test if the value is a perfect square (i.e. its square root is another * integer). See <a href= * "http://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer"> * Stackoverflow.com - Fastest way to determine if an integer's square root * is an integer</a> * * @param bi * @return <code>true</code> if the number is a perfect square. */ public final static boolean isPerfectSquare(BigInteger bi) { try { return isPerfectSquare(toLong(bi)); } catch (ArithmeticException ae) { } return false; // number out of range exception }
/** {@inheritDoc} */ @Override public long toLong() throws ArithmeticException { if (toBigDenominator().equals(BigInteger.ONE)) { return NumberUtil.toLong(toBigNumerator()); } if (toBigNumerator().equals(BigInteger.ZERO)) { return 0L; } throw new ArithmeticException("toLong: denominator != 1"); }
/** * Test if the fraction value is a perfect square (i.e. its numerator's and * denominator's square root are integers). See <a href= * "http://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer"> * Stackoverflow.com - Fastest way to determine if an integer's square root * is an integer</a> * * @param bf * @return <code>true</code> if the number is a perfect square. */ public final static boolean isPerfectSquare(BigFraction bf) { try { long num = toLong(bf.getNumerator()); long den = toLong(bf.getDenominator()); return isPerfectSquare(den) && isPerfectSquare(num); } catch (ArithmeticException ae) { } return false; // number out of range exception }
/** * Test if the fraction value is a perfect square (i.e. its numerator's and * denominator's square root are integers). See <a href= * "http://stackoverflow.com/questions/295579/fastest-way-to-determine-if-an-integers-square-root-is-an-integer"> * Stackoverflow.com - Fastest way to determine if an integer's square root * is an integer</a> * * @param bf * @return <code>true</code> if the number is a perfect square. */ public final static boolean isPerfectSquare(IRational bf) { try { long num = toLong(bf.toBigNumerator()); long den = toLong(bf.toBigDenominator()); return isPerfectSquare(den) && isPerfectSquare(num); } catch (ArithmeticException ae) { } return false; // number out of range exception }