Example usage for java.lang Math expm1

List of usage examples for java.lang Math expm1

Introduction

In this page you can find the example usage for java.lang Math expm1.

Prototype

public static double expm1(double x) 

Source Link

Document

Returns ex -1.

Usage

From source file:Main.java

public static void main(String[] args) {

    double x = 5;
    double y = 0.5;

    // call expm1 for both numbers and print the result
    System.out.println("Math.expm1(" + x + ")=" + Math.expm1(x));
    System.out.println("Math.expm1(" + y + ")=" + Math.expm1(y));

}

From source file:org.broadinstitute.gatk.utils.MathUtils.java

/**
 * Calculates {@code log(1-exp(a))} without loosing precision.
 *
 * <p>//from  w w w. j ava  2  s . c om
 *     This is based on the approach described in:
 *
 * </p>
 * <p>
 *     Maechler M, Accurately Computing log(1-exp(-|a|)) Assessed by the Rmpfr package, 2012 <br/>
 *     <a ref="http://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf">Online document</a>.
 *
 * </p>
 *
 * @param a the input exponent.
 * @return {@link Double#NaN NaN} if {@code a > 0}, otherwise the corresponding value.
 */
public static double log1mexp(final double a) {
    if (a > 0)
        return Double.NaN;
    if (a == 0)
        return Double.NEGATIVE_INFINITY;

    return (a < LOG1MEXP_THRESHOLD) ? Math.log1p(-Math.exp(a)) : Math.log(-Math.expm1(a));
}

From source file:org.cirdles.ludwig.isoplot3.Pub.java

/**
 * Ludwig specifies Return radiogenic 207Pb/206Pb (secular equilibrium). All
 * calculations in annum.//from  w  ww.j  a v a  2 s  . c o m
 *
 * @param age
 * @param lambda235
 * @param lambda238
 * @param uRatio
 * @return double [1] containing radiogenic 207Pb/206Pb.
 */
public static double[] pb76(double age, double lambda235, double lambda238, double uRatio) {
    double[] retVal;

    if (age == 0.0) {
        retVal = new double[] { lambda235 / lambda238 / uRatio };
    } else {
        retVal = new double[] { Math.expm1(lambda235 * age) / Math.expm1(lambda238 * age) / uRatio };
    }

    return retVal;
}

From source file:org.eclipse.dataset.Maths.java

/**
 * expm1 - evaluate the exponential function - 1 on each element of the dataset
 * @param a//  w  ww .ja v  a2s .c o m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset expm1(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDtype();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.expm1(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.expm1(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.expm1(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.expm1(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.expm1(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.expm1(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.expm1(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.expm1(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.expm1(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.expm1(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.expm1(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.expm1(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.expm1(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.expm1(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.expm1(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.expm1(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.expm1(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.expm1(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.expm1(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.expm1(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.expm1(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.expm1(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.expm1(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.expm1(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.expm1(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.expm1(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float tf;
                float ox;
                float oy;
                tf = (float) (Math.expm1(ix));
                ox = (float) (tf * Math.cos(iy));
                oy = (float) (tf * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                float tf;
                float ox;
                float oy;
                tf = (float) (Math.expm1(ix));
                ox = (float) (tf * Math.cos(iy));
                oy = (float) (tf * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double tf;
                double ox;
                double oy;
                tf = (Math.expm1(ix));
                ox = (tf * Math.cos(iy));
                oy = (tf * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                double tf;
                double ox;
                double oy;
                tf = (Math.expm1(ix));
                ox = (tf * Math.cos(iy));
                oy = (tf * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "expm1 supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "expm1");
    return result;
}

From source file:org.eclipse.january.dataset.GeneratedMaths.java

/**
 * expm1 - evaluate the exponential function - 1 on each element of the dataset
 * @param a/*w  w w  . j av  a2 s .c om*/
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset expm1(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int as = da.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.expm1(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.expm1(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.expm1(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.expm1(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.expm1(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.expm1(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.expm1(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.expm1(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.expm1(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.expm1(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.expm1(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.expm1(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.expm1(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.expm1(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.expm1(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.expm1(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.expm1(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.expm1(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).getData();
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.expm1(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.expm1(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.expm1(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.expm1(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.expm1(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.expm1(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.expm1(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.expm1(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float tf;
                float ox;
                float oy;
                tf = (float) (Math.expm1(ix));
                ox = (float) (tf * Math.cos(iy));
                oy = (float) (tf * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                float tf;
                float ox;
                float oy;
                tf = (float) (Math.expm1(ix));
                ox = (float) (tf * Math.cos(iy));
                oy = (float) (tf * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
        if (as == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double tf;
                double ox;
                double oy;
                tf = (Math.expm1(ix));
                ox = (tf * Math.cos(iy));
                oy = (tf * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                double tf;
                double ox;
                double oy;
                tf = (Math.expm1(ix));
                ox = (tf * Math.cos(iy));
                oy = (tf * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "expm1 supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "expm1");
    return result;
}

From source file:org.eclipse.january.dataset.Maths.java

/**
 * expm1 - evaluate the exponential function - 1 on each element of the dataset
 * @param a// www. jav a  2  s  . co  m
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset expm1(final Object a, final Dataset o) {
    final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    final Dataset result = it.getOutput();
    final int is = result.getElementsPerItem();
    final int dt = result.getDType();

    switch (dt) {
    case Dataset.INT8:
        final byte[] oi8data = ((ByteDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                byte ox;
                ox = (byte) toLong(Math.expm1(ix));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(Math.expm1(ix));
                oi8data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT16:
        final short[] oi16data = ((ShortDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                short ox;
                ox = (short) toLong(Math.expm1(ix));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(Math.expm1(ix));
                oi16data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT64:
        final long[] oi64data = ((LongDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                long ox;
                ox = toLong(Math.expm1(ix));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(Math.expm1(ix));
                oi64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.INT32:
        final int[] oi32data = ((IntegerDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                int ox;
                ox = (int) toLong(Math.expm1(ix));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(Math.expm1(ix));
                oi32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYINT8:
        final byte[] oai8data = ((CompoundByteDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.expm1(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        byte ox;
                        ox = (byte) toLong(Math.expm1(ix));
                        oai8data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT16:
        final short[] oai16data = ((CompoundShortDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.expm1(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        short ox;
                        ox = (short) toLong(Math.expm1(ix));
                        oai16data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT64:
        final long[] oai64data = ((CompoundLongDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.expm1(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        long ox;
                        ox = toLong(Math.expm1(ix));
                        oai64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYINT32:
        final int[] oai32data = ((CompoundIntegerDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.expm1(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        int ox;
                        ox = (int) toLong(Math.expm1(ix));
                        oai32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.FLOAT32:
        final float[] of32data = ((FloatDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float ox;
                ox = (float) (Math.expm1(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.expm1(ix));
                of32data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.FLOAT64:
        final double[] of64data = ((DoubleDataset) result).data;
        if (it.isOutputDouble()) {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double ox;
                ox = (Math.expm1(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.expm1(ix));
                of64data[it.oIndex] = ox;
            }
        }
        break;
    case Dataset.ARRAYFLOAT32:
        final float[] oaf32data = ((CompoundFloatDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    oaf32data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.expm1(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        float ox;
                        ox = (float) (Math.expm1(ix));
                        oaf32data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.ARRAYFLOAT64:
        final double[] oaf64data = ((CompoundDoubleDataset) result).data;
        if (is == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.expm1(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.expm1(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.expm1(ix));
                    for (int j = 0; j < is; j++) {
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        } else {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.expm1(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            } else {
                while (it.hasNext()) {
                    for (int j = 0; j < is; j++) {
                        final long ix = da.getElementLongAbs(it.aIndex + j);
                        double ox;
                        ox = (Math.expm1(ix));
                        oaf64data[it.oIndex + j] = ox;
                    }
                }
            }
        }
        break;
    case Dataset.COMPLEX64:
        final float[] oc64data = ((ComplexFloatDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                float tf;
                float ox;
                float oy;
                tf = (float) (Math.expm1(ix));
                ox = (float) (tf * Math.cos(iy));
                oy = (float) (tf * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                float tf;
                float ox;
                float oy;
                tf = (float) (Math.expm1(ix));
                ox = (float) (tf * Math.cos(iy));
                oy = (float) (tf * Math.sin(iy));
                oc64data[it.oIndex] = ox;
                oc64data[it.oIndex + 1] = oy;
            }
        }
        break;
    case Dataset.COMPLEX128:
        final double[] oc128data = ((ComplexDoubleDataset) result).data;
        if (da.getElementsPerItem() == 1) {
            final double iy = 0;
            while (it.hasNext()) {
                final double ix = it.aDouble;
                double tf;
                double ox;
                double oy;
                tf = (Math.expm1(ix));
                ox = (tf * Math.cos(iy));
                oy = (tf * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        } else {
            while (it.hasNext()) {
                final double ix = it.aDouble;
                final double iy = da.getElementDoubleAbs(it.aIndex + 1);
                double tf;
                double ox;
                double oy;
                tf = (Math.expm1(ix));
                ox = (tf * Math.cos(iy));
                oy = (tf * Math.sin(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "expm1 supports integer, compound integer, real, compound real, complex datasets only");
    }

    addFunctionName(result, "expm1");
    return result;
}

From source file:org.esa.beam.util.math.FastMathPerformance.java

public void testExpm1() {
    System.gc();//from w ww . j  a va2 s .  c  om
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.expm1(-i * F1);
    long strictTime = System.nanoTime() - time;

    System.gc();
    double y = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        y += FastMath.expm1(-i * F1);
    long fastTime = System.nanoTime() - time;

    System.gc();
    double z = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        z += Math.expm1(-i * F1);
    long mathTime = System.nanoTime() - time;
    report("expm1", x + y + z, strictTime, fastTime, mathTime);
}

From source file:org.renjin.MathExt.java

public static double expm1(double x) {
    return Math.expm1(x);
}

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

@Deferrable
@Builtin
@DataParallel
public static double expm1(double x) {
    return Math.expm1(x);
}

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

@Deferrable
@Builtin// w  w w.  ja va 2s .c o m
@DataParallel(value = PreserveAttributeStyle.ALL, passNA = true)
public static double expm1(double x) {
    return Math.expm1(x);
}