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);
}
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;
}