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