Search in sources :

Example 1 with NumStr

use of org.matheclipse.core.expression.NumStr in project symja_android_library by axkr.

the class ExprParser method getReal.

private static INum getReal(String str) {
    int index = str.indexOf("*^");
    int fExponent = 1;
    String fFloatStr = str;
    if (index > 0) {
        fFloatStr = str.substring(0, index);
        fExponent = Integer.parseInt(str.substring(index + 2));
    }
    if (fFloatStr.length() > 15) {
        int precision = fFloatStr.length();
        Apfloat apfloatValue = new Apfloat(fFloatStr, precision);
        if (fExponent != 1) {
            // value * 10 ^ exponent
            return F.num(apfloatValue.multiply(ApfloatMath.pow(new Apfloat(10, precision), new Apint(fExponent))));
        }
        return F.num(apfloatValue);
    }
    double fDouble = Double.parseDouble(fFloatStr);
    if (fExponent != 1) {
        // value * 10 ^ exponent
        fDouble = fDouble * Math.pow(10, fExponent);
    }
    return new NumStr(fFloatStr, fExponent);
}
Also used : NumStr(org.matheclipse.core.expression.NumStr) Apint(org.apfloat.Apint) Apint(org.apfloat.Apint) Apfloat(org.apfloat.Apfloat)

Example 2 with NumStr

use of org.matheclipse.core.expression.NumStr in project symja_android_library by axkr.

the class ExprParser method getNumber.

/**
	 * Method Declaration.
	 * 
	 * @return
	 * @see
	 */
private IExpr getNumber(final boolean negative) throws SyntaxError {
    IExpr temp = null;
    final Object[] result = getNumberString();
    String number = (String) result[0];
    final int numFormat = ((Integer) result[1]).intValue();
    try {
        if (negative) {
            number = '-' + number;
        }
        if (numFormat < 0) {
            // TODO use getReal() if apfloat problems are fixed
            // temp = getReal(number);
            temp = new NumStr(number);
        // temp = fFactory.createDouble(number);
        } else {
            temp = F.integer(number, numFormat);
        // temp = fFactory.createInteger(number, numFormat);
        }
    } catch (final Throwable e) {
        throwSyntaxError("Number format error: " + number, number.length());
    }
    getNextToken();
    return temp;
}
Also used : NumStr(org.matheclipse.core.expression.NumStr) IExpr(org.matheclipse.core.interfaces.IExpr) Apint(org.apfloat.Apint)

Aggregations

Apint (org.apfloat.Apint)2 NumStr (org.matheclipse.core.expression.NumStr)2 Apfloat (org.apfloat.Apfloat)1 IExpr (org.matheclipse.core.interfaces.IExpr)1