Example usage for org.apache.commons.math.complex Complex pow

List of usage examples for org.apache.commons.math.complex Complex pow

Introduction

In this page you can find the example usage for org.apache.commons.math.complex Complex pow.

Prototype

public Complex pow(Complex x) 

Source Link

Document

Returns of value of this complex number raised to the power of x.

Usage

From source file:geogebra.kernel.GeoVec2D.java

/** c = a ^ b Michael Borcherds 2009-03-10 */
final public static void complexPower(GeoVec2D a, NumberValue b, GeoVec2D c) {
    Complex out = new Complex(a.x, a.y);
    out = out.pow(new Complex(b.getDouble(), 0));
    c.x = out.getReal();/*  w  ww  .j  a v a  2  s  . com*/
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:geogebra.common.kernel.geos.GeoVec2D.java

/**
 * c = cbrt(a) Michael Borcherds 2010-02-07
 * //  w w w  .j av a 2s .  c o  m
 * @param a
 *            a
 * @param c
 *            c
 */
final public static void complexCbrt(GeoVec2D a, GeoVec2D c) {
    Complex out = new Complex(a.x, a.y);
    out = out.pow(new Complex(1 / 3d, 0));
    c.x = out.getReal();
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:geogebra.common.kernel.geos.GeoVec2D.java

/**
 * c = a ^ b Michael Borcherds 2009-03-14
 * /*from ww w.  j  av a2s  .c o  m*/
 * @param a
 *            base
 * @param b
 *            exponent
 * @param c
 *            result
 */
final public static void complexPower(GeoVec2D a, GeoVec2D b, GeoVec2D c) {
    Complex out = new Complex(a.x, a.y);
    out = out.pow(new Complex(b.x, b.y));
    c.x = out.getReal();
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:geogebra.common.kernel.geos.GeoVec2D.java

/**
 * c = a ^ b Michael Borcherds 2009-03-10
 * /* w  w  w .j  av a2s .  com*/
 * @param a
 *            base
 * @param b
 *            exponent
 * @param c
 *            result
 */
final public static void complexPower(NumberValue a, GeoVec2D b, GeoVec2D c) {
    Complex out = new Complex(a.getDouble(), 0);
    out = out.pow(new Complex(b.x, b.y));
    c.x = out.getReal();
    c.y = out.getImaginary();
    c.setMode(Kernel.COORD_COMPLEX);
}

From source file:org.renjin.primitives.Ops.java

@Deferrable
@Builtin("^")/*from  ww  w .  j av a 2  s . c om*/
@DataParallel(PreserveAttributeStyle.ALL)
public static Complex power(Complex x, Complex y) {
    // handle common cases with better precision than the log(exp(x)*y) trick used by Apache Commons
    if (y.getImaginary() == 0) {
        double yr = y.getReal();
        if (yr == 0) {
            return new Complex(1, 0);
        } else if (yr == 1) {
            return x;
        } else {
            int k = (int) yr;
            if (k == yr && k < 65536) {
                return power(x, k);
            }
        }
    }

    return x.pow(y);
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.ByteDataset.java

@Override
public ByteDataset ipower(final Object b) {
    if (b instanceof AbstractDataset) {
        AbstractDataset bds = (AbstractDataset) b;
        checkCompatibility(bds);/*from ww w.  ja v a 2  s . c o m*/
        // BOOLEAN_OMIT
        IndexIterator it1 = getIterator();
        IndexIterator it2 = bds.getIterator();
        // BOOLEAN_OMIT
        while (it1.hasNext() && it2.hasNext()) {
            final double v = Math.pow(data[it1.index], bds.getElementDoubleAbs(it2.index));
            if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                data[it1.index] = 0; // INT_ZEROTEST
            } else { // INT_ZEROTEST
                data[it1.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
            } // INT_ZEROTEST
        }
    } else {
        double vr = toReal(b);
        double vi = toImag(b);
        IndexIterator it1 = getIterator();
        // BOOLEAN_OMIT
        if (vi == 0.) {
            while (it1.hasNext()) {
                final double v = Math.pow(data[it1.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                    data[it1.index] = 0; // INT_ZEROTEST
                } else { // INT_ZEROTEST
                    data[it1.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_ZEROTEST
            }
        } else {
            Complex zv = new Complex(vr, vi);
            while (it1.hasNext()) {
                Complex zd = new Complex(data[it1.index], 0.);
                final double v = zd.pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                    data[it1.index] = 0; // INT_ZEROTEST
                } else { // INT_ZEROTEST
                    data[it1.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_ZEROTEST
            }
        }
    }
    setDirty();
    return this;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.DoubleDataset.java

@Override
public DoubleDataset ipower(final Object b) {
    if (b instanceof AbstractDataset) { // BOOLEAN_OMIT
        AbstractDataset bds = (AbstractDataset) b; // BOOLEAN_OMIT
        checkCompatibility(bds); // BOOLEAN_OMIT
        // BOOLEAN_OMIT
        IndexIterator it1 = getIterator(); // BOOLEAN_OMIT
        IndexIterator it2 = bds.getIterator(); // BOOLEAN_OMIT
        // BOOLEAN_OMIT
        while (it1.hasNext() && it2.hasNext()) { // BOOLEAN_OMIT
            final double v = Math.pow(data[it1.index], bds.getElementDoubleAbs(it2.index)); // BOOLEAN_OMIT
            // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
            //    data[it1.index] = 0; // INT_ZEROTEST
            // } else { // INT_ZEROTEST
            data[it1.index] = v; // PRIM_TYPE_LONG // BOOLEAN_OMIT // ADD_CAST
            // } // INT_ZEROTEST
        } // BOOLEAN_OMIT
    } else { // BOOLEAN_OMIT
        double vr = toReal(b); // BOOLEAN_OMIT
        double vi = toImag(b); // BOOLEAN_OMIT
        IndexIterator it1 = getIterator(); // BOOLEAN_OMIT
        // BOOLEAN_OMIT
        if (vi == 0.) { // BOOLEAN_OMIT
            while (it1.hasNext()) { // BOOLEAN_OMIT
                final double v = Math.pow(data[it1.index], vr); // BOOLEAN_OMIT
                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                //    data[it1.index] = 0; // INT_ZEROTEST
                // } else { // INT_ZEROTEST
                data[it1.index] = v; // PRIM_TYPE_LONG // BOOLEAN_OMIT // ADD_CAST
                // } // INT_ZEROTEST
            } // BOOLEAN_OMIT
        } else { // BOOLEAN_OMIT
            Complex zv = new Complex(vr, vi); // BOOLEAN_OMIT
            while (it1.hasNext()) { // BOOLEAN_OMIT
                Complex zd = new Complex(data[it1.index], 0.); // BOOLEAN_OMIT
                final double v = zd.pow(zv).getReal(); // BOOLEAN_OMIT
                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                //    data[it1.index] = 0; // INT_ZEROTEST
                // } else { // INT_ZEROTEST
                data[it1.index] = v; // PRIM_TYPE_LONG // BOOLEAN_OMIT // ADD_CAST
                // } // INT_ZEROTEST
            } // BOOLEAN_OMIT
        } // BOOLEAN_OMIT
    } // BOOLEAN_OMIT
    setDirty(); // BOOLEAN_OMIT
    return this;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.FloatDataset.java

@Override
public FloatDataset ipower(final Object b) {
    if (b instanceof AbstractDataset) {
        AbstractDataset bds = (AbstractDataset) b;
        checkCompatibility(bds);/*from w w w  .jav  a  2s .c o m*/
        // BOOLEAN_OMIT
        IndexIterator it1 = getIterator();
        IndexIterator it2 = bds.getIterator();
        // BOOLEAN_OMIT
        while (it1.hasNext() && it2.hasNext()) {
            final double v = Math.pow(data[it1.index], bds.getElementDoubleAbs(it2.index));
            // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
            //    data[it1.index] = 0; // INT_ZEROTEST
            // } else { // INT_ZEROTEST
            data[it1.index] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
            // } // INT_ZEROTEST
        }
    } else {
        double vr = toReal(b);
        double vi = toImag(b);
        IndexIterator it1 = getIterator();
        // BOOLEAN_OMIT
        if (vi == 0.) {
            while (it1.hasNext()) {
                final double v = Math.pow(data[it1.index], vr);
                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                //    data[it1.index] = 0; // INT_ZEROTEST
                // } else { // INT_ZEROTEST
                data[it1.index] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
                // } // INT_ZEROTEST
            }
        } else {
            Complex zv = new Complex(vr, vi);
            while (it1.hasNext()) {
                Complex zd = new Complex(data[it1.index], 0.);
                final double v = zd.pow(zv).getReal();
                // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                //    data[it1.index] = 0; // INT_ZEROTEST
                // } else { // INT_ZEROTEST
                data[it1.index] = (float) v; // PRIM_TYPE_LONG // ADD_CAST
                // } // INT_ZEROTEST
            }
        }
    }
    setDirty();
    return this;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.IntegerDataset.java

@Override
public IntegerDataset ipower(final Object b) {
    if (b instanceof AbstractDataset) {
        AbstractDataset bds = (AbstractDataset) b;
        checkCompatibility(bds);/*from   w  ww . j a v a 2 s . co m*/
        // BOOLEAN_OMIT
        IndexIterator it1 = getIterator();
        IndexIterator it2 = bds.getIterator();
        // BOOLEAN_OMIT
        while (it1.hasNext() && it2.hasNext()) {
            final double v = Math.pow(data[it1.index], bds.getElementDoubleAbs(it2.index));
            if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                data[it1.index] = 0; // INT_ZEROTEST
            } else { // INT_ZEROTEST
                data[it1.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
            } // INT_ZEROTEST
        }
    } else {
        double vr = toReal(b);
        double vi = toImag(b);
        IndexIterator it1 = getIterator();
        // BOOLEAN_OMIT
        if (vi == 0.) {
            while (it1.hasNext()) {
                final double v = Math.pow(data[it1.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                    data[it1.index] = 0; // INT_ZEROTEST
                } else { // INT_ZEROTEST
                    data[it1.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_ZEROTEST
            }
        } else {
            Complex zv = new Complex(vr, vi);
            while (it1.hasNext()) {
                Complex zd = new Complex(data[it1.index], 0.);
                final double v = zd.pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                    data[it1.index] = 0; // INT_ZEROTEST
                } else { // INT_ZEROTEST
                    data[it1.index] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_ZEROTEST
            }
        }
    }
    setDirty();
    return this;
}

From source file:uk.ac.diamond.scisoft.analysis.dataset.LongDataset.java

@Override
public LongDataset ipower(final Object b) {
    if (b instanceof AbstractDataset) {
        AbstractDataset bds = (AbstractDataset) b;
        checkCompatibility(bds);//from  w  w w.  j av  a2 s  .  c  o  m
        // BOOLEAN_OMIT
        IndexIterator it1 = getIterator();
        IndexIterator it2 = bds.getIterator();
        // BOOLEAN_OMIT
        while (it1.hasNext() && it2.hasNext()) {
            final double v = Math.pow(data[it1.index], bds.getElementDoubleAbs(it2.index));
            if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                data[it1.index] = 0; // INT_ZEROTEST
            } else { // INT_ZEROTEST
                data[it1.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
            } // INT_ZEROTEST
        }
    } else {
        double vr = toReal(b);
        double vi = toImag(b);
        IndexIterator it1 = getIterator();
        // BOOLEAN_OMIT
        if (vi == 0.) {
            while (it1.hasNext()) {
                final double v = Math.pow(data[it1.index], vr);
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                    data[it1.index] = 0; // INT_ZEROTEST
                } else { // INT_ZEROTEST
                    data[it1.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_ZEROTEST
            }
        } else {
            Complex zv = new Complex(vr, vi);
            while (it1.hasNext()) {
                Complex zd = new Complex(data[it1.index], 0.);
                final double v = zd.pow(zv).getReal();
                if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_ZEROTEST
                    data[it1.index] = 0; // INT_ZEROTEST
                } else { // INT_ZEROTEST
                    data[it1.index] = (long) v; // PRIM_TYPE_LONG // ADD_CAST
                } // INT_ZEROTEST
            }
        }
    }
    setDirty();
    return this;
}