Refine search
/** * Returns the default complex format for the given locale. * @param locale the specific locale used by the format. * @return the complex format specific to the given locale. */ public static ComplexFormat getInstance(Locale locale) { NumberFormat f = CompositeFormat.getDefaultNumberFormat(locale); return new ComplexFormat(f); }
/** * Parses a string to produce a {@link Complex} object. * * @param source the string to parse. * @return the parsed {@link Complex} object. * @throws MathParseException if the beginning of the specified string * cannot be parsed. */ public Complex parse(String source) throws MathParseException { ParsePosition parsePosition = new ParsePosition(0); Complex result = parse(source, parsePosition); if (parsePosition.getIndex() == 0) { throw new MathParseException(source, parsePosition.getErrorIndex(), Complex.class); } return result; }
double re = complex.getReal(); CompositeFormat.formatDouble(re, getRealFormat(), toAppendTo, pos); double im = complex.getImaginary(); StringBuffer imAppendTo; if (im < 0.0) { toAppendTo.append(" - "); imAppendTo = formatImaginary(-im, new StringBuffer(), pos); toAppendTo.append(imAppendTo); toAppendTo.append(getImaginaryCharacter()); } else if (im > 0.0 || Double.isNaN(im)) { toAppendTo.append(" + "); imAppendTo = formatImaginary(im, new StringBuffer(), pos); toAppendTo.append(imAppendTo); toAppendTo.append(getImaginaryCharacter());
Number re = CompositeFormat.parseNumber(source, getRealFormat(), pos); if (re == null) { return new Complex(re.doubleValue(), 0.0); case '-' : sign = -1; Number im = CompositeFormat.parseNumber(source, getRealFormat(), pos); if (im == null) { if (!CompositeFormat.parseFixedstring(source, getImaginaryCharacter(), pos)) { return null; return new Complex(re.doubleValue(), im.doubleValue() * sign);
ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i"); Complex second = new Complex(2.0, 5.0); Complex answer = c.log(); // natural logarithm. answer = c.cos(); // cosine answer = c.pow(second); // first raised to the power of second ComplexFormat format = new ComplexFormat(); // default format String s1 = format.format(c); // s1 contains "1.110 + 2.222i" String s2 = format.format(second); // s2 contains "2.0 + 5.0i"
String str = "3.23+4.1i"; Complex c = new ComplexFormat().parse(str); double realPart = c.getReal(); double imaginaryPart = c.getImaginary();
ComplexFormat complexFormat = new ComplexFormat(df); studentAnswerComplex = complexFormat.parse(trimmedValue); if (studentAnswerComplex.getImaginary() == 0) { isComplex = false;
ComplexFormat format = new ComplexFormat(); Complex lhs = new Complex(1.0, 3.0); Complex rhs = new Complex(2.0, 5.0); Complex z = new Complex(2.0,2.0); Complex z1 = z.reciprocal(); System.out.println("Recipocal : "+ format.format(z1)); ComplexFormat format = new ComplexFormat(); // default format Complex c = new Complex(1.1111, 2.2222);
boolean range; boolean matchresult = false; ComplexFormat complexFormat = new ComplexFormat(); Complex answerComplex = null; Complex studentAnswerComplex; answerComplex = complexFormat.parse(answer); } catch(MathParseException ex) { log.debug("Number is not Complex: " + answer); matchresult = (studentAnswerComplex != null && answerComplex.equals(studentAnswerComplex));
ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i");
/** * This method calls {@link #format(Object,StringBuffer,FieldPosition)}. * * @param c Complex object to format. * @return A formatted number in the form "Re(c) + Im(c)i". */ public String format(Complex c) { return format(c, new StringBuffer(), new FieldPosition(0)).toString(); }
/** * Returns the default complex format for the current locale. * @return the default complex format. */ public static ComplexFormat getInstance() { return getInstance(Locale.getDefault()); }
/** * Format the absolute value of the imaginary part. * * @param absIm Absolute value of the imaginary part of a complex number. * @param toAppendTo where the text is to be appended. * @param pos On input: an alignment field, if desired. On output: the * offsets of the alignment field. * @return the value passed in as toAppendTo. */ private StringBuffer formatImaginary(double absIm, StringBuffer toAppendTo, FieldPosition pos) { pos.setBeginIndex(0); pos.setEndIndex(0); CompositeFormat.formatDouble(absIm, getImaginaryFormat(), toAppendTo, pos); if (toAppendTo.toString().equals("1")) { // Remove the character "1" if it is the only one. toAppendTo.setLength(0); } return toAppendTo; }
double re = complex.getReal(); CompositeFormat.formatDouble(re, getRealFormat(), toAppendTo, pos); double im = complex.getImaginary(); StringBuffer imAppendTo; if (im < 0.0) { toAppendTo.append(" - "); imAppendTo = formatImaginary(-im, new StringBuffer(), pos); toAppendTo.append(imAppendTo); toAppendTo.append(getImaginaryCharacter()); } else if (im > 0.0 || Double.isNaN(im)) { toAppendTo.append(" + "); imAppendTo = formatImaginary(im, new StringBuffer(), pos); toAppendTo.append(imAppendTo); toAppendTo.append(getImaginaryCharacter());
ComplexFormat complexFormat = new ComplexFormat(df); studentAnswerComplex = complexFormat.parse(trimmedValue); if (studentAnswerComplex.getImaginary() == 0) { isComplex = false;
Number re = CompositeFormat.parseNumber(source, getRealFormat(), pos); if (re == null) { return new Complex(re.doubleValue(), 0.0); case '-' : sign = -1; Number im = CompositeFormat.parseNumber(source, getRealFormat(), pos); if (im == null) { if (!CompositeFormat.parseFixedstring(source, getImaginaryCharacter(), pos)) { return null; return new Complex(re.doubleValue(), im.doubleValue() * sign);
boolean range; boolean matchresult = false; ComplexFormat complexFormat = new ComplexFormat(); Complex answerComplex = null; Complex studentAnswerComplex; answerComplex = complexFormat.parse(answer); } catch(MathParseException ex) { log.debug("Number is not Complex: " + answer); matchresult = (studentAnswerComplex != null && answerComplex.equals(studentAnswerComplex));
ComplexFormat cf = new ComplexFormat(); Complex c = cf.parse("1.110 + 2.222i");
/** * This method calls {@link #format(Object,StringBuffer,FieldPosition)}. * * @param c Complex object to format. * @return A formatted number in the form "Re(c) + Im(c)i". */ public String format(Complex c) { return format(c, new StringBuffer(), new FieldPosition(0)).toString(); }