List of usage examples for org.apache.commons.math3.complex Complex pow
public Complex pow(double x)
From source file:com.autsia.bracer.BracerParser.java
/** * Evaluates once parsed math expression with "var" variable included * * @param variableValue User-specified <code>Double</code> value * @return <code>String</code> representation of the result * @throws <code>ParseException</code> if the input expression is not * correct * @since 3.0/*from w ww . j a v a2s . c om*/ */ public String evaluate(double variableValue) throws ParseException { /* check if is there something to evaluate */ if (stackRPN.empty()) { return ""; } /* clean answer stack */ stackAnswer.clear(); /* get the clone of the RPN stack for further evaluating */ @SuppressWarnings("unchecked") Stack<String> stackRPN = (Stack<String>) this.stackRPN.clone(); /* enroll the variable value into expression */ Collections.replaceAll(stackRPN, VARIABLE, Double.toString(variableValue)); /* evaluating the RPN expression */ while (!stackRPN.empty()) { String token = stackRPN.pop(); if (isNumber(token)) { stackAnswer.push(token); } else if (isOperator(token)) { Complex a = complexFormat.parse(stackAnswer.pop()); Complex b = complexFormat.parse(stackAnswer.pop()); boolean aBoolean = a.getReal() == 1.0; boolean bBoolean = b.getReal() == 1.0; switch (token) { case "+": stackAnswer.push(complexFormat.format(b.add(a))); break; case "-": stackAnswer.push(complexFormat.format(b.subtract(a))); break; case "*": stackAnswer.push(complexFormat.format(b.multiply(a))); break; case "/": stackAnswer.push(complexFormat.format(b.divide(a))); break; case "|": stackAnswer.push(String.valueOf(aBoolean || bBoolean ? "1" : "0")); break; case "&": stackAnswer.push(String.valueOf(aBoolean && bBoolean ? "1" : "0")); break; } } else if (isFunction(token)) { Complex a = complexFormat.parse(stackAnswer.pop()); boolean aBoolean = a.getReal() == 1.0; switch (token) { case "abs": stackAnswer.push(complexFormat.format(a.abs())); break; case "acos": stackAnswer.push(complexFormat.format(a.acos())); break; case "arg": stackAnswer.push(complexFormat.format(a.getArgument())); break; case "asin": stackAnswer.push(complexFormat.format(a.asin())); break; case "atan": stackAnswer.push(complexFormat.format(a.atan())); break; case "conj": stackAnswer.push(complexFormat.format(a.conjugate())); break; case "cos": stackAnswer.push(complexFormat.format(a.cos())); break; case "cosh": stackAnswer.push(complexFormat.format(a.cosh())); break; case "exp": stackAnswer.push(complexFormat.format(a.exp())); break; case "imag": stackAnswer.push(complexFormat.format(a.getImaginary())); break; case "log": stackAnswer.push(complexFormat.format(a.log())); break; case "neg": stackAnswer.push(complexFormat.format(a.negate())); break; case "real": stackAnswer.push(complexFormat.format(a.getReal())); break; case "sin": stackAnswer.push(complexFormat.format(a.sin())); break; case "sinh": stackAnswer.push(complexFormat.format(a.sinh())); break; case "sqrt": stackAnswer.push(complexFormat.format(a.sqrt())); break; case "tan": stackAnswer.push(complexFormat.format(a.tan())); break; case "tanh": stackAnswer.push(complexFormat.format(a.tanh())); break; case "pow": Complex b = complexFormat.parse(stackAnswer.pop()); stackAnswer.push(complexFormat.format(b.pow(a))); break; case "not": stackAnswer.push(String.valueOf(!aBoolean ? "1" : "0")); break; } } } if (stackAnswer.size() > 1) { throw new ParseException("Some operator is missing", 0); } return stackAnswer.pop(); }
From source file:com.calc.BracerParser.java
/** * Evaluates once parsed math expression with "var" variable included * * @param variableValue User-specified <code>Double</code> value * @return <code>String</code> representation of the result * @throws <code>ParseException</code> if the input expression is not * correct * @since 3.0/*w w w. j a v a 2s . com*/ */ public String evaluate(double variableValue) throws ParseException { /* check if is there something to evaluate */ if (stackRPN.empty()) { return ""; } /* clean answer stack */ stackAnswer.clear(); /* get the clone of the RPN stack for further evaluating */ @SuppressWarnings("unchecked") Stack<String> stackRPN = (Stack<String>) this.stackRPN.clone(); /* enroll the variable value into expression */ Collections.replaceAll(stackRPN, VARIABLE, Double.toString(variableValue)); /* evaluating the RPN expression */ while (!stackRPN.empty()) { String token = stackRPN.pop(); if (isNumber(token)) { stackAnswer.push(token); } else if (isOperator(token)) { Complex a = complexFormat.parse(stackAnswer.pop()); Complex b = complexFormat.parse(stackAnswer.pop()); boolean aBoolean = a.getReal() == 1.0; boolean bBoolean = b.getReal() == 1.0; switch (token) { case "+": stackAnswer.push(complexFormat.format(b.add(a))); break; case "-": stackAnswer.push(complexFormat.format(b.subtract(a))); break; case "*": stackAnswer.push(complexFormat.format(b.multiply(a))); break; case "/": stackAnswer.push(complexFormat.format(b.divide(a))); break; case "|": stackAnswer.push(String.valueOf(aBoolean || bBoolean ? "1" : "0")); break; case "&": stackAnswer.push(String.valueOf(aBoolean && bBoolean ? "1" : "0")); break; } } else if (isFunction(token)) { Complex a = complexFormat.parse(stackAnswer.pop()); boolean aBoolean = a.getReal() == 1.0; switch (token) { case "fat": stackAnswer.push(complexFormat.format(a.abs())); break; case "fib": stackAnswer.push(complexFormat.format(a.acos())); break; case "arg": stackAnswer.push(complexFormat.format(a.getArgument())); break; case "asin": stackAnswer.push(complexFormat.format(a.asin())); break; case "atan": stackAnswer.push(complexFormat.format(a.atan())); break; case "conj": stackAnswer.push(complexFormat.format(a.conjugate())); break; case "cos": stackAnswer.push(complexFormat.format(a.cos())); break; case "cosh": stackAnswer.push(complexFormat.format(a.cosh())); break; case "exp": stackAnswer.push(complexFormat.format(a.exp())); break; case "imag": stackAnswer.push(complexFormat.format(a.getImaginary())); break; case "log": stackAnswer.push(complexFormat.format(a.log())); break; case "neg": stackAnswer.push(complexFormat.format(a.negate())); break; case "real": stackAnswer.push(complexFormat.format(a.getReal())); break; case "sin": stackAnswer.push(complexFormat.format(a.sin())); break; case "sinh": stackAnswer.push(complexFormat.format(a.sinh())); break; case "sqrt": stackAnswer.push(complexFormat.format(a.sqrt())); break; case "tan": stackAnswer.push(complexFormat.format(a.tan())); break; case "tanh": stackAnswer.push(complexFormat.format(a.tanh())); break; case "pow": Complex b = complexFormat.parse(stackAnswer.pop()); stackAnswer.push(complexFormat.format(b.pow(a))); break; case "not": stackAnswer.push(String.valueOf(!aBoolean ? "1" : "0")); break; } } } if (stackAnswer.size() > 1) { throw new ParseException("Some operator is missing", 0); } return stackAnswer.pop(); }
From source file:org.eclipse.dataset.ByteDataset.java
@Override public ByteDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }/*from www . j a v a 2 s.c o m*/ } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { Complex zd = new Complex(data[it.index], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(data[it.index], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index] = 0; // INT_USE } else { // INT_USE data[it.index] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); final double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } else {// NAN_OMIT while (it.hasNext()) { final double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } setDirty(); return this; }
From source file:org.eclipse.dataset.CompoundByteDataset.java
@Override public CompoundByteDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final int is = bds.getElementsPerItem(); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }//w w w .java 2 s . c om } } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { for (int i = 0; i < isize; i++) { Complex zd = new Complex(data[it.index + i], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else if (is == 1) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else if (is == isize) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { while (it.hasNext()) { double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (byte) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } setDirty(); return this; }
From source file:org.eclipse.dataset.CompoundDoubleDataset.java
@Override public CompoundDoubleDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final int is = bds.getElementsPerItem(); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE }//from w w w . j a va2s . c om } } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { for (int i = 0; i < isize; i++) { Complex zd = new Complex(data[it.index + i], 0); final double v = zd.pow(zv).getReal(); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } } else if (is == 1) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } else if (is == isize) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i)); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); double v = new Complex(it.aDouble, 0).pow(zv).getReal(); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex] = 0; // INT_USE // } else { // INT_USE data[it.aIndex] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE for (int i = 1; i < isize; i++) { v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal(); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex + i] = 0; // INT_USE // } else { // INT_USE data[it.aIndex + i] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } else { while (it.hasNext()) { double v = Math.pow(it.aDouble, it.bDouble); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex] = 0; // INT_USE // } else { // INT_USE data[it.aIndex] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE for (int i = 1; i < isize; i++) { v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i)); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex + i] = 0; // INT_USE // } else { // INT_USE data[it.aIndex + i] = v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } } setDirty(); return this; }
From source file:org.eclipse.dataset.CompoundFloatDataset.java
@Override public CompoundFloatDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final int is = bds.getElementsPerItem(); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE }// w ww . j a v a2 s . c o m } } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { for (int i = 0; i < isize; i++) { Complex zd = new Complex(data[it.index + i], 0); final double v = zd.pow(zv).getReal(); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } } else if (is == 1) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } else if (is == isize) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i)); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.index + i] = 0; // INT_USE // } else { // INT_USE data[it.index + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); double v = new Complex(it.aDouble, 0).pow(zv).getReal(); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex] = 0; // INT_USE // } else { // INT_USE data[it.aIndex] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE for (int i = 1; i < isize; i++) { v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal(); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex + i] = 0; // INT_USE // } else { // INT_USE data[it.aIndex + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } else { while (it.hasNext()) { double v = Math.pow(it.aDouble, it.bDouble); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex] = 0; // INT_USE // } else { // INT_USE data[it.aIndex] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE for (int i = 1; i < isize; i++) { v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i)); // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // data[it.aIndex + i] = 0; // INT_USE // } else { // INT_USE data[it.aIndex + i] = (float) v; // PRIM_TYPE_LONG // ADD_CAST // } // INT_USE } } } } setDirty(); return this; }
From source file:org.eclipse.dataset.CompoundIntegerDataset.java
@Override public CompoundIntegerDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final int is = bds.getElementsPerItem(); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }// w ww .ja va 2 s . co m } } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { for (int i = 0; i < isize; i++) { Complex zd = new Complex(data[it.index + i], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else if (is == 1) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else if (is == isize) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { while (it.hasNext()) { double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (int) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } setDirty(); return this; }
From source file:org.eclipse.dataset.CompoundLongDataset.java
@Override public CompoundLongDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final int is = bds.getElementsPerItem(); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }//from w w w .j a v a 2 s. c o m } } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { for (int i = 0; i < isize; i++) { Complex zd = new Complex(data[it.index + i], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else if (is == 1) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else if (is == isize) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { while (it.hasNext()) { double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } setDirty(); return this; }
From source file:org.eclipse.dataset.CompoundShortDataset.java
@Override public CompoundShortDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); final int is = bds.getElementsPerItem(); if (bds.getSize() == 1) { final double vr = bds.getElementDoubleAbs(0); final IndexIterator it = getIterator(); if (bds.isComplex()) { final double vi = bds.getElementDoubleAbs(1); if (vi == 0) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE }//w w w . j a v a 2 s. c o m } } else { final Complex zv = new Complex(vr, vi); while (it.hasNext()) { for (int i = 0; i < isize; i++) { Complex zd = new Complex(data[it.index + i], 0); final double v = zd.pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else if (is == 1) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], vr); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else if (is == isize) { while (it.hasNext()) { for (int i = 0; i < isize; i++) { final double v = Math.pow(data[it.index + i], bds.getElementDoubleAbs(i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.index + i] = 0; // INT_USE } else { // INT_USE data[it.index + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } else { final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); it.setOutputDouble(true); if (bds.isComplex()) { while (it.hasNext()) { final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); double v = new Complex(it.aDouble, 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = new Complex(data[it.aIndex + i], 0).pow(zv).getReal(); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } else { while (it.hasNext()) { double v = Math.pow(it.aDouble, it.bDouble); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex] = 0; // INT_USE } else { // INT_USE data[it.aIndex] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE for (int i = 1; i < isize; i++) { v = Math.pow(data[it.aIndex + i], bds.getElementDoubleAbs(it.bIndex + i)); if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE data[it.aIndex + i] = 0; // INT_USE } else { // INT_USE data[it.aIndex + i] = (short) (long) v; // PRIM_TYPE_LONG // ADD_CAST } // INT_USE } } } } setDirty(); return this; }
From source file:org.eclipse.dataset.DoubleDataset.java
@Override public DoubleDataset ipower(final Object b) { Dataset bds = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b); // NAN_OMIT if (bds.getSize() == 1) { // NAN_OMIT final double vr = bds.getElementDoubleAbs(0); // NAN_OMIT final IndexIterator it = getIterator(); // NAN_OMIT if (bds.isComplex()) { // NAN_OMIT final double vi = bds.getElementDoubleAbs(1); // NAN_OMIT if (vi == 0) { // NAN_OMIT while (it.hasNext()) { // NAN_OMIT final double v = Math.pow(data[it.index], vr); // NAN_OMIT // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // NAN_OMIT // data[it.index] = 0; // INT_USE // NAN_OMIT // } else { // INT_USE // NAN_OMIT data[it.index] = v; // PRIM_TYPE_LONG // NAN_OMIT // ADD_CAST // } // INT_USE // NAN_OMIT } // NAN_OMIT } else { // NAN_OMIT final Complex zv = new Complex(vr, vi); // NAN_OMIT while (it.hasNext()) { // NAN_OMIT Complex zd = new Complex(data[it.index], 0); // NAN_OMIT final double v = zd.pow(zv).getReal(); // NAN_OMIT // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // NAN_OMIT // data[it.index] = 0; // INT_USE // NAN_OMIT // } else { // INT_USE // NAN_OMIT data[it.index] = v; // PRIM_TYPE_LONG // NAN_OMIT // ADD_CAST // } // INT_USE // NAN_OMIT } // NAN_OMIT } // NAN_OMIT } else {// NAN_OMIT while (it.hasNext()) { // NAN_OMIT final double v = Math.pow(data[it.index], vr); // NAN_OMIT // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // NAN_OMIT // data[it.index] = 0; // INT_USE // NAN_OMIT // } else { // INT_USE // NAN_OMIT data[it.index] = v; // PRIM_TYPE_LONG // NAN_OMIT // ADD_CAST // } // INT_USE // NAN_OMIT } // NAN_OMIT } // NAN_OMIT } else { // NAN_OMIT final BroadcastIterator it = BroadcastIterator.createIterator(this, bds); // NAN_OMIT it.setOutputDouble(true); // NAN_OMIT if (bds.isComplex()) { // NAN_OMIT while (it.hasNext()) { // NAN_OMIT final Complex zv = new Complex(it.bDouble, bds.getElementDoubleAbs(it.bIndex + 1)); // NAN_OMIT final double v = new Complex(it.aDouble, 0).pow(zv).getReal(); // NAN_OMIT // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // NAN_OMIT // data[it.aIndex] = 0; // INT_USE // NAN_OMIT // } else { // INT_USE // NAN_OMIT data[it.aIndex] = v; // PRIM_TYPE_LONG // NAN_OMIT // ADD_CAST // } // INT_USE // NAN_OMIT } // NAN_OMIT } else {// NAN_OMIT while (it.hasNext()) { // NAN_OMIT final double v = Math.pow(it.aDouble, it.bDouble); // NAN_OMIT // if (Double.isInfinite(v) || Double.isNaN(v)) { // INT_USE // NAN_OMIT // data[it.aIndex] = 0; // INT_USE // NAN_OMIT // } else { // INT_USE // NAN_OMIT data[it.aIndex] = v; // PRIM_TYPE_LONG // NAN_OMIT // ADD_CAST // } // INT_USE // NAN_OMIT } // NAN_OMIT } // NAN_OMIT } // NAN_OMIT setDirty(); // NAN_OMIT return this; }