Package lipstone.joshua.parser.exceptions

Examples of lipstone.joshua.parser.exceptions.UndefinedResultException


   * @throws UndefinedResultException
   *             if this number is complex, meaning that this is thrown on imaginary part != 0
   */
  public double doubleValue() throws UndefinedResultException {
    if (internal.imag().compareTo(Apfloat.ZERO) != 0)
      throw new UndefinedResultException("Cannot get the double value of a complex number.", null);
    if (infinity == 1)
      return Double.POSITIVE_INFINITY;
    if (infinity == -1)
      return Double.NEGATIVE_INFINITY;
    return internal.doubleValue();
View Full Code Here


   * @return this + number
   * @throws UndefinedResultException
   */
  public BigDec add(BigDec number) throws UndefinedResultException {
    if (infinity != 0 && number.infinity != 0 && infinity != number.infinity)
      throw new UndefinedResultException("infinty - infinity is an undefined operation.", null);
    int inf = infinity + number.infinity;
    if (inf >= 1)
      return new BigDec(new Integer(1));
    if (inf <= -1)
      return new BigDec(new Integer(-1));
View Full Code Here

   * @return this - number
   * @throws UndefinedResultException
   */
  public BigDec subtract(BigDec number) throws UndefinedResultException {
    if (infinity != 0 && number.infinity != 0 && infinity == number.infinity)
      throw new UndefinedResultException("infinty - infinity is an undefined operation.", null);
    int inf = infinity - number.infinity;
    if (inf >= 1)
      return new BigDec(new Integer(1));
    if (inf <= -1)
      return new BigDec(new Integer(-1));
View Full Code Here

   * @return this / number
   * @throws UndefinedResultException
   */
  public BigDec divide(BigDec number) throws UndefinedResultException {
    if (infinity != 0 && number.infinity != 0)
      throw new UndefinedResultException("Infinity / infinity is an undefined operation.", null);
    else if (infinity != 0)
      return new BigDec(new Integer(infinity));
    else if (number.infinity != 0)
      return ZERO;
    else if (number.eq(ZERO) && eq(ZERO))
      throw new UndefinedResultException("0 / 0 is an undefined operation.", null);
    else if (number.eq(ZERO))
      return new BigDec(new Integer(signum()));
    return new BigDec(internal.divide(number.internal));
  }
View Full Code Here

   */
  public BigDec mod(BigDec number) throws UndefinedResultException {
    if (infinity != 0)
      return new BigDec(new Integer(1));
    if (number.eq(ZERO))
      throw new UndefinedResultException(null);
    if (!isComplex() && !number.isComplex())
      return new BigDec(ApfloatMath.fmod(internal.real(), number.internal.real()));
    return gt(number) ? complexMod(internal, number.internal) : complexMod(number.internal, internal);
  }
View Full Code Here

   * @return the signed remainder of the division operation
   * @throws UndefinedResultException
   */
  public BigDec remainder(BigDec number) throws UndefinedResultException {
    if (number.eq(ZERO))
      throw new UndefinedResultException("The remainder when dividing by zero is undefined.", null);
    if (!isComplex() && !number.isComplex())
      return new BigDec(ApfloatMath.fmod(internal.real(), number.internal.real()));
    return gt(number) ? complexMod(internal, number.internal) : complexMod(number.internal, internal);
  }
View Full Code Here

   * @throws UndefinedResultException
   *             when both this and exp are infinities
   */
  public BigDec pow(BigDec exp) throws UndefinedResultException {
    if (infinity != 0 && exp.infinity != 0)
      throw new UndefinedResultException(null);
    else if (infinity != 0)
      return new BigDec(new Integer(infinity));
    else if (exp.infinity > 0)
      return new BigDec(new Integer(exp.infinity));
    else if (exp.infinity < 0)
View Full Code Here

   */
  public BigDec gcd(BigDec other) throws UndefinedResultException {
    if (isComplex() && other.isComplex())
      return gt(other) ? complexGCD(internal, other.internal) : complexGCD(other.internal, internal);
    if (!isInt() || !other.isInt())
      throw new UndefinedResultException("The gcd operation is only valid over the integers.", null);
    BigDec a = this, r = null;
    while ((r = other.mod(a)).neq(ZERO)) {
      a = other;
      other = r;
    }
View Full Code Here

   * @throws UndefinedResultException
   *             if either this number or <tt>other</tt> is not an integer
   */
  public BigDec lcm(BigDec other) throws UndefinedResultException {
    if (!isInt() || !other.isInt())
      throw new UndefinedResultException("The lcm operation is only valid over the integers.", null);
    return multiply(other).divide(gcd(other));
  }
View Full Code Here

   * @throws UndefinedResultException
   *             if this <tt>BigDec</tt> is an infinity
   */
  public ConsCell toFraction() throws UndefinedResultException {
    if (infinity != 0)
      throw new UndefinedResultException(null);
    BigDec numerator = this, denominator = BigDec.ONE, ten = new BigDec(10);
    while (!numerator.isInt()) {
      numerator = numerator.multiply(ten);
      denominator = denominator.multiply(ten);
    }
View Full Code Here

TOP

Related Classes of lipstone.joshua.parser.exceptions.UndefinedResultException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.