Search in sources :

Example 26 with Apfloat

use of org.apfloat.Apfloat in project symja_android_library by axkr.

the class TeXFormFactory method convertApcomplex.

public void convertApcomplex(final StringBuilder buf, final Apcomplex dc, final int precedence, boolean caller) {
    if (Precedence.PLUS < precedence) {
        if (caller == PLUS_CALL) {
            buf.append(" + ");
            caller = false;
        }
        buf.append("\\left( ");
    }
    Apfloat realPart = dc.real();
    Apfloat imaginaryPart = dc.imag();
    boolean realZero = realPart.equals(Apcomplex.ZERO);
    boolean imaginaryZero = imaginaryPart.equals(Apcomplex.ZERO);
    if (realZero && imaginaryZero) {
        convertDoubleString(buf, "0.0", Precedence.PLUS, false);
    } else {
        if (!realZero) {
            buf.append(convertApfloatToFormattedString(realPart));
            if (!imaginaryZero) {
                buf.append(" + ");
                final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
                convertDoubleString(buf, convertApfloatToFormattedString(imaginaryPart), Precedence.TIMES, isNegative);
                // InvisibleTimes
                buf.append("\\,");
                buf.append("i ");
            }
        } else {
            if (caller == PLUS_CALL) {
                buf.append("+");
                caller = false;
            }
            final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
            convertDoubleString(buf, convertApfloatToFormattedString(imaginaryPart), Precedence.TIMES, isNegative);
            // InvisibleTimes
            buf.append("\\,");
            buf.append("i ");
        }
    }
    if (Precedence.PLUS < precedence) {
        buf.append("\\right) ");
    }
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 27 with Apfloat

use of org.apfloat.Apfloat in project symja_android_library by axkr.

the class MathMLFormFactory method convertApcomplex.

public void convertApcomplex(final StringBuilder buf, final Apcomplex ac, final int precedence) {
    Apfloat realPart = ac.real();
    Apfloat imaginaryPart = ac.imag();
    final boolean isImNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
    tagStart(buf, "mrow");
    if (Precedence.PLUS < precedence) {
        tag(buf, "mo", "(");
    }
    // convertApfloat(buf, realPart);
    buf.append(convertApfloatToFormattedString(realPart));
    if (isImNegative) {
        tag(buf, "mo", "-");
        imaginaryPart = imaginaryPart.negate();
    } else {
        tag(buf, "mo", "+");
    }
    // convertApfloat(buf, imaginaryPart);
    buf.append(convertApfloatToFormattedString(imaginaryPart));
    // <!ENTITY InvisibleTimes "&#x2062;" >
    // <!ENTITY CenterDot "&#0183;" >
    tag(buf, "mo", "&#0183;");
    // <!ENTITY ImaginaryI "&#x2148;" >
    // "&#x2148;");
    tag(buf, "mi", "&#x2148;");
    if (Precedence.PLUS < precedence) {
        tag(buf, "mo", ")");
    }
    tagEnd(buf, "mrow");
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 28 with Apfloat

use of org.apfloat.Apfloat in project symja_android_library by axkr.

the class DoubleFormFactory method convertApcomplex.

public void convertApcomplex(final StringBuilder buf, final Apcomplex dc, final int precedence, boolean caller) {
    if (Precedence.PLUS < precedence) {
        if (caller == PLUS_CALL) {
            append(buf, "+");
            caller = false;
        }
        append(buf, "(");
    }
    Apfloat realPart = dc.real();
    Apfloat imaginaryPart = dc.imag();
    boolean realZero = realPart.equals(Apcomplex.ZERO);
    boolean imaginaryZero = imaginaryPart.equals(Apcomplex.ZERO);
    if (realZero && imaginaryZero) {
        convertDoubleString(buf, "0.0", Precedence.PLUS, false);
    } else {
        if (!realZero) {
            append(buf, convertApfloat(realPart));
            if (!imaginaryZero) {
                append(buf, "+I*");
                final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
                convertDoubleString(buf, convertApfloat(imaginaryPart), Precedence.TIMES, isNegative);
            }
        } else {
            if (caller == PLUS_CALL) {
                append(buf, "+");
                caller = false;
            }
            append(buf, "I*");
            final boolean isNegative = imaginaryPart.compareTo(Apcomplex.ZERO) < 0;
            convertDoubleString(buf, convertApfloat(imaginaryPart), Precedence.TIMES, isNegative);
        }
    }
    if (Precedence.PLUS < precedence) {
        append(buf, ")");
    }
}
Also used : Apfloat(org.apfloat.Apfloat)

Example 29 with Apfloat

use of org.apfloat.Apfloat in project symja_android_library by axkr.

the class FuzzyParser 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];
    int numFormat = ((Integer) result[1]);
    try {
        if (negative) {
            number = '-' + number;
        }
        if (numFormat == 10 && fCurrentChar == '`') {
            numFormat = -1;
        }
        if (numFormat < 0) {
            if (fCurrentChar == '`' && isValidPosition()) {
                fCurrentPosition++;
                if (isValidPosition() && fInputString[fCurrentPosition] == '`') {
                    fCurrentPosition += 2;
                    long precision = getJavaLong();
                    if (precision < ParserConfig.MACHINE_PRECISION) {
                        precision = ParserConfig.MACHINE_PRECISION;
                    }
                    return F.num(new Apfloat(number, precision));
                } else {
                    fCurrentPosition++;
                    long precision = getJavaLong();
                    if (precision < ParserConfig.MACHINE_PRECISION) {
                        precision = ParserConfig.MACHINE_PRECISION;
                    }
                    return F.num(new Apfloat(number, precision));
                }
            }
            temp = new NumStr(number);
        // temp = fFactory.createDouble(number);
        } else {
            temp = F.ZZ(number, numFormat);
        // temp = fFactory.createInteger(number, numFormat);
        }
    } catch (final RuntimeException rex) {
        throwSyntaxError("Number format error: " + number, number.length());
    }
    getNextToken();
    return temp;
}
Also used : NumStr(org.matheclipse.core.expression.NumStr) IExpr(org.matheclipse.core.interfaces.IExpr) Apfloat(org.apfloat.Apfloat)

Aggregations

Apfloat (org.apfloat.Apfloat)29 IExpr (org.matheclipse.core.interfaces.IExpr)8 FixedPrecisionApfloatHelper (org.apfloat.FixedPrecisionApfloatHelper)7 Apcomplex (org.apfloat.Apcomplex)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 Apint (org.apfloat.Apint)3 IAST (org.matheclipse.core.interfaces.IAST)3 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)3 IComplexNum (org.matheclipse.core.interfaces.IComplexNum)3 IInteger (org.matheclipse.core.interfaces.IInteger)3 INum (org.matheclipse.core.interfaces.INum)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 BigIntegerNode (com.fasterxml.jackson.databind.node.BigIntegerNode)2 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)2 DecimalNode (com.fasterxml.jackson.databind.node.DecimalNode)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)2 FloatNode (com.fasterxml.jackson.databind.node.FloatNode)2 IntNode (com.fasterxml.jackson.databind.node.IntNode)2 LongNode (com.fasterxml.jackson.databind.node.LongNode)2 NullNode (com.fasterxml.jackson.databind.node.NullNode)2