Example usage for java.lang Math signum

List of usage examples for java.lang Math signum

Introduction

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

Prototype

public static float signum(float f) 

Source Link

Document

Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.

Usage

From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java

private int exposureToProgress(final float exposure) {
    return (int) (Math.signum(exposure) * (Math.sqrt(Math.abs(exposure * 3000000)))) + 3000;
}

From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java

private float progressToExposure(final int progress) {
    final int p = progress - 3000;
    return Math.signum(p) * (p * p / 3000000.0f);
}

From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java

public boolean identicalValue(String localValue, String serverValue, ElementDataType dt) {

    if (localValue == null && serverValue == null) {
        return true;
    } else if (localValue == null || serverValue == null) {
        return false;
    } else if (localValue.equals(serverValue)) {
        return true;
    }//from   www  .j a v a2  s  . c  o m

    // NOT textually identical.
    //
    // Everything must be textually identical except possibly number fields
    // which may have rounding due to different database implementations,
    // data representations, and marshaling libraries.
    //
    if (dt == ElementDataType.number) {
        // !!Important!! Double.valueOf(str) handles NaN and +/-Infinity
        Double localNumber = Double.valueOf(localValue);
        Double serverNumber = Double.valueOf(serverValue);

        if (localNumber.equals(serverNumber)) {
            // simple case -- trailing zeros or string representation mix-up
            //
            return true;
        } else if (localNumber.isInfinite() && serverNumber.isInfinite()) {
            // if they are both plus or both minus infinity, we have a match
            if (Math.signum(localNumber) == Math.signum(serverNumber)) {
                return true;
            } else {
                return false;
            }
        } else if (localNumber.isNaN() || localNumber.isInfinite() || serverNumber.isNaN()
                || serverNumber.isInfinite()) {
            // one or the other is special1
            return false;
        } else {
            double localDbl = localNumber;
            double serverDbl = serverNumber;
            if (localDbl == serverDbl) {
                return true;
            }
            // OK. We have two values like 9.80 and 9.8
            // consider them equal if they are adjacent to each other.
            double localNear = localDbl;
            int idist = 0;
            int idistMax = 128;
            for (idist = 0; idist < idistMax; ++idist) {
                localNear = Math.nextAfter(localNear, serverDbl);
                if (localNear == serverDbl) {
                    break;
                }
            }
            if (idist < idistMax) {
                return true;
            }
            return false;
        }
    } else {
        // textual identity is required!
        return false;
    }
}

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Computes real roots for quadratic equation of the form
 * {@code ax^2 + bx + c = 0}, given real coefficients {@code a}, {@code b},
 * and {@code c}. If there are two distinct roots, they are returned in a
 * two-element array. If there is a single root or two identical roots, the
 * result is returned in a single-element array. If there are no real-valued
 * roots, the function returns a zero-length array. Note that the
 * discriminant {@code b*b-4*a*c} contains the potential for catastrophic
 * cancellation if its two terms are nearly equal, so in this case the
 * algorithm uses {@code BigDecimal}s and methods described by W. Kahan in
 * "On the Cost of Floating-Point Computation Without Extra-Precise
 * Arithmetic"//from  www. j  a v a2 s. c o  m
 * (<a href="http://www.cs.berkeley.edu/~wkahan/Qdrtcs.pdf">www.cs.berkeley.edu/~wkahan/Qdrtcs.pdf/</a>),
 * which references TJ Dekker (A Floating-Point Technique for Extending the
 * Available Precision,? pp 234-242 in Numerische Mathematik 18, 1971).
 *
 * @param a quadratic coefficient
 * @param b linear coefficient
 * @param c constant term
 * @return array of distinct roots in order from least to greatest, or
 *         zero-length array if there are no real-valued roots
 */
public static final double[] quadraticRoots(double a, double b, double c) {
    if (a == 0.0) {
        if (b == 0.0) {
            return new double[0];
        } else {
            return new double[] { -c / b };
        }
    } else if (b == 0.0) {
        if (c == 0.0) {
            return new double[] { 0.0 };
        } else {
            double q = Math.sqrt(-c / a);
            return new double[] { -q, q };
        }
    } else if (c == 0.0) {
        if (a == 0.0) {
            return new double[] { 0.0 };
        } else {
            double r = -b / a;
            if (r < 0.0) {
                return new double[] { r, 0.0 };
            } else {
                return new double[] { 0.0, r };
            }
        }
    } else {
        double p = b * b;
        double q = 4.0 * a * c;
        double d = p - q;
        double sqrtD = Math.sqrt(d);
        double pie = 3; // see reference cited in javadoc for the origin of this number
        if (pie * Math.abs(d) < p + q) {
            BigDecimal aBD = new BigDecimal(a, MathContext.DECIMAL64);
            BigDecimal bBD = new BigDecimal(b, MathContext.DECIMAL64);
            BigDecimal cBD = new BigDecimal(c, MathContext.DECIMAL64);
            BigDecimal pBD = bBD.multiply(bBD);
            BigDecimal qBD = aBD.multiply(cBD).multiply(new BigDecimal(4, MathContext.DECIMAL64));
            BigDecimal dBD = pBD.subtract(qBD);
            if (dBD.doubleValue() < 0) { // discriminant < 0.0
                return new double[0];
            } else if (dBD.doubleValue() == 0) { // discriminant is truly zero to double precision
                return new double[] { -b / (2.0 * a) };
            }
            sqrtD = sqrt(dBD, MathContext.DECIMAL64).doubleValue();
        }
        double s = -0.5 * (b + Math.signum(b) * sqrtD);
        double r1 = s / a;
        double r2 = c / s;
        if (r1 < r2) {
            return new double[] { r1, r2 };
        } else if (r1 > r2) {
            return new double[] { r2, r1 };
        } else {
            return new double[] { r1 };
        }
    }
}

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Computes real roots to the cubic equation
 * {@code x^3 + a*x^2 + b*x + c = 0}, given real coefficients {@code a},
 * {@code b}, and {@code c}. If there are three distinct roots, they are
 * returned in a three-element array. If there is a double root and a single
 * root, the results are returned in a two-element array. If there is a
 * single real root, the result is returned in a single-element array.
 * <p>/*from ww w .  j av a2 s .  c  om*/
 * Code adapted from GSL poly/solve_cubic.c
 * (<a href="http://www.gnu.org/software/gsl/">www.gnu.org/software/gsl/</a>)
 * </p>
 *
 * @param a quadratic coefficient
 * @param b linear coefficient
 * @param c constant term
 * @return array of distinct roots in order from least to greatest
 */
public static final double[] cubicRoots(double a, double b, double c) {
    if (c == 0.0) {
        double[] qr = quadraticRoots(1.0, a, b);
        if (qr.length == 2) {
            if (qr[0] != 0.0 && qr[1] != 0.0) {
                double[] output = new double[] { 0.0, qr[0], qr[1] };
                Arrays.sort(output);
                return output;
            } else if (qr[0] * qr[1] == 0.0) { // the zero root is already present in qr
                return qr;
            }
        } else if (qr.length == 1) {
            if (qr[0] > 0.0) {
                return new double[] { 0.0, qr[0] };
            } else if (qr[0] < 0.0) {
                return new double[] { qr[0], 0.0 };
            } else {
                return qr;
            }
        } else {
            return new double[] { 0.0 };
        }
    }

    double q = (a * a - 3 * b);
    double r = (2 * a * a * a - 9 * a * b + 27 * c);

    double Q = q / 9;
    double R = r / 54;

    double Q3 = Q * Q * Q;
    double R2 = R * R;

    double CR2 = 729 * r * r;
    double CQ3 = 2916 * q * q * q;

    if (R == 0 && Q == 0) {
        return new double[] { -a / 3.0 };
    } else if (CR2 == CQ3) {
        /* this test is actually R2 == Q3, written in a form suitable
         for exact computation with integers */

        /* Due to finite precision some double roots may be missed, and
         considered to be a pair of complex roots z = x +/- epsilon i
         close to the real axis. */
        double sqrtQ = Math.sqrt(Q);

        if (R > 0) {
            return new double[] { -2.0 * sqrtQ - a / 3.0, sqrtQ - a / 3.0 };
        } else {
            return new double[] { -sqrtQ - a / 3.0, 2.0 * sqrtQ - a / 3.0 };
        }
    } else if (R2 < Q3) {
        double ratio = Math.signum(R) * Math.sqrt(R2 / Q3);
        double theta = Math.acos(ratio);
        double norm = -2 * Math.sqrt(Q);
        double x0 = norm * Math.cos(theta / 3) - a / 3;
        double x1 = norm * Math.cos((theta + 2.0 * Math.PI) / 3) - a / 3;
        double x2 = norm * Math.cos((theta - 2.0 * Math.PI) / 3) - a / 3;

        /* Sort x0, x1, x2 into increasing order */
        if (x0 > x1) {
            double temp = x1;
            x1 = x0;
            x0 = temp;
        }

        if (x1 > x2) {
            double temp = x2;
            x2 = x1;
            x1 = temp;

            if (x0 > x1) {
                temp = x1;
                x1 = x0;
                x0 = temp;
            }
        }
        return new double[] { x0, x1, x2 };
    } else {
        double sgnR = (R >= 0 ? 1 : -1);
        double A = -sgnR * Math.pow(Math.abs(R) + Math.sqrt(R2 - Q3), 1.0 / 3.0);
        double B = Q / A;
        return new double[] { A + B - a / 3 };
    }
}

From source file:com.wb.launcher3.Page.java

public boolean handleMotionEvent(MotionEvent ev) {
    if (getChildCount() <= 0) {
        return false;
    }// w  w w  .  ja va 2s. c om
    acquireVelocityTrackerAndAddMovement(ev);
    switch (MotionEvent.ACTION_MASK & ev.getAction()) {
    case MotionEvent.ACTION_POINTER_DOWN:
        if (ev.getPointerCount() <= 2) {
            if (!this.mScroller.isFinished()) {
                this.mScroller.abortAnimation();
            }
            int index = (ev.getAction()
                    & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
            float px = ev.getX(index);
            mLastMotionX = px;
            mDownMotionX = px;
            mLastMotionY = ev.getY(index);
            mLastMotionXRemainder = 0.0F;
            mTotalMotionX = 0.0F;
            mActivePointerId = ev.getPointerId(index);
            mTouchState = TOUCH_STATE_SCROLLING;
            pageBeginMoving();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex >= 0) {
                float x = ev.getX(pointerIndex);
                float deltaX = mLastMotionX + mLastMotionXRemainder - x;
                mTotalMotionX += Math.abs(deltaX);
                if (Math.abs(deltaX) >= 1.0F) {
                    mTouchX += deltaX;
                    mSmoothingTime = System.nanoTime() / NANOTIME_DIV;
                    if (!mDeferScrollUpdate) {
                        scrollBy((int) deltaX, 0);
                        if (DEBUG)
                            Log.d(TAG, "handleMotionEvent().Scrolling: " + deltaX);
                    } else {
                        invalidate();
                    }
                    mLastMotionX = x;
                    mLastMotionXRemainder = deltaX - (int) deltaX;
                } else {
                    awakenScrollBars();
                }
            }
        } else {
            determineScrollingStart(ev);
        }
        break;

    case MotionEvent.ACTION_POINTER_UP:
        if (ev.getPointerCount() > 2) {
            onOtherPointerUp(ev);
            break;
        }

        if (mTouchState == TOUCH_STATE_SCROLLING) {
            final int activePointerId = mActivePointerId;
            final int pointerIndex = ev.findPointerIndex(activePointerId);
            final float x = ev.getX(pointerIndex);
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int velocityX = (int) velocityTracker.getXVelocity(activePointerId);
            final int deltaX = (int) (x - mDownMotionX);
            final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth();
            boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD;

            mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x);

            boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING
                    && Math.abs(velocityX) > mFlingThresholdVelocity;
            boolean returnToOriginalPage = false;
            if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD
                    && Math.signum(velocityX) != Math.signum(deltaX) && isFling) {
                returnToOriginalPage = true;
            }

            if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED) {
                m_moveNextDeltaX = deltaX;
                m_isSignificantMoveNext = (!returnToOriginalPage && (isSignificantMove || isFling));
            }

            int finalPage;
            if (((isSignificantMove && deltaX > 0 && !isFling) || (isFling && velocityX > 0))
                    && mCurrentPage > 0) {
                finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1;
                snapToPageWithVelocity(finalPage, velocityX);
            } else if (((isSignificantMove && deltaX < 0 && !isFling) || (isFling && velocityX < 0))
                    && mCurrentPage < getChildCount() - 1) {
                finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1;
                snapToPageWithVelocity(finalPage, velocityX);
            } else {
                snapToDestination();
            }
        } else if (mTouchState == TOUCH_STATE_PREV_PAGE) {
            int nextPage = Math.max(0, mCurrentPage - 1);
            if (nextPage != mCurrentPage) {
                snapToPage(nextPage);
            } else {
                snapToDestination();
            }
        } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) {
            int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1);
            if (nextPage != mCurrentPage) {
                snapToPage(nextPage);
            } else {
                snapToDestination();
            }
        } else {
            snapToDestination();
            onUnhandledTap(ev);
        }
        mTouchState = TOUCH_STATE_REST;
        mActivePointerId = INVALID_POINTER;
        releaseVelocityTracker();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mTouchState == TOUCH_STATE_SCROLLING) {
            snapToDestination();
        }
        mTouchState = TOUCH_STATE_REST;
        mActivePointerId = INVALID_POINTER;
        releaseVelocityTracker();
        break;
    }

    return true;
}

From source file:gedi.util.ArrayUtils.java

public static int compare(double[] a1, double[] a2, double eps) {
    int n = Math.min(a1.length, a2.length);
    for (int i = 0; i < n; i++) {
        double r = a1[i] - a2[i];
        if (Math.abs(r) > eps)
            return (int) Math.signum(r);
    }/*ww  w  . jav  a 2  s.  c o  m*/
    return a1.length - a2.length;
}

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

/**
 * signum - sign of each element/*from  w ww .j  a  va2s .  c  o m*/
 * @param a
 * @return dataset
 */
@SuppressWarnings("cast")
public static AbstractDataset signum(final AbstractDataset a) {
    final int isize;
    final IndexIterator it = a.getIterator();
    AbstractDataset ds;
    final int dt = a.getDtype();

    switch (dt) {
    case AbstractDataset.INT8:
        ds = AbstractDataset.zeros(a, AbstractDataset.INT8);
        final byte[] i8data = ((ByteDataset) a).data;
        final byte[] oi8data = ((ByteDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final byte ix = i8data[it.index];
            byte ox;
            ox = (byte) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
            oi8data[i++] = ox;
        }
        break;
    case AbstractDataset.INT16:
        ds = AbstractDataset.zeros(a, AbstractDataset.INT16);
        final short[] i16data = ((ShortDataset) a).data;
        final short[] oi16data = ((ShortDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final short ix = i16data[it.index];
            short ox;
            ox = (short) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
            oi16data[i++] = ox;
        }
        break;
    case AbstractDataset.INT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.INT64);
        final long[] i64data = ((LongDataset) a).data;
        final long[] oi64data = ((LongDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final long ix = i64data[it.index];
            long ox;
            ox = (long) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
            oi64data[i++] = ox;
        }
        break;
    case AbstractDataset.INT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.INT32);
        final int[] i32data = ((IntegerDataset) a).data;
        final int[] oi32data = ((IntegerDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final int ix = i32data[it.index];
            int ox;
            ox = (int) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
            oi32data[i++] = ox;
        }
        break;
    case AbstractDataset.ARRAYINT8:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYINT8);
        isize = a.getElementsPerItem();
        final byte[] ai8data = ((CompoundByteDataset) a).data;
        final byte[] oai8data = ((CompoundByteDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final byte ix = ai8data[it.index + j];
                byte ox;
                ox = (byte) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oai8data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT16:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYINT16);
        isize = a.getElementsPerItem();
        final short[] ai16data = ((CompoundShortDataset) a).data;
        final short[] oai16data = ((CompoundShortDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final short ix = ai16data[it.index + j];
                short ox;
                ox = (short) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oai16data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYINT64);
        isize = a.getElementsPerItem();
        final long[] ai64data = ((CompoundLongDataset) a).data;
        final long[] oai64data = ((CompoundLongDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final long ix = ai64data[it.index + j];
                long ox;
                ox = (long) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oai64data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYINT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYINT32);
        isize = a.getElementsPerItem();
        final int[] ai32data = ((CompoundIntegerDataset) a).data;
        final int[] oai32data = ((CompoundIntegerDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final int ix = ai32data[it.index + j];
                int ox;
                ox = (int) (ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oai32data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.FLOAT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32);
        final float[] f32data = ((FloatDataset) a).data;
        final float[] of32data = ((FloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final float ix = f32data[it.index];
            float ox;
            ox = (float) (Math.signum(ix));
            of32data[i++] = ox;
        }
        break;
    case AbstractDataset.FLOAT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64);
        final double[] f64data = ((DoubleDataset) a).data;
        final double[] of64data = ((DoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final double ix = f64data[it.index];
            double ox;
            ox = (double) (Math.signum(ix));
            of64data[i++] = ox;
        }
        break;
    case AbstractDataset.ARRAYFLOAT32:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32);
        isize = a.getElementsPerItem();
        final float[] af32data = ((CompoundFloatDataset) a).data;
        final float[] oaf32data = ((CompoundFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final float ix = af32data[it.index + j];
                float ox;
                ox = (float) (Math.signum(ix));
                oaf32data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.ARRAYFLOAT64:
        ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64);
        isize = a.getElementsPerItem();
        final double[] af64data = ((CompoundDoubleDataset) a).data;
        final double[] oaf64data = ((CompoundDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            for (int j = 0; j < isize; j++) {
                final double ix = af64data[it.index + j];
                double ox;
                ox = (double) (Math.signum(ix));
                oaf64data[i++] = ox;
            }
        }
        break;
    case AbstractDataset.COMPLEX64:
        ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX64);
        final float[] c64data = ((ComplexFloatDataset) a).data;
        final float[] oc64data = ((ComplexFloatDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final float ix = c64data[it.index];
            final float iy = c64data[it.index + 1];
            float ox;
            float oy;
            ox = (float) (Math.signum(ix));
            oy = (float) (Math.signum(iy));
            oc64data[i++] = ox;
            oc64data[i++] = oy;
        }
        break;
    case AbstractDataset.COMPLEX128:
        ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX128);
        final double[] c128data = ((ComplexDoubleDataset) a).data;
        final double[] oc128data = ((ComplexDoubleDataset) ds).getData();
        for (int i = 0; it.hasNext();) {
            final double ix = c128data[it.index];
            final double iy = c128data[it.index + 1];
            double ox;
            double oy;
            ox = (double) (Math.signum(ix));
            oy = (double) (Math.signum(iy));
            oc128data[i++] = ox;
            oc128data[i++] = oy;
        }
        break;
    default:
        throw new IllegalArgumentException(
                "signum supports integer, compound integer, real, compound real, complex datasets only");
    }

    ds.setName(a.getName());
    addFunctionName(ds, "signum");
    return ds;
}

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

/**
 * signum - sign of each element//from   ww  w . j  a va2  s  .  c o  m
 * @param a
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset signum(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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai8data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    byte ox;
                    ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai16data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    short ox;
                    ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai32data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    int ox;
                    ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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.signum(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (float) (Math.signum(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.signum(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.signum(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.signum(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (float) (Math.signum(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.signum(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.signum(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.signum(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.signum(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.signum(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.signum(ix));
                    oaf64data[it.oIndex] = ox;
                }
            }
        } else if (as == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    double ox;
                    ox = (Math.signum(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.signum(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.signum(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.signum(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 ox;
                float oy;
                ox = (float) (Math.signum(ix));
                oy = (float) (Math.signum(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 ox;
                float oy;
                ox = (float) (Math.signum(ix));
                oy = (float) (Math.signum(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 ox;
                double oy;
                ox = (Math.signum(ix));
                oy = (Math.signum(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 ox;
                double oy;
                ox = (Math.signum(ix));
                oy = (Math.signum(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "signum supports integer, compound integer, real, compound real, complex datasets only");
    }

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

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

/**
 * signum - sign of each element/*from w w w.java 2  s  .c  om*/
 * @param a
 * @param o output can be null - in which case, a new dataset is created
 * @return dataset
 */
public static Dataset signum(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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi8data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                byte ox;
                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi16data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                short ox;
                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                long ox;
                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                oi32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                int ox;
                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai8data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    byte ox;
                    ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai16data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    short ox;
                    ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    long ox;
                    ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai64data[it.oIndex] = ox;
                }
            }
        } else if (da.getElementsPerItem() == 1) {
            if (it.isOutputDouble()) {
                while (it.hasNext()) {
                    final double ix = it.aDouble;
                    long ox;
                    ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    oai32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    int ox;
                    ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                    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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
                        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.signum(ix));
                of32data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                float ox;
                ox = (Math.signum(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.signum(ix));
                of64data[it.oIndex] = ox;
            }
        } else {
            while (it.hasNext()) {
                final long ix = it.aLong;
                double ox;
                ox = (Math.signum(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.signum(ix));
                    oaf32data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    float ox;
                    ox = (Math.signum(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.signum(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 = (Math.signum(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.signum(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 = (Math.signum(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.signum(ix));
                    oaf64data[it.oIndex] = ox;
                }
            } else {
                while (it.hasNext()) {
                    final long ix = it.aLong;
                    double ox;
                    ox = (Math.signum(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.signum(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.signum(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.signum(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.signum(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 ox;
                float oy;
                ox = (float) (Math.signum(ix));
                oy = (float) (Math.signum(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 ox;
                float oy;
                ox = (float) (Math.signum(ix));
                oy = (float) (Math.signum(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 ox;
                double oy;
                ox = (Math.signum(ix));
                oy = (Math.signum(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 ox;
                double oy;
                ox = (Math.signum(ix));
                oy = (Math.signum(iy));
                oc128data[it.oIndex] = ox;
                oc128data[it.oIndex + 1] = oy;
            }
        }
        break;
    default:
        throw new IllegalArgumentException(
                "signum supports integer, compound integer, real, compound real, complex datasets only");
    }

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