Package org.apfloat

Examples of org.apfloat.Apfloat


 
  public BigDec round(ConsCell input) throws ParserException {
    ConsCell num = parser.run(input);
    if (num.length() != 1 || num.getCarType() != ConsType.NUMBER)
      throw new UndefinedResultException("The argument to the round function must evaluate to a number", this);
    Apfloat real = ((BigDec) num.getCar()).getInternal().real(), complex = ((BigDec) num.getCar()).getInternal().imag(), round = new Apfloat(0.5);
    return new BigDec(real.frac().compareTo(round) == -1 ? real.floor() : real.ceil(), complex.frac().compareTo(round) == -1 ? complex.floor() : complex.ceil());
  }
View Full Code Here


    this(real, 0.0);
  }
 
  public BigDec(double real, double complex) {
    infinity = real == Double.POSITIVE_INFINITY || complex == Double.POSITIVE_INFINITY ? 1 : real == Double.NEGATIVE_INFINITY || complex == Double.NEGATIVE_INFINITY ? -1 : 0;
    internal = infinity == 0 ? new Apcomplex(new Apfloat(real, PRECISION), new Apfloat(complex, PRECISION)) : null;
  }
View Full Code Here

      infinity = 1;
    else if (new Integer(real).doubleValue() == Double.NEGATIVE_INFINITY)
      infinity = -1;
    else
      infinity = 0;
    internal = infinity == 0 ? new Apcomplex(new Apfloat(real, PRECISION), new Apfloat(complex, PRECISION)) : null;
  }
View Full Code Here

      infinity = 1;
    else if (new Long(real).doubleValue() == Double.NEGATIVE_INFINITY)
      infinity = -1;
    else
      infinity = 0;
    internal = infinity == 0 ? new Apcomplex(new Apfloat(real, PRECISION), new Apfloat(complex, PRECISION)) : null;
  }
View Full Code Here

  public BigDec(String number) {
    Matcher m = complexNumber.matcher(number.replaceAll(" ", "").toLowerCase());
    if (!m.matches()) {
      if (number.equals("i")) {
        infinity = 0;
        internal = new Apcomplex(new Apfloat(0, PRECISION), new Apfloat(1, PRECISION));
        return;
      }
      throw new NumberFormatException(number + " is not a valid complex number.");
    }
    Apfloat real = new Apfloat(0, PRECISION), imaginary = new Apfloat(0, PRECISION);
    int sign = 1;
    if ("-".equals(m.group(1)))
      sign = -1;
    if (m.group(2).equals("infinity")) {
      infinity = sign;
      internal = null;
      return;
    }
    if (m.group(2).equals("i")) {
      imaginary = new Apfloat(1, PRECISION);
    }
    else if (m.group(5) != null)
      imaginary = sign == -1 ? new Apfloat("-" + m.group(3), PRECISION) : new Apfloat(m.group(3), PRECISION);
    else
      real = sign == -1 ? new Apfloat("-" + m.group(3), PRECISION) : new Apfloat(m.group(3), PRECISION);
    if (m.group(6) != null) {
      sign = 1;
      if ("-".equals(m.group(7)))
        sign = -1;
      if (m.group(8).equals("infinity")) {
        infinity = sign;
        internal = null;
        return;
      }
      if (m.group(8).equals("i")) {
        imaginary = new Apfloat(1, PRECISION);
      }
      else if (m.group(11) != null)
        imaginary = sign == -1 ? new Apfloat("-" + m.group(9), PRECISION) : new Apfloat(m.group(9), PRECISION);
      else
        real = sign == -1 ? new Apfloat("-" + m.group(9), PRECISION) : new Apfloat(m.group(9), PRECISION);
    }
    infinity = 0;
    internal = new Apcomplex(real, imaginary);
  }
View Full Code Here

    return new BigDec(b.subtract(getQ(b, a, ApZERO, ApZERO, -1).multiply(a)));
  }
 
  //0 -> +1, 1 -> +i, 2 -> -1, 3 -> -i
  private Apcomplex getQ(Apcomplex b, Apcomplex a, Apcomplex q, Apcomplex lastR, int direction) {
    Apfloat norm = ApcomplexMath.norm(b);
    //q, r
    Pair<Apcomplex, Apcomplex>[] r = (Pair<Apcomplex, Apcomplex>[]) Array.newInstance(new Pair<Apcomplex, Apcomplex>(null, null).getClass(), 4);
    if (direction >= 0) {
      direction = (direction + 2) % 4;
      r[direction] = new Pair<Apcomplex, Apcomplex>(q, lastR);
View Full Code Here

      return true;
    else if (infinity != 0 || number.infinity != 0)
      return false;
    if (!isComplex() && !number.isComplex())
      return internal.real().compareTo(number.internal.real()) > 0;
    return ApfloatMath.abs(ApcomplexMath.pow(internal.real(), new Apfloat(2)).real().add(ApcomplexMath.pow(internal.imag(), new Apfloat(2)).real())).
        compareTo(ApfloatMath.abs(ApcomplexMath.pow(number.internal.real(), new Apfloat(2)).real().add(ApcomplexMath.pow(number.internal.imag(), new Apfloat(2)).real()))) > 0;
  }
View Full Code Here

      return true;
    else if (infinity != 0 || number.infinity != 0)
      return false;
    if (!isComplex() && !number.isComplex())
      return internal.real().compareTo(number.internal.real()) < 0;
    return ApfloatMath.abs(ApcomplexMath.pow(internal.real(), new Apfloat(2)).real().add(ApcomplexMath.pow(internal.imag(), new Apfloat(2)).real())).
        compareTo(ApfloatMath.abs(ApcomplexMath.pow(number.internal.real(), new Apfloat(2)).real().add(ApcomplexMath.pow(number.internal.imag(), new Apfloat(2)).real()))) < 0;
  }
View Full Code Here

TOP

Related Classes of org.apfloat.Apfloat

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.