Example usage for org.apache.commons.math3.complex ComplexFormat ComplexFormat

List of usage examples for org.apache.commons.math3.complex ComplexFormat ComplexFormat

Introduction

In this page you can find the example usage for org.apache.commons.math3.complex ComplexFormat ComplexFormat.

Prototype

public ComplexFormat() 

Source Link

Document

Create an instance with the default imaginary character, 'i', and the default number format for both real and imaginary parts.

Usage

From source file:lirmm.inria.fr.math.TestUtils.java

/**
 * Fails iff values does not contain a number within epsilon of z.
 *
 * @param msg  message to return with failure
 * @param values complex array to search
 * @param z  value sought/*from www.  j  av a  2  s  .  c  o  m*/
 * @param epsilon  tolerance
 */
public static void assertContains(String msg, Complex[] values, Complex z, double epsilon) {
    for (Complex value : values) {
        if (Precision.equals(value.getReal(), z.getReal(), epsilon)
                && Precision.equals(value.getImaginary(), z.getImaginary(), epsilon)) {
            return;
        }
    }
    Assert.fail(msg + " Unable to find " + (new ComplexFormat()).format(z));
}

From source file:org.interpss.mapper.report.AcscResultMapperImpl.java

public static void mapAcscFaultSummary(AcscNetwork faultNet, SimpleFaultAlgorithm algo,
        RptFaultSummaryBean bean) {/* w ww  .j a v  a  2s  . com*/
    double baseKVA = faultNet.getBaseKva();
    Object fault = algo.getFaultList().get(0);
    if (fault instanceof AcscBranchFault) {
        AcscBranchFault fBranch = (AcscBranchFault) fault;
        double baseV = fBranch.getFaultBranch().getFromAcscBus().getBaseVoltage();
        bean.setType(RptFaultSummaryBean.Type_BranchFault);
        bean.setBusId(fBranch.getFaultBranch().getId());
        bean.setBusName(fBranch.getFaultBranch().getName());
        bean.setFaultType("BranchFault");
        bean.setFaultCode(fBranch.getFaultCode().toString());
        bean.setFaultAmpspu(new ComplexFormat().format(fBranch.getFaultResult().getSCCurrent_012().b_1));
        bean.setFaultAmps(new ComplexFormat()
                .format(fBranch.getFaultResult().getSCCurrent_012(UnitType.Amp, baseV, baseKVA).b_1));
        bean.setFaultDistance(Number2String.toStr("##0.0", fBranch.getDistance() * 100.0) + "%");
    } else {
        AcscBusFault fBus = (AcscBusFault) fault;
        double baseV = fBus.getAcscBus().getBaseVoltage();
        bean.setType(RptFaultSummaryBean.Type_BusFault);
        bean.setBusId(fBus.getAcscBus().getId());
        bean.setBusName(fBus.getAcscBus().getName());
        bean.setFaultType("BusFault");
        bean.setFaultCode(fBus.getFaultCode().toString());
        bean.setFaultAmpspu(new ComplexFormat().format(fBus.getFaultResult().getSCCurrent_012().b_1));
        bean.setFaultAmps(new ComplexFormat()
                .format(fBus.getFaultResult().getSCCurrent_012(UnitType.Amp, baseV, baseKVA).b_1));
        bean.setFaultDistance(" ");
    }
}

From source file:org.nmrfx.processor.gui.ComplexOperationItem.java

@Override
public void setFromString(String sValue) {
    ComplexFormat cfTemp = new ComplexFormat();
    Complex oldValue = value;//  w ww .  j av a2 s.c  o m

    Complex newValue = cfTemp.parse(sValue);
    if (newValue == null) {
        return;
    }

    value = newValue;

    listener.changed(this, complexToString(oldValue), complexToString(value));

}