    001/*-
    002 *******************************************************************************
    003 * Copyright (c) 2011, 2016 Diamond Light Source Ltd.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the Eclipse Public License v1.0
    006 * which accompanies this distribution, and is available at
    007 * http://www.eclipse.org/legal/epl-v10.html
    008 *
    009 * Contributors:
    010 *    Peter Chang - initial API and implementation and/or initial documentation
    011 *******************************************************************************/
    012
    013package org.eclipse.january.dataset;
    014
    015import java.util.ArrayList;
    016import java.util.Arrays;
    017import java.util.Collection;
    018import java.util.Iterator;
    019import java.util.List;
    020
    021import org.apache.commons.math3.complex.Complex;
    022import org.eclipse.january.dataset.DTypeUtils;
    023import org.eclipse.january.dataset.Comparisons.Monotonicity;
    024
    025/**
    026 * Mathematics class
    027 */
    028public class Maths {
    029
    030        // DO NOT EDIT THIS FILE, EDIT internal/template/MathsPreface.java INSTEAD
    031
    032        /**
    033         * Unwrap result from mathematical methods if necessary
    034         *
    035         * @param o
    036         * @param a
    037         * @return a dataset if a is a dataset or an object of the same class as o
    038         */
    039        public static Object unwrap(final Dataset o, final Object a) {
    040                return a instanceof Dataset ? o : o.getObjectAbs(o.getOffset());
    041        }
    042
    043        /**
    044         * Unwrap result from mathematical methods if necessary
    045         *
    046         * @param o
    047         * @param a
    048         * @return a dataset if either a and b are datasets or an object of the same
    049         *         class as o
    050         */
    051        public static Object unwrap(final Dataset o, final Object a, final Object b) {
    052                return (a instanceof Dataset || b instanceof Dataset) ? o : o.getObjectAbs(o.getOffset());
    053        }
    054
    055        /**
    056         * Unwrap result from mathematical methods if necessary
    057         *
    058         * @param o
    059         * @param a
    060         * @return a dataset if any inputs are datasets or an object of the same
    061         *         class as o
    062         */
    063        public static Object unwrap(final Dataset o, final Object... a) {
    064                boolean isAnyDataset = false;
    065                for (Object obj : a) {
    066                        if (obj instanceof Dataset) {
    067                                isAnyDataset = true;
    068                                break;
    069                        }
    070                }
    071                return isAnyDataset ? o : o.getObjectAbs(o.getOffset());
    072        }
    073
    074        /**
    075         * @param a
    076         * @param b
    077         * @return floor divide of a and b
    078         */
    079        public static Dataset floorDivide(final Object a, final Object b) {
    080                return floorDivide(a, b, null);
    081        }
    082
    083        /**
    084         * @param a
    085         * @param b
    086         * @param o
    087         *            output can be null - in which case, a new dataset is created
    088         * @return floor divide of a and b
    089         */
    090        public static Dataset floorDivide(final Object a, final Object b, final Dataset o) {
    091                return Maths.divideTowardsFloor(a, b, o).ifloor();
    092        }
    093
    094        /**
    095         * @param a
    096         * @param b
    097         * @return floor remainder of a and b
    098         */
    099        public static Dataset floorRemainder(final Object a, final Object b) {
    100                return floorRemainder(a, b, null);
    101        }
    102
    103        /**
    104         * @param a
    105         * @param b
    106         * @param o
    107         *            output can be null - in which case, a new dataset is created
    108         * @return floor remainder of a and b
    109         */
    110        public static Dataset floorRemainder(final Object a, final Object b, final Dataset o) {
    111                Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    112                Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    113                Dataset dq = floorDivide(da, db);
    114                dq.imultiply(db);
    115                return Maths.subtract(da, dq, o);
    116        }
    117
    118        /**
    119         * Find reciprocal from dataset
    120         *
    121         * @param a
    122         * @return reciprocal dataset
    123         */
    124        public static Dataset reciprocal(final Object a) {
    125                return reciprocal(a, null);
    126        }
    127
    128        /**
    129         * Find reciprocal from dataset
    130         *
    131         * @param a
    132         * @param o
    133         *            output can be null - in which case, a new dataset is created
    134         * @return reciprocal dataset
    135         */
    136        public static Dataset reciprocal(final Object a, final Dataset o) {
    137                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    138                return Maths.divide(1, da, o);
    139        }
    140
    141        /**
    142         * abs - absolute value of each element
    143         *
    144         * @param a
    145         * @return dataset
    146         */
    147        public static Dataset abs(final Object a) {
    148                return abs(a, null);
    149        }
    150
    151        /**
    152         * abs - absolute value of each element
    153         *
    154         * @param a
    155         * @param o
    156         *            output can be null - in which case, a new dataset is created
    157         * @return dataset
    158         */
    159        public static Dataset abs(final Object a, final Dataset o) {
    160                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    161                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, false);
    162                final Dataset result = it.getOutput();
    163                final int is = result.getElementsPerItem();
    164                final int dt = result.getDType();
    165                final int as = da.getElementsPerItem();
    166                final boolean reset = result == o && is > 1;
    167
    168                switch (dt) {
    169                case Dataset.INT8:
    170                        final byte[] oi8data = ((ByteDataset) result).getData();
    171                        it.setOutputDouble(false);
    172
    173                        while (it.hasNext()) {
    174                                oi8data[it.oIndex] = (byte) Math.abs(it.aLong);
    175                        }
    176                        break;
    177                case Dataset.INT16:
    178                        final short[] oi16data = ((ShortDataset) result).getData();
    179                        it.setOutputDouble(false);
    180
    181                        while (it.hasNext()) {
    182                                oi16data[it.oIndex] = (short) Math.abs(it.aLong);
    183                        }
    184                        break;
    185                case Dataset.INT32:
    186                        final int[] oi32data = ((IntegerDataset) result).getData();
    187                        it.setOutputDouble(false);
    188
    189                        while (it.hasNext()) {
    190                                oi32data[it.oIndex] = (int) Math.abs(it.aLong);
    191                        }
    192                        break;
    193                case Dataset.INT64:
    194                        final long[] oi64data = ((LongDataset) result).getData();
    195                        it.setOutputDouble(false);
    196
    197                        while (it.hasNext()) {
    198                                oi64data[it.oIndex] = Math.abs(it.aLong);
    199                        }
    200                        break;
    201                case Dataset.ARRAYINT8:
    202                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    203                        it.setOutputDouble(false);
    204
    205                        if (is == 1) {
    206                                while (it.hasNext()) {
    207                                        oai8data[it.oIndex] = (byte) Math.abs(it.aLong);
    208                                }
    209                        } else if (as == 1) {
    210                                while (it.hasNext()) {
    211                                        byte ox = (byte) Math.abs(it.aLong);
    212                                        for (int j = 0; j < is; j++) {
    213                                                oai8data[it.oIndex + j] = ox;
    214                                        }
    215                                }
    216                        } else {
    217                                while (it.hasNext()) {
    218                                        oai8data[it.oIndex] = (byte) Math.abs(it.aLong);
    219                                        for (int j = 1; j < is; j++) {
    220                                                oai8data[it.oIndex + j] = (byte) Math.abs(da.getElementLongAbs(it.aIndex + j));
    221                                        }
    222                                }
    223                        }
    224                        break;
    225                case Dataset.ARRAYINT16:
    226                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    227                        it.setOutputDouble(false);
    228
    229                        if (is == 1) {
    230                                while (it.hasNext()) {
    231                                        oai16data[it.oIndex] = (short) Math.abs(it.aLong);
    232                                }
    233                        } else if (as == 1) {
    234                                while (it.hasNext()) {
    235                                        short ox = (short) Math.abs(it.aLong);
    236                                        for (int j = 0; j < is; j++) {
    237                                                oai16data[it.oIndex + j] = ox;
    238                                        }
    239                                }
    240                        } else {
    241                                while (it.hasNext()) {
    242                                        oai16data[it.oIndex] = (short) Math.abs(it.aLong);
    243                                        for (int j = 1; j < is; j++) {
    244                                                oai16data[it.oIndex + j] = (short) Math.abs(da.getElementLongAbs(it.aIndex + j));
    245                                        }
    246                                }
    247                        }
    248                        break;
    249                case Dataset.ARRAYINT32:
    250                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    251                        it.setOutputDouble(false);
    252
    253                        if (is == 1) {
    254                                while (it.hasNext()) {
    255                                        oai32data[it.oIndex] = (int) Math.abs(it.aLong);
    256                                }
    257                        } else if (as == 1) {
    258                                while (it.hasNext()) {
    259                                        int ox = (int) Math.abs(it.aLong);
    260                                        for (int j = 0; j < is; j++) {
    261                                                oai32data[it.oIndex + j] = ox;
    262                                        }
    263                                }
    264                        } else {
    265                                while (it.hasNext()) {
    266                                        oai32data[it.oIndex] = (int) Math.abs(it.aLong);
    267                                        for (int j = 1; j < is; j++) {
    268                                                oai32data[it.oIndex + j] = (int) Math.abs(da.getElementLongAbs(it.aIndex + j));
    269                                        }
    270                                }
    271                        }
    272                        break;
    273                case Dataset.ARRAYINT64:
    274                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    275                        it.setOutputDouble(false);
    276
    277                        if (is == 1) {
    278                                while (it.hasNext()) {
    279                                        oai64data[it.oIndex] = Math.abs(it.aLong);
    280                                }
    281                        } else if (as == 1) {
    282                                while (it.hasNext()) {
    283                                        long ox = Math.abs(it.aLong);
    284                                        for (int j = 0; j < is; j++) {
    285                                                oai64data[it.oIndex + j] = ox;
    286                                        }
    287                                }
    288                        } else {
    289                                while (it.hasNext()) {
    290                                        oai64data[it.oIndex] = Math.abs(it.aLong);
    291                                        for (int j = 1; j < is; j++) {
    292                                                oai64data[it.oIndex + j] = Math.abs(da.getElementLongAbs(it.aIndex + j));
    293                                        }
    294                                }
    295                        }
    296                        break;
    297                case Dataset.FLOAT32:
    298                        final float[] of32data = ((FloatDataset) result).getData();
    299                        if (as == 1) {
    300                                while (it.hasNext()) {
    301                                        of32data[it.oIndex] = (float) (Math.abs(it.aDouble));
    302                                }
    303                        } else {
    304                                while (it.hasNext()) {
    305                                        of32data[it.oIndex] = (float) (Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1)));
    306                                }
    307                        }
    308                        break;
    309                case Dataset.FLOAT64:
    310                        final double[] of64data = ((DoubleDataset) result).getData();
    311                        if (as == 1) {
    312                                while (it.hasNext()) {
    313                                        of64data[it.oIndex] = Math.abs(it.aDouble);
    314                                }
    315                        } else {
    316                                while (it.hasNext()) {
    317                                        of64data[it.oIndex] = Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1));
    318                                }
    319                        }
    320                        break;
    321                case Dataset.ARRAYFLOAT32:
    322                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    323                        if (is == 1) {
    324                                while (it.hasNext()) {
    325                                        oaf32data[it.oIndex] = (float) (Math.abs(it.aDouble));
    326                                }
    327                        } else if (as == 1) {
    328                                while (it.hasNext()) {
    329                                        float ox = (float) (Math.abs(it.aDouble));
    330                                        for (int j = 0; j < is; j++) {
    331                                                oaf32data[it.oIndex + j] = ox;
    332                                        }
    333                                }
    334                        } else {
    335                                while (it.hasNext()) {
    336                                        oaf32data[it.oIndex] = (float) Math.abs(it.aDouble);
    337                                        for (int j = 1; j < is; j++) {
    338                                                oaf32data[it.oIndex + j] = (float) Math.abs(da.getElementDoubleAbs(it.aIndex + j));
    339                                        }
    340                                }
    341                        }
    342                        break;
    343                case Dataset.ARRAYFLOAT64:
    344                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    345                        if (is == 1) {
    346                                while (it.hasNext()) {
    347                                        oaf64data[it.oIndex] = Math.abs(it.aDouble);
    348                                }
    349                        } else if (as == 1) {
    350                                while (it.hasNext()) {
    351                                        final double ix = it.aDouble;
    352                                        double ox = Math.abs(ix);
    353                                        for (int j = 0; j < is; j++) {
    354                                                oaf64data[it.oIndex + j] = ox;
    355                                        }
    356                                }
    357                        } else {
    358                                while (it.hasNext()) {
    359                                        oaf64data[it.oIndex] = Math.abs(it.aDouble);
    360                                        for (int j = 1; j < is; j++) {
    361                                                oaf64data[it.oIndex + j] = Math.abs(da.getElementDoubleAbs(it.aIndex + j));
    362                                        }
    363                                }
    364                        }
    365                        break;
    366                case Dataset.COMPLEX64:
    367                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    368                        if (as == 1) {
    369                                while (it.hasNext()) {
    370                                        oc64data[it.oIndex] = (float) Math.abs(it.aDouble);
    371                                        if (reset) {
    372                                                oc64data[it.oIndex + 1] = 0;
    373                                        }
    374                                }
    375                        } else {
    376                                while (it.hasNext()) {
    377                                        oc64data[it.oIndex] = (float) Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1));
    378                                        if (reset) {
    379                                                oc64data[it.oIndex + 1] = 0;
    380                                        }
    381                                }
    382                        }
    383                        break;
    384                case Dataset.COMPLEX128:
    385                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    386                        if (as == 1) {
    387                                while (it.hasNext()) {
    388                                        oc128data[it.oIndex] = Math.abs(it.aDouble);
    389                                        if (reset) {
    390                                                oc128data[it.oIndex + 1] = 0;
    391                                        }
    392                                }
    393                        } else {
    394                                while (it.hasNext()) {
    395                                        oc128data[it.oIndex] = Math.hypot(it.aDouble, da.getElementDoubleAbs(it.aIndex + 1));
    396                                        if (reset) {
    397                                                oc128data[it.oIndex + 1] = 0;
    398                                        }
    399                                }
    400                        }
    401                        break;
    402                default:
    403                        throw new IllegalArgumentException(
    404                                        "abs supports integer, compound integer, real, compound real, complex datasets only");
    405                }
    406
    407                addFunctionName(result, "abs");
    408                return result;
    409        }
    410
    411        /**
    412         * @param a
    413         * @return a^*, complex conjugate of a
    414         */
    415        public static Dataset conjugate(final Object a) {
    416                return conjugate(a, null);
    417        }
    418
    419        /**
    420         * @param a
    421         * @param o
    422         *            output can be null - in which case, a new dataset is created
    423         * @return a^*, complex conjugate of a
    424         */
    425        public static Dataset conjugate(final Object a, final Dataset o) {
    426                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    427                int at = da.getDType();
    428                IndexIterator it1 = da.getIterator();
    429
    430                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, true);
    431                Dataset result = it.getOutput();
    432
    433                switch (at) {
    434                case Dataset.COMPLEX64:
    435                        float[] c64data = ((ComplexFloatDataset) result).getData();
    436
    437                        for (int i = 0; it1.hasNext();) {
    438                                c64data[i++] = (float) da.getElementDoubleAbs(it1.index);
    439                                c64data[i++] = (float) -da.getElementDoubleAbs(it1.index + 1);
    440                        }
    441                        result.setName(Operations.bracketIfNecessary(da.getName()).append("^*").toString());
    442                        break;
    443                case Dataset.COMPLEX128:
    444                        double[] c128data = ((ComplexDoubleDataset) result).getData();
    445
    446                        for (int i = 0; it1.hasNext();) {
    447                                c128data[i++] = da.getElementDoubleAbs(it1.index);
    448                                c128data[i++] = -da.getElementDoubleAbs(it1.index + 1);
    449                        }
    450                        result.setName(Operations.bracketIfNecessary(da.getName()).append("^*").toString());
    451                        break;
    452                default:
    453                        result = da;
    454                }
    455
    456                return result;
    457        }
    458
    459        /**
    460         * @param a
    461         *            side of right-angled triangle
    462         * @param b
    463         *            side of right-angled triangle
    464         * @return hypotenuse of right-angled triangle: sqrt(a^2 + a^2)
    465         */
    466        public static Dataset hypot(final Object a, final Object b) {
    467                return hypot(a, b, null);
    468        }
    469
    470        /**
    471         * @param a
    472         *            side of right-angled triangle
    473         * @param b
    474         *            side of right-angled triangle
    475         * @param o
    476         *            output can be null - in which case, a new dataset is created
    477         * @return hypotenuse of right-angled triangle: sqrt(a^2 + a^2)
    478         */
    479        public static Dataset hypot(final Object a, final Object b, final Dataset o) {
    480                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    481                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    482
    483                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    484                it.setOutputDouble(true);
    485                final Dataset result = it.getOutput();
    486                final int is = result.getElementsPerItem();
    487                final int as = da.getElementsPerItem();
    488                final int bs = db.getElementsPerItem();
    489                final int dt = result.getDType();
    490                switch (dt) {
    491                case Dataset.BOOL:
    492                        boolean[] bdata = ((BooleanDataset) result).getData();
    493
    494                        while (it.hasNext()) {
    495                                bdata[it.oIndex] = Math.hypot(it.aDouble, it.bDouble) != 0;
    496                        }
    497                        break;
    498                case Dataset.INT8:
    499                        byte[] i8data = ((ByteDataset) result).getData();
    500
    501                        while (it.hasNext()) {
    502                                i8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble));
    503                        }
    504                        break;
    505                case Dataset.INT16:
    506                        short[] i16data = ((ShortDataset) result).getData();
    507
    508                        while (it.hasNext()) {
    509                                i16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble));
    510                        }
    511                        break;
    512                case Dataset.INT32:
    513                        int[] i32data = ((IntegerDataset) result).getData();
    514
    515                        while (it.hasNext()) {
    516                                i32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble));
    517                        }
    518                        break;
    519                case Dataset.INT64:
    520                        long[] i64data = ((LongDataset) result).getData();
    521
    522                        while (it.hasNext()) {
    523                                i64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble));
    524                        }
    525                        break;
    526                case Dataset.FLOAT32:
    527                        float[] f32data = ((FloatDataset) result).getData();
    528
    529                        while (it.hasNext()) {
    530                                f32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble);
    531                        }
    532                        break;
    533                case Dataset.FLOAT64:
    534                        double[] f64data = ((DoubleDataset) result).getData();
    535
    536                        while (it.hasNext()) {
    537                                f64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble);
    538                        }
    539                        break;
    540                case Dataset.ARRAYINT8:
    541                        byte[] ai8data = ((CompoundByteDataset) result).getData();
    542
    543                        if (is == 1) {
    544                                while (it.hasNext()) {
    545                                        ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble));
    546                                }
    547                        } else if (as == 1) {
    548                                while (it.hasNext()) {
    549                                        ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble));
    550                                        for (int j = 1; j < is; j++) {
    551                                                ai8data[it.oIndex
    552                                                                + j] = (byte) toLong(Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    553                                        }
    554                                }
    555                        } else if (bs == 1) {
    556                                while (it.hasNext()) {
    557                                        ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble));
    558                                        for (int j = 1; j < is; j++) {
    559                                                ai8data[it.oIndex
    560                                                                + j] = (byte) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    561                                        }
    562                                }
    563                        } else {
    564                                while (it.hasNext()) {
    565                                        ai8data[it.oIndex] = (byte) toLong(Math.hypot(it.aDouble, it.bDouble));
    566                                        for (int j = 1; j < is; j++) {
    567                                                ai8data[it.oIndex + j] = (byte) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j),
    568                                                                db.getElementDoubleAbs(it.bIndex + j)));
    569                                        }
    570                                }
    571                        }
    572                        break;
    573                case Dataset.ARRAYINT16:
    574                        short[] ai16data = ((CompoundShortDataset) result).getData();
    575
    576                        if (is == 1) {
    577                                while (it.hasNext()) {
    578                                        ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble));
    579                                }
    580                        } else if (as == 1) {
    581                                while (it.hasNext()) {
    582                                        ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble));
    583                                        for (int j = 1; j < is; j++) {
    584                                                ai16data[it.oIndex
    585                                                                + j] = (short) toLong(Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    586                                        }
    587                                }
    588                        } else if (bs == 1) {
    589                                while (it.hasNext()) {
    590                                        ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble));
    591                                        for (int j = 1; j < is; j++) {
    592                                                ai16data[it.oIndex
    593                                                                + j] = (short) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    594                                        }
    595                                }
    596                        } else {
    597                                while (it.hasNext()) {
    598                                        ai16data[it.oIndex] = (short) toLong(Math.hypot(it.aDouble, it.bDouble));
    599                                        for (int j = 1; j < is; j++) {
    600                                                ai16data[it.oIndex + j] = (short) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j),
    601                                                                db.getElementDoubleAbs(it.bIndex + j)));
    602                                        }
    603                                }
    604                        }
    605                        break;
    606                case Dataset.ARRAYINT32:
    607                        int[] ai32data = ((CompoundIntegerDataset) result).getData();
    608
    609                        if (is == 1) {
    610                                while (it.hasNext()) {
    611                                        ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble));
    612                                }
    613                        } else if (as == 1) {
    614                                while (it.hasNext()) {
    615                                        ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble));
    616                                        for (int j = 1; j < is; j++) {
    617                                                ai32data[it.oIndex
    618                                                                + j] = (int) toLong(Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    619                                        }
    620                                }
    621                        } else if (bs == 1) {
    622                                while (it.hasNext()) {
    623                                        ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble));
    624                                        for (int j = 1; j < is; j++) {
    625                                                ai32data[it.oIndex
    626                                                                + j] = (int) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    627                                        }
    628                                }
    629                        } else {
    630                                while (it.hasNext()) {
    631                                        ai32data[it.oIndex] = (int) toLong(Math.hypot(it.aDouble, it.bDouble));
    632                                        for (int j = 1; j < is; j++) {
    633                                                ai32data[it.oIndex + j] = (int) toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j),
    634                                                                db.getElementDoubleAbs(it.bIndex + j)));
    635                                        }
    636                                }
    637                        }
    638                        break;
    639                case Dataset.ARRAYINT64:
    640                        long[] ai64data = ((CompoundLongDataset) result).getData();
    641
    642                        if (is == 1) {
    643                                while (it.hasNext()) {
    644                                        ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble));
    645                                }
    646                        } else if (as == 1) {
    647                                while (it.hasNext()) {
    648                                        ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble));
    649                                        for (int j = 1; j < is; j++) {
    650                                                ai64data[it.oIndex + j] = toLong(Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    651                                        }
    652                                }
    653                        } else if (bs == 1) {
    654                                while (it.hasNext()) {
    655                                        ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble));
    656                                        for (int j = 1; j < is; j++) {
    657                                                ai64data[it.oIndex + j] = toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    658                                        }
    659                                }
    660                        } else {
    661                                while (it.hasNext()) {
    662                                        ai64data[it.oIndex] = toLong(Math.hypot(it.aDouble, it.bDouble));
    663                                        for (int j = 1; j < is; j++) {
    664                                                ai64data[it.oIndex + j] = toLong(Math.hypot(da.getElementDoubleAbs(it.aIndex + j),
    665                                                                db.getElementDoubleAbs(it.bIndex + j)));
    666                                        }
    667                                }
    668                        }
    669                        break;
    670                case Dataset.ARRAYFLOAT32:
    671                        float[] a32data = ((CompoundFloatDataset) result).getData();
    672
    673                        if (is == 1) {
    674                                while (it.hasNext()) {
    675                                        a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble);
    676                                }
    677                        } else if (as == 1) {
    678                                while (it.hasNext()) {
    679                                        a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble);
    680                                        for (int j = 1; j < is; j++) {
    681                                                a32data[it.oIndex + j] = (float) Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j));
    682                                        }
    683                                }
    684                        } else if (bs == 1) {
    685                                while (it.hasNext()) {
    686                                        a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble);
    687                                        for (int j = 1; j < is; j++) {
    688                                                a32data[it.oIndex + j] = (float) Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble);
    689                                        }
    690                                }
    691                        } else {
    692                                while (it.hasNext()) {
    693                                        a32data[it.oIndex] = (float) Math.hypot(it.aDouble, it.bDouble);
    694                                        for (int j = 1; j < is; j++) {
    695                                                a32data[it.oIndex + j] = (float) Math.hypot(da.getElementDoubleAbs(it.aIndex + j),
    696                                                                db.getElementDoubleAbs(it.bIndex + j));
    697                                        }
    698                                }
    699                        }
    700                        break;
    701                case Dataset.ARRAYFLOAT64:
    702                        double[] a64data = ((CompoundDoubleDataset) result).getData();
    703
    704                        if (is == 1) {
    705                                while (it.hasNext()) {
    706                                        a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble);
    707                                }
    708                        } else if (as == 1) {
    709                                while (it.hasNext()) {
    710                                        a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble);
    711                                        for (int j = 1; j < is; j++) {
    712                                                a64data[it.oIndex + j] = Math.hypot(it.aDouble, db.getElementDoubleAbs(it.bIndex + j));
    713                                        }
    714                                }
    715                        } else if (bs == 1) {
    716                                while (it.hasNext()) {
    717                                        a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble);
    718                                        for (int j = 1; j < is; j++) {
    719                                                a64data[it.oIndex + j] = Math.hypot(da.getElementDoubleAbs(it.aIndex + j), it.bDouble);
    720                                        }
    721                                }
    722                        } else {
    723                                while (it.hasNext()) {
    724                                        a64data[it.oIndex] = Math.hypot(it.aDouble, it.bDouble);
    725                                        for (int j = 1; j < is; j++) {
    726                                                a64data[it.oIndex + j] = Math.hypot(da.getElementDoubleAbs(it.aIndex + j),
    727                                                                db.getElementDoubleAbs(it.bIndex + j));
    728                                        }
    729                                }
    730                        }
    731                        break;
    732                default:
    733                        throw new UnsupportedOperationException("hypot does not support this dataset type");
    734                }
    735
    736                addFunctionName(da, db, result, "hypot");
    737
    738                return result;
    739        }
    740
    741        /**
    742         * @param a
    743         *            opposite side of right-angled triangle
    744         * @param b
    745         *            adjacent side of right-angled triangle
    746         * @return angle of triangle: atan(b/a)
    747         */
    748        public static Dataset arctan2(final Object a, final Object b) {
    749                return arctan2(a, b, null);
    750        }
    751
    752        /**
    753         * @param a
    754         *            opposite side of right-angled triangle
    755         * @param b
    756         *            adjacent side of right-angled triangle
    757         * @param o
    758         *            output can be null - in which case, a new dataset is created
    759         * @return angle of triangle: atan(b/a)
    760         */
    761        public static Dataset arctan2(final Object a, final Object b, final Dataset o) {
    762                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    763                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    764
    765                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    766                it.setOutputDouble(true);
    767                final Dataset result = it.getOutput();
    768                final int is = result.getElementsPerItem();
    769                final int as = da.getElementsPerItem();
    770                final int bs = db.getElementsPerItem();
    771                final int dt = result.getDType();
    772                switch (dt) {
    773                case Dataset.BOOL:
    774                        boolean[] bdata = ((BooleanDataset) result).getData();
    775
    776                        while (it.hasNext()) {
    777                                bdata[it.oIndex] = Math.atan2(it.aDouble, it.bDouble) != 0;
    778                        }
    779                        break;
    780                case Dataset.INT8:
    781                        byte[] i8data = ((ByteDataset) result).getData();
    782
    783                        while (it.hasNext()) {
    784                                i8data[it.oIndex] = (byte) toLong(Math.atan2(it.aDouble, it.bDouble));
    785                        }
    786                        break;
    787                case Dataset.INT16:
    788                        short[] i16data = ((ShortDataset) result).getData();
    789
    790                        while (it.hasNext()) {
    791                                i16data[it.oIndex] = (short) toLong(Math.atan2(it.aDouble, it.bDouble));
    792                        }
    793                        break;
    794                case Dataset.INT32:
    795                        int[] i32data = ((IntegerDataset) result).getData();
    796
    797                        while (it.hasNext()) {
    798                                i32data[it.oIndex] = (int) toLong(Math.atan2(it.aDouble, it.bDouble));
    799                        }
    800                        break;
    801                case Dataset.INT64:
    802                        long[] i64data = ((LongDataset) result).getData();
    803
    804                        while (it.hasNext()) {
    805                                i64data[it.oIndex] = toLong(Math.atan2(it.aDouble, it.bDouble));
    806                        }
    807                        break;
    808                case Dataset.FLOAT32:
    809                        float[] f32data = ((FloatDataset) result).getData();
    810
    811                        while (it.hasNext()) {
    812                                f32data[it.oIndex] = (float) Math.atan2(it.aDouble, it.bDouble);
    813                        }
    814                        break;
    815                case Dataset.FLOAT64:
    816                        double[] f64data = ((DoubleDataset) result).getData();
    817
    818                        while (it.hasNext()) {
    819                                f64data[it.oIndex] = Math.atan2(it.aDouble, it.bDouble);
    820                        }
    821                        break;
    822                case Dataset.ARRAYINT8:
    823                        byte[] ai8data = ((CompoundByteDataset) result).getData();
    824
    825                        if (is == 1) {
    826                                while (it.hasNext()) {
    827                                        ai8data[it.oIndex] = (byte) toLong(Math.atan2(it.aDouble, it.bDouble));
    828                                }
    829                        } else if (as == 1) {
    830                                while (it.hasNext()) {
    831                                        ai8data[it.oIndex] = (byte) toLong(Math.atan2(it.aDouble, it.bDouble));
    832                                        for (int j = 1; j < is; j++) {
    833                                                ai8data[it.oIndex
    834                                                                + j] = (byte) toLong(Math.atan2(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    835                                        }
    836                                }
    837                        } else if (bs == 1) {
    838                                while (it.hasNext()) {
    839                                        ai8data[it.oIndex] = (byte) toLong(Math.atan2(it.aDouble, it.bDouble));
    840                                        for (int j = 1; j < is; j++) {
    841                                                ai8data[it.oIndex
    842                                                                + j] = (byte) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    843                                        }
    844                                }
    845                        } else {
    846                                while (it.hasNext()) {
    847                                        ai8data[it.oIndex] = (byte) toLong(Math.atan2(it.aDouble, it.bDouble));
    848                                        for (int j = 1; j < is; j++) {
    849                                                ai8data[it.oIndex + j] = (byte) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j),
    850                                                                db.getElementDoubleAbs(it.bIndex + j)));
    851                                        }
    852                                }
    853                        }
    854                        break;
    855                case Dataset.ARRAYINT16:
    856                        short[] ai16data = ((CompoundShortDataset) result).getData();
    857
    858                        if (is == 1) {
    859                                while (it.hasNext()) {
    860                                        ai16data[it.oIndex] = (short) toLong(Math.atan2(it.aDouble, it.bDouble));
    861                                }
    862                        } else if (as == 1) {
    863                                while (it.hasNext()) {
    864                                        ai16data[it.oIndex] = (short) toLong(Math.atan2(it.aDouble, it.bDouble));
    865                                        for (int j = 1; j < is; j++) {
    866                                                ai16data[it.oIndex
    867                                                                + j] = (short) toLong(Math.atan2(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    868                                        }
    869                                }
    870                        } else if (bs == 1) {
    871                                while (it.hasNext()) {
    872                                        ai16data[it.oIndex] = (short) toLong(Math.atan2(it.aDouble, it.bDouble));
    873                                        for (int j = 1; j < is; j++) {
    874                                                ai16data[it.oIndex
    875                                                                + j] = (short) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    876                                        }
    877                                }
    878                        } else {
    879                                while (it.hasNext()) {
    880                                        ai16data[it.oIndex] = (short) toLong(Math.atan2(it.aDouble, it.bDouble));
    881                                        for (int j = 1; j < is; j++) {
    882                                                ai16data[it.oIndex + j] = (short) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j),
    883                                                                db.getElementDoubleAbs(it.bIndex + j)));
    884                                        }
    885                                }
    886                        }
    887                        break;
    888                case Dataset.ARRAYINT32:
    889                        int[] ai32data = ((CompoundIntegerDataset) result).getData();
    890
    891                        if (is == 1) {
    892                                while (it.hasNext()) {
    893                                        ai32data[it.oIndex] = (int) toLong(Math.atan2(it.aDouble, it.bDouble));
    894                                }
    895                        } else if (as == 1) {
    896                                while (it.hasNext()) {
    897                                        ai32data[it.oIndex] = (int) toLong(Math.atan2(it.aDouble, it.bDouble));
    898                                        for (int j = 1; j < is; j++) {
    899                                                ai32data[it.oIndex
    900                                                                + j] = (int) toLong(Math.atan2(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    901                                        }
    902                                }
    903                        } else if (bs == 1) {
    904                                while (it.hasNext()) {
    905                                        ai32data[it.oIndex] = (int) toLong(Math.atan2(it.aDouble, it.bDouble));
    906                                        for (int j = 1; j < is; j++) {
    907                                                ai32data[it.oIndex
    908                                                                + j] = (int) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    909                                        }
    910                                }
    911                        } else {
    912                                while (it.hasNext()) {
    913                                        ai32data[it.oIndex] = (int) toLong(Math.atan2(it.aDouble, it.bDouble));
    914                                        for (int j = 1; j < is; j++) {
    915                                                ai32data[it.oIndex + j] = (int) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j),
    916                                                                db.getElementDoubleAbs(it.bIndex + j)));
    917                                        }
    918                                }
    919                        }
    920                        break;
    921                case Dataset.ARRAYINT64:
    922                        long[] ai64data = ((CompoundLongDataset) result).getData();
    923
    924                        if (is == 1) {
    925                                while (it.hasNext()) {
    926                                        ai64data[it.oIndex] = toLong(Math.atan2(it.aDouble, it.bDouble));
    927                                }
    928                        } else if (as == 1) {
    929                                while (it.hasNext()) {
    930                                        ai64data[it.oIndex] = toLong(Math.atan2(it.aDouble, it.bDouble));
    931                                        for (int j = 1; j < is; j++) {
    932                                                ai64data[it.oIndex + j] = toLong(Math.atan2(it.aDouble, db.getElementDoubleAbs(it.bIndex + j)));
    933                                        }
    934                                }
    935                        } else if (bs == 1) {
    936                                while (it.hasNext()) {
    937                                        ai64data[it.oIndex] = toLong(Math.atan2(it.aDouble, it.bDouble));
    938                                        for (int j = 1; j < is; j++) {
    939                                                ai64data[it.oIndex + j] = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j), it.bDouble));
    940                                        }
    941                                }
    942                        } else {
    943                                while (it.hasNext()) {
    944                                        ai64data[it.oIndex] = toLong(Math.atan2(it.aDouble, it.bDouble));
    945                                        for (int j = 1; j < is; j++) {
    946                                                ai64data[it.oIndex + j] = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + j),
    947                                                                db.getElementDoubleAbs(it.bIndex + j)));
    948                                        }
    949                                }
    950                        }
    951                        break;
    952                case Dataset.ARRAYFLOAT32:
    953                        float[] a32data = ((CompoundFloatDataset) result).getData();
    954
    955                        if (is == 1) {
    956                                while (it.hasNext()) {
    957                                        a32data[it.oIndex] = (float) Math.atan2(it.aDouble, it.bDouble);
    958                                }
    959                        } else if (as == 1) {
    960                                while (it.hasNext()) {
    961                                        a32data[it.oIndex] = (float) Math.atan2(it.aDouble, it.bDouble);
    962                                        for (int j = 1; j < is; j++) {
    963                                                a32data[it.oIndex + j] = (float) Math.atan2(it.aDouble, db.getElementDoubleAbs(it.bIndex + j));
    964                                        }
    965                                }
    966                        } else if (bs == 1) {
    967                                while (it.hasNext()) {
    968                                        a32data[it.oIndex] = (float) Math.atan2(it.aDouble, it.bDouble);
    969                                        for (int j = 1; j < is; j++) {
    970                                                a32data[it.oIndex + j] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + j), it.bDouble);
    971                                        }
    972                                }
    973                        } else {
    974                                while (it.hasNext()) {
    975                                        a32data[it.oIndex] = (float) Math.atan2(it.aDouble, it.bDouble);
    976                                        for (int j = 1; j < is; j++) {
    977                                                a32data[it.oIndex + j] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + j),
    978                                                                db.getElementDoubleAbs(it.bIndex + j));
    979                                        }
    980                                }
    981                        }
    982                        break;
    983                case Dataset.ARRAYFLOAT64:
    984                        double[] a64data = ((CompoundDoubleDataset) result).getData();
    985
    986                        if (is == 1) {
    987                                while (it.hasNext()) {
    988                                        a64data[it.oIndex] = Math.atan2(it.aDouble, it.bDouble);
    989                                }
    990                        } else if (as == 1) {
    991                                while (it.hasNext()) {
    992                                        a64data[it.oIndex] = Math.atan2(it.aDouble, it.bDouble);
    993                                        for (int j = 1; j < is; j++) {
    994                                                a64data[it.oIndex + j] = Math.atan2(it.aDouble, db.getElementDoubleAbs(it.bIndex + j));
    995                                        }
    996                                }
    997                        } else if (bs == 1) {
    998                                while (it.hasNext()) {
    999                                        a64data[it.oIndex] = Math.atan2(it.aDouble, it.bDouble);
    1000                                        for (int j = 1; j < is; j++) {
    1001                                                a64data[it.oIndex + j] = Math.atan2(da.getElementDoubleAbs(it.aIndex + j), it.bDouble);
    1002                                        }
    1003                                }
    1004                        } else {
    1005                                while (it.hasNext()) {
    1006                                        a64data[it.oIndex] = Math.atan2(it.aDouble, it.bDouble);
    1007                                        for (int j = 1; j < is; j++) {
    1008                                                a64data[it.oIndex + j] = Math.atan2(da.getElementDoubleAbs(it.aIndex + j),
    1009                                                                db.getElementDoubleAbs(it.bIndex + j));
    1010                                        }
    1011                                }
    1012                        }
    1013                        break;
    1014                default:
    1015                        throw new UnsupportedOperationException("atan2 does not support multiple-element dataset");
    1016                }
    1017
    1018                addFunctionName(da, db, result, "atan2");
    1019
    1020                return result;
    1021        }
    1022
    1023        /**
    1024         * Create a dataset of the arguments from a complex dataset
    1025         *
    1026         * @param a
    1027         * @return dataset of angles in radians
    1028         */
    1029        public static Dataset angle(final Object a) {
    1030                return angle(a, false, null);
    1031        }
    1032
    1033        /**
    1034         * Create a dataset of the arguments from a complex dataset
    1035         *
    1036         * @param a
    1037         * @param inDegrees
    1038         *            if true then return angles in degrees else in radians
    1039         * @return dataset of angles
    1040         */
    1041        public static Dataset angle(final Object a, final boolean inDegrees) {
    1042                return angle(a, inDegrees, null);
    1043        }
    1044
    1045        /**
    1046         * Create a dataset of the arguments from a complex dataset
    1047         *
    1048         * @param a
    1049         * @param o
    1050         *            output can be null - in which case, a new dataset is created
    1051         * @return dataset of angles in radians
    1052         */
    1053        public static Dataset angle(final Object a, final Dataset o) {
    1054                return angle(a, false, o);
    1055        }
    1056
    1057        /**
    1058         * Create a dataset of the arguments from a complex dataset
    1059         *
    1060         * @param a
    1061         * @param inDegrees
    1062         *            if true then return angles in degrees else in radians
    1063         * @param o
    1064         *            output can be null - in which case, a new dataset is created
    1065         * @return dataset of angles
    1066         */
    1067        public static Dataset angle(final Object a, final boolean inDegrees, final Dataset o) {
    1068                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    1069
    1070                if (!da.isComplex()) {
    1071                        throw new UnsupportedOperationException("angle does not support this dataset type");
    1072                }
    1073
    1074                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, false, false);
    1075                final Dataset result = it.getOutput();
    1076                final int is = result.getElementsPerItem();
    1077                final int dt = result.getDType();
    1078
    1079                switch (dt) {
    1080                case Dataset.INT8:
    1081                        final byte[] oi8data = ((ByteDataset) result).getData();
    1082                        it.setOutputDouble(false);
    1083
    1084                        if (inDegrees) {
    1085                                while (it.hasNext()) {
    1086                                        oi8data[it.oIndex] = (byte) toLong(
    1087                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1088                                }
    1089                        } else {
    1090                                while (it.hasNext()) {
    1091                                        oi8data[it.oIndex] = (byte) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1092                                }
    1093                        }
    1094                        break;
    1095                case Dataset.INT16:
    1096                        final short[] oi16data = ((ShortDataset) result).getData();
    1097                        it.setOutputDouble(false);
    1098
    1099                        if (inDegrees) {
    1100                                while (it.hasNext()) {
    1101                                        oi16data[it.oIndex] = (short) toLong(
    1102                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1103                                }
    1104                        } else {
    1105                                while (it.hasNext()) {
    1106                                        oi16data[it.oIndex] = (short) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1107                                }
    1108                        }
    1109                        break;
    1110                case Dataset.INT32:
    1111                        final int[] oi32data = ((IntegerDataset) result).getData();
    1112                        it.setOutputDouble(false);
    1113
    1114                        if (inDegrees) {
    1115                                while (it.hasNext()) {
    1116                                        oi32data[it.oIndex] = (int) toLong(
    1117                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1118                                }
    1119                        } else {
    1120                                while (it.hasNext()) {
    1121                                        oi32data[it.oIndex] = (int) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1122                                }
    1123                        }
    1124                        break;
    1125                case Dataset.INT64:
    1126                        final long[] oi64data = ((LongDataset) result).getData();
    1127                        it.setOutputDouble(false);
    1128
    1129                        if (inDegrees) {
    1130                                while (it.hasNext()) {
    1131                                        oi64data[it.oIndex] = toLong(
    1132                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1133                                }
    1134                        } else {
    1135                                while (it.hasNext()) {
    1136                                        oi64data[it.oIndex] = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1137                                }
    1138                        }
    1139                        break;
    1140                case Dataset.ARRAYINT8:
    1141                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    1142                        it.setOutputDouble(false);
    1143
    1144                        if (inDegrees) {
    1145                                while (it.hasNext()) {
    1146                                        final byte ox = (byte) toLong(
    1147                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1148                                        for (int j = 0; j < is; j++) {
    1149                                                oai8data[it.oIndex + j] = ox;
    1150                                        }
    1151                                }
    1152                        } else {
    1153                                while (it.hasNext()) {
    1154                                        final byte ox = (byte) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1155                                        for (int j = 0; j < is; j++) {
    1156                                                oai8data[it.oIndex + j] = ox;
    1157                                        }
    1158                                }
    1159                        }
    1160                        break;
    1161                case Dataset.ARRAYINT16:
    1162                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    1163                        it.setOutputDouble(false);
    1164
    1165                        if (inDegrees) {
    1166                                while (it.hasNext()) {
    1167                                        final short ox = (short) toLong(
    1168                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1169                                        for (int j = 0; j < is; j++) {
    1170                                                oai16data[it.oIndex + j] = ox;
    1171                                        }
    1172                                }
    1173                        } else {
    1174                                while (it.hasNext()) {
    1175                                        final short ox = (short) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1176                                        for (int j = 0; j < is; j++) {
    1177                                                oai16data[it.oIndex + j] = ox;
    1178                                        }
    1179                                }
    1180                        }
    1181                        break;
    1182                case Dataset.ARRAYINT32:
    1183                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    1184                        it.setOutputDouble(false);
    1185
    1186                        if (inDegrees) {
    1187                                while (it.hasNext()) {
    1188                                        final int ox = (int) toLong(
    1189                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1190                                        for (int j = 0; j < is; j++) {
    1191                                                oai32data[it.oIndex + j] = ox;
    1192                                        }
    1193                                }
    1194                        } else {
    1195                                while (it.hasNext()) {
    1196                                        final int ox = (int) toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1197                                        for (int j = 0; j < is; j++) {
    1198                                                oai32data[it.oIndex + j] = ox;
    1199                                        }
    1200                                }
    1201                        }
    1202                        break;
    1203                case Dataset.ARRAYINT64:
    1204                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    1205                        it.setOutputDouble(false);
    1206
    1207                        if (inDegrees) {
    1208                                while (it.hasNext()) {
    1209                                        final long ox = toLong(
    1210                                                        Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble)));
    1211                                        for (int j = 0; j < is; j++) {
    1212                                                oai64data[it.oIndex + j] = ox;
    1213                                        }
    1214                                }
    1215                        } else {
    1216                                while (it.hasNext()) {
    1217                                        final long ox = toLong(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1218                                        for (int j = 0; j < is; j++) {
    1219                                                oai64data[it.oIndex + j] = ox;
    1220                                        }
    1221                                }
    1222                        }
    1223                        break;
    1224                case Dataset.FLOAT32:
    1225                        final float[] of32data = ((FloatDataset) result).getData();
    1226
    1227                        if (inDegrees) {
    1228                                while (it.hasNext()) {
    1229                                        of32data[it.oIndex] = (float) Math
    1230                                                        .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1231                                }
    1232                        } else {
    1233                                while (it.hasNext()) {
    1234                                        of32data[it.oIndex] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble);
    1235                                }
    1236                        }
    1237                        break;
    1238                case Dataset.FLOAT64:
    1239                        final double[] of64data = ((DoubleDataset) result).getData();
    1240
    1241                        if (inDegrees) {
    1242                                while (it.hasNext()) {
    1243                                        of64data[it.oIndex] = Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1244                                }
    1245                        } else {
    1246                                while (it.hasNext()) {
    1247                                        of64data[it.oIndex] = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble);
    1248                                }
    1249                        }
    1250                        break;
    1251                case Dataset.ARRAYFLOAT32:
    1252                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    1253
    1254                        if (inDegrees) {
    1255                                while (it.hasNext()) {
    1256                                        final float ox = (float) Math
    1257                                                        .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1258                                        for (int j = 0; j < is; j++) {
    1259                                                oaf32data[it.oIndex + j] = ox;
    1260                                        }
    1261                                }
    1262                        } else {
    1263                                while (it.hasNext()) {
    1264                                        final float ox = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble);
    1265                                        for (int j = 0; j < is; j++) {
    1266                                                oaf32data[it.oIndex + j] = ox;
    1267                                        }
    1268                                }
    1269                        }
    1270                        break;
    1271                case Dataset.ARRAYFLOAT64:
    1272                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    1273
    1274                        if (inDegrees) {
    1275                                while (it.hasNext()) {
    1276                                        final double ox = Math.toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1277                                        for (int j = 0; j < is; j++) {
    1278                                                oaf64data[it.oIndex + j] = ox;
    1279                                        }
    1280                                }
    1281                        } else {
    1282                                while (it.hasNext()) {
    1283                                        final double ox = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble);
    1284                                        for (int j = 0; j < is; j++) {
    1285                                                oaf64data[it.oIndex + j] = ox;
    1286                                        }
    1287                                }
    1288                        }
    1289                        break;
    1290                case Dataset.COMPLEX64:
    1291                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    1292
    1293                        if (inDegrees) {
    1294                                while (it.hasNext()) {
    1295                                        oc64data[it.oIndex] = (float) Math
    1296                                                        .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1297                                        oc64data[it.oIndex + 1] = 0;
    1298                                }
    1299                        } else {
    1300                                while (it.hasNext()) {
    1301                                        oc64data[it.oIndex] = (float) Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble);
    1302                                        oc64data[it.oIndex + 1] = 0;
    1303                                }
    1304                        }
    1305                        break;
    1306                case Dataset.COMPLEX128:
    1307                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    1308
    1309                        if (inDegrees) {
    1310                                while (it.hasNext()) {
    1311                                        oc128data[it.oIndex] = Math
    1312                                                        .toDegrees(Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble));
    1313                                        oc128data[it.oIndex + 1] = 0;
    1314                                }
    1315                        } else {
    1316                                while (it.hasNext()) {
    1317                                        oc128data[it.oIndex] = Math.atan2(da.getElementDoubleAbs(it.aIndex + 1), it.aDouble);
    1318                                        oc128data[it.oIndex + 1] = 0;
    1319                                }
    1320                        }
    1321                        break;
    1322                default:
    1323                        throw new IllegalArgumentException("angle does not support this dataset type");
    1324                }
    1325
    1326                addFunctionName(result, "angle");
    1327
    1328                return result;
    1329        }
    1330
    1331        /**
    1332         * Create a phase only dataset. NB it will contain NaNs if there are any
    1333         * items with zero amplitude
    1334         *
    1335         * @param a
    1336         *            dataset
    1337         * @param keepZeros
    1338         *            if true then zero items are returned as zero rather than NaNs
    1339         * @return complex dataset where items have unit amplitude
    1340         */
    1341        public static Dataset phaseAsComplexNumber(final Object a, final boolean keepZeros) {
    1342                return phaseAsComplexNumber(a, null, keepZeros);
    1343        }
    1344
    1345        /**
    1346         * Create a phase only dataset. NB it will contain NaNs if there are any
    1347         * items with zero amplitude
    1348         *
    1349         * @param a
    1350         *            dataset
    1351         * @param o
    1352         *            output can be null - in which case, a new dataset is created
    1353         * @param keepZeros
    1354         *            if true then zero items are returned as zero rather than NaNs
    1355         * @return complex dataset where items have unit amplitude
    1356         */
    1357        public static Dataset phaseAsComplexNumber(final Object a, final Dataset o, final boolean keepZeros) {
    1358                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    1359
    1360                if (!da.isComplex()) {
    1361                        throw new IllegalArgumentException("Input dataset is not of complex type");
    1362                }
    1363                Dataset result = o == null ? DatasetFactory.zeros(da) : o;
    1364                if (!result.isComplex()) {
    1365                        throw new IllegalArgumentException("Output dataset is not of complex type");
    1366                }
    1367                final int dt = result.getDType();
    1368                SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, result);
    1369
    1370                switch (dt) {
    1371                case Dataset.COMPLEX64:
    1372                        float[] z64data = ((ComplexFloatDataset) result).getData();
    1373
    1374                        if (keepZeros) {
    1375                                while (it.hasNext()) {
    1376                                        double rr = it.aDouble;
    1377                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
    1378                                        double am = Math.hypot(rr, ri);
    1379                                        if (am == 0) {
    1380                                                z64data[it.oIndex] = 0;
    1381                                                z64data[it.oIndex + 1] = 0;
    1382                                        } else {
    1383                                                z64data[it.oIndex] = (float) (rr / am);
    1384                                                z64data[it.oIndex + 1] = (float) (ri / am);
    1385                                        }
    1386                                }
    1387                        } else {
    1388                                while (it.hasNext()) {
    1389                                        double rr = it.aDouble;
    1390                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
    1391                                        double am = Math.hypot(rr, ri);
    1392                                        z64data[it.oIndex] = (float) (rr / am);
    1393                                        z64data[it.oIndex + 1] = (float) (ri / am);
    1394                                }
    1395                        }
    1396                        break;
    1397                case Dataset.COMPLEX128:
    1398                        double[] z128data = ((ComplexDoubleDataset) result).getData();
    1399
    1400                        if (keepZeros) {
    1401                                while (it.hasNext()) {
    1402                                        double rr = it.aDouble;
    1403                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
    1404                                        double am = Math.hypot(rr, ri);
    1405                                        if (am == 0) {
    1406                                                z128data[it.oIndex] = 0;
    1407                                                z128data[it.oIndex + 1] = 0;
    1408                                        } else {
    1409                                                z128data[it.oIndex] = rr / am;
    1410                                                z128data[it.oIndex + 1] = ri / am;
    1411                                        }
    1412                                }
    1413                        } else {
    1414                                while (it.hasNext()) {
    1415                                        double rr = it.aDouble;
    1416                                        double ri = da.getElementDoubleAbs(it.aIndex + 1);
    1417                                        double am = Math.hypot(rr, ri);
    1418                                        z128data[it.oIndex] = rr / am;
    1419                                        z128data[it.oIndex + 1] = ri / am;
    1420                                }
    1421                        }
    1422                        break;
    1423                }
    1424
    1425                addFunctionName(result, "phase");
    1426
    1427                return result;
    1428        }
    1429
    1430        /**
    1431         * Adds all sets passed in together
    1432         *
    1433         * The first IDataset must cast to Dataset
    1434         *
    1435         * For memory efficiency sake if add(...) is called with a set of size one,
    1436         * no clone is done, the original object is returned directly. Otherwise a
    1437         * new data set is returned, the sum of those passed in.
    1438         *
    1439         * @param sets
    1440         * @param requireClone
    1441         * @return sum of collection
    1442         */
    1443        public static Dataset add(final Collection<IDataset> sets, boolean requireClone) {
    1444                if (sets.isEmpty())
    1445                        return null;
    1446                final Iterator<IDataset> it = sets.iterator();
    1447                if (sets.size() == 1)
    1448                        return DatasetUtils.convertToDataset(it.next());
    1449
    1450                Dataset sum = requireClone ? ((Dataset) it.next()).clone() : (Dataset) it.next();
    1451
    1452                while (it.hasNext()) {
    1453                        Maths.add(sum, it.next(), sum);
    1454                }
    1455
    1456                return sum;
    1457        }
    1458
    1459        /**
    1460         * Multiplies all sets passed in together
    1461         *
    1462         * The first IDataset must cast to Dataset
    1463         *
    1464         * @param sets
    1465         * @param requireClone
    1466         * @return product of collection
    1467         */
    1468        public static Dataset multiply(final Collection<IDataset> sets, boolean requireClone) {
    1469                if (sets.isEmpty())
    1470                        return null;
    1471                final Iterator<IDataset> it = sets.iterator();
    1472                if (sets.size() == 1)
    1473                        return DatasetUtils.convertToDataset(it.next());
    1474                Dataset product = requireClone ? ((Dataset) it.next()).clone() : (Dataset) it.next();
    1475
    1476                while (it.hasNext()) {
    1477                        Maths.multiply(product, it.next(), product);
    1478                }
    1479
    1480                return product;
    1481        }
    1482
    1483        /**
    1484         * Linearly interpolate values at points in a 1D dataset corresponding to
    1485         * given coordinates.
    1486         *
    1487         * @param x
    1488         *            input 1-D coordinate dataset (must be ordered)
    1489         * @param d
    1490         *            input 1-D dataset
    1491         * @param x0
    1492         *            coordinate values
    1493         * @param left
    1494         *            value to use when x0 lies left of domain. If null, then
    1495         *            interpolate to zero by using leftmost interval
    1496         * @param right
    1497         *            value to use when x0 lies right of domain. If null, then
    1498         *            interpolate to zero by using rightmost interval
    1499         * @return interpolated values
    1500         */
    1501        public static Dataset interpolate(final Dataset x, final Dataset d, final IDataset x0, Number left, Number right) {
    1502                assert x.getRank() == 1;
    1503                assert d.getRank() == 1;
    1504
    1505                DoubleDataset r = DatasetFactory.zeros(DoubleDataset.class, x0.getShape());
    1506
    1507                Monotonicity mono = Comparisons.findMonotonicity(x);
    1508                if (mono == Monotonicity.NOT_ORDERED) {
    1509                        throw new IllegalArgumentException("Dataset x must be ordered");
    1510                }
    1511                DoubleDataset dx = DatasetUtils.cast(DoubleDataset.class, x);
    1512                Dataset dx0 = DatasetUtils.convertToDataset(x0);
    1513                if (x == dx) {
    1514                        dx = (DoubleDataset) x.flatten();
    1515                }
    1516                double[] xa = dx.getData();
    1517                int s = xa.length - 1;
    1518                boolean isReversed = mono == Monotonicity.STRICTLY_DECREASING || mono == Monotonicity.NONINCREASING;
    1519                if (isReversed) {
    1520                        double[] txa = xa.clone();
    1521                        for (int i = 0; i <= s; i++) { // reverse order
    1522                                txa[s - i] = xa[i];
    1523                        }
    1524                        xa = txa;
    1525                }
    1526
    1527                IndexIterator it = dx0.getIterator();
    1528                int k = -1;
    1529                while (it.hasNext()) {
    1530                        k++;
    1531                        double v = dx0.getElementDoubleAbs(it.index);
    1532                        int i = Arrays.binarySearch(xa, v);
    1533                        if (i < 0) {
    1534                                // i = -(insertion point) - 1
    1535                                if (i == -1) {
    1536                                        if (left != null) {
    1537                                                r.setAbs(k, left.doubleValue());
    1538                                                continue;
    1539                                        }
    1540                                        final double d1 = xa[0] - xa[1];
    1541                                        double t = d1 - v + xa[0];
    1542                                        if (t >= 0)
    1543                                                continue; // sets to zero
    1544                                        t /= d1;
    1545                                        r.setAbs(k, t * d.getDouble(isReversed ? s : 0));
    1546                                } else if (i == -s - 2) {
    1547                                        if (right != null) {
    1548                                                r.setAbs(k, right.doubleValue());
    1549                                                continue;
    1550                                        }
    1551                                        final double d1 = xa[s] - xa[s - 1];
    1552                                        double t = d1 - v + xa[s];
    1553                                        if (t <= 0)
    1554                                                continue; // sets to zero
    1555                                        t /= d1;
    1556                                        r.setAbs(k, t * d.getDouble(isReversed ? 0 : s));
    1557                                } else {
    1558                                        i = -i - 1;
    1559                                        double t = (xa[i] - v) / (xa[i] - xa[i - 1]);
    1560                                        if (isReversed) {
    1561                                                i = s - i;
    1562                                                r.setAbs(k, t * d.getDouble(i + 1) + (1 - t) * d.getDouble(i));
    1563                                        } else {
    1564                                                r.setAbs(k, (1 - t) * d.getDouble(i) + t * d.getDouble(i - 1));
    1565                                        }
    1566                                }
    1567                        } else {
    1568                                r.setAbs(k, d.getDouble(isReversed ? s - i : i));
    1569                        }
    1570                }
    1571                return r;
    1572        }
    1573
    1574        /**
    1575         * Linearly interpolate a value at a point in a 1D dataset. The dataset is
    1576         * considered to have zero support outside its bounds. Thus points just
    1577         * outside are interpolated from the boundary value to zero.
    1578         *
    1579         * @param d
    1580         *            input dataset
    1581         * @param x0
    1582         *            coordinate
    1583         * @return interpolated value
    1584         */
    1585        public static double interpolate(final Dataset d, final double x0) {
    1586                assert d.getRank() == 1;
    1587
    1588                final int i0 = (int) Math.floor(x0);
    1589                final int e0 = d.getSize() - 1;
    1590                if (i0 < -1 || i0 > e0)
    1591                        return 0;
    1592
    1593                final double u0 = x0 - i0;
    1594
    1595                double r = 0;
    1596                final double f1 = i0 < 0 ? 0 : d.getDouble(i0);
    1597                if (u0 > 0) {
    1598                        r = (1 - u0) * f1 + (i0 == e0 ? 0 : u0 * d.getDouble(i0 + 1));
    1599                } else {
    1600                        r = f1;
    1601                }
    1602                return r;
    1603        }
    1604
    1605        /**
    1606         * Linearly interpolate a value at a point in a 1D dataset with a mask. The
    1607         * dataset is considered to have zero support outside its bounds. Thus
    1608         * points just outside are interpolated from the boundary value to zero.
    1609         *
    1610         * @param d
    1611         *            input dataset
    1612         * @param m
    1613         *            mask dataset
    1614         * @param x0
    1615         *            coordinate
    1616         * @return interpolated value
    1617         */
    1618        public static double interpolate(final Dataset d, final Dataset m, final double x0) {
    1619                assert d.getRank() == 1;
    1620                assert m.getRank() == 1;
    1621
    1622                final int i0 = (int) Math.floor(x0);
    1623                final int e0 = d.getSize() - 1;
    1624                if (i0 < -1 || i0 > e0)
    1625                        return 0;
    1626
    1627                final double u0 = x0 - i0;
    1628
    1629                double r = 0;
    1630                final double f1 = i0 < 0 ? 0 : d.getDouble(i0) * m.getDouble(i0);
    1631                if (u0 > 0) {
    1632                        r = (1 - u0) * f1 + (i0 == e0 ? 0 : u0 * d.getDouble(i0 + 1) * m.getDouble(i0 + 1));
    1633                } else {
    1634                        r = f1;
    1635                }
    1636                return r;
    1637        }
    1638
    1639        /**
    1640         * Linearly interpolate an array of values at a point in a compound 1D
    1641         * dataset. The dataset is considered to have zero support outside its
    1642         * bounds. Thus points just outside are interpolated from the boundary value
    1643         * to zero.
    1644         *
    1645         * @param values
    1646         *            interpolated array
    1647         * @param d
    1648         *            input dataset
    1649         * @param x0
    1650         *            coordinate
    1651         */
    1652        public static void interpolate(final double[] values, final CompoundDataset d, final double x0) {
    1653                assert d.getRank() == 1;
    1654
    1655                final int is = d.getElementsPerItem();
    1656                if (is != values.length)
    1657                        throw new IllegalArgumentException("Output array length must match elements in item");
    1658                final double[] f1, f2;
    1659
    1660                final int i0 = (int) Math.floor(x0);
    1661                final int e0 = d.getSize() - 1;
    1662                if (i0 < -1 || i0 > e0) {
    1663                        Arrays.fill(values, 0);
    1664                        return;
    1665                }
    1666                final double u0 = x0 - i0;
    1667
    1668                if (u0 > 0) {
    1669                        f1 = new double[is];
    1670                        if (i0 >= 0)
    1671                                d.getDoubleArray(f1, i0);
    1672                        double t = 1 - u0;
    1673                        if (i0 == e0) {
    1674                                for (int j = 0; j < is; j++)
    1675                                        values[j] = t * f1[j];
    1676                        } else {
    1677                                f2 = new double[is];
    1678                                d.getDoubleArray(f2, i0 + 1);
    1679                                for (int j = 0; j < is; j++)
    1680                                        values[j] = t * f1[j] + u0 * f2[j];
    1681                        }
    1682                } else {
    1683                        if (i0 >= 0)
    1684                                d.getDoubleArray(values, i0);
    1685                        else
    1686                                Arrays.fill(values, 0);
    1687                }
    1688        }
    1689
    1690        /**
    1691         * Linearly interpolate a value at a point in a 2D dataset. The dataset is
    1692         * considered to have zero support outside its bounds. Thus points just
    1693         * outside are interpolated from the boundary value to zero.
    1694         *
    1695         * @param d
    1696         *            input dataset
    1697         * @param x0
    1698         *            coordinate
    1699         * @param x1
    1700         *            coordinate
    1701         * @return bilinear interpolation
    1702         */
    1703        public static double interpolate(final Dataset d, final double x0, final double x1) {
    1704                final int[] s = d.getShape();
    1705                assert s.length == 2;
    1706
    1707                final int e0 = s[0] - 1;
    1708                final int e1 = s[1] - 1;
    1709                final int i0 = (int) Math.floor(x0);
    1710                final int i1 = (int) Math.floor(x1);
    1711                final double u0 = x0 - i0;
    1712                final double u1 = x1 - i1;
    1713                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1)
    1714                        return 0;
    1715
    1716                // use bilinear interpolation
    1717                double r = 0;
    1718                final double f1, f2, f3, f4;
    1719                f1 = i0 < 0 || i1 < 0 ? 0 : d.getDouble(i0, i1);
    1720                if (u1 > 0) {
    1721                        if (u0 > 0) {
    1722                                if (i0 == e0) {
    1723                                        f2 = 0;
    1724                                        f4 = 0;
    1725                                        f3 = i1 == e1 ? 0 : d.getDouble(i0, i1 + 1);
    1726                                } else {
    1727                                        f2 = i1 < 0 ? 0 : d.getDouble(i0 + 1, i1);
    1728                                        if (i1 == e1) {
    1729                                                f4 = 0;
    1730                                                f3 = 0;
    1731                                        } else {
    1732                                                f4 = d.getDouble(i0 + 1, i1 + 1);
    1733                                                f3 = i0 < 0 ? 0 : d.getDouble(i0, i1 + 1);
    1734                                        }
    1735                                }
    1736                                r = (1 - u0) * (1 - u1) * f1 + u0 * (1 - u1) * f2 + (1 - u0) * u1 * f3 + u0 * u1 * f4;
    1737                        } else {
    1738                                f3 = i0 < 0 || i1 == e1 ? 0 : d.getDouble(i0, i1 + 1);
    1739                                r = (1 - u1) * f1 + u1 * f3;
    1740                        }
    1741                } else { // exactly on axis 1
    1742                        if (u0 > 0) {
    1743                                f2 = i0 == e0 || i1 < 0 ? 0 : d.getDouble(i0 + 1, i1);
    1744                                r = (1 - u0) * f1 + u0 * f2;
    1745                        } else { // exactly on axis 0
    1746                                r = f1;
    1747                        }
    1748                }
    1749                return r;
    1750        }
    1751
    1752        /**
    1753         * Linearly interpolate a value at a point in a 2D dataset with a mask. The
    1754         * dataset is considered to have zero support outside its bounds. Thus
    1755         * points just outside are interpolated from the boundary value to zero.
    1756         *
    1757         * @param d
    1758         *            input dataset
    1759         * @param m
    1760         *            mask dataset
    1761         * @param x0
    1762         *            coordinate
    1763         * @param x1
    1764         *            coordinate
    1765         * @return bilinear interpolation
    1766         */
    1767        public static double interpolate(final Dataset d, final Dataset m, final double x0, final double x1) {
    1768                if (m == null)
    1769                        return interpolate(d, x0, x1);
    1770
    1771                final int[] s = d.getShape();
    1772                assert s.length == 2;
    1773                assert m.getRank() == 2;
    1774
    1775                final int e0 = s[0] - 1;
    1776                final int e1 = s[1] - 1;
    1777                final int i0 = (int) Math.floor(x0);
    1778                final int i1 = (int) Math.floor(x1);
    1779                final double u0 = x0 - i0;
    1780                final double u1 = x1 - i1;
    1781                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1)
    1782                        return 0;
    1783
    1784                // use bilinear interpolation
    1785                double r = 0;
    1786                final double f1, f2, f3, f4;
    1787                f1 = i0 < 0 || i1 < 0 ? 0 : d.getDouble(i0, i1) * m.getDouble(i0, i1);
    1788                if (u1 > 0) {
    1789                        if (i0 == e0) {
    1790                                f2 = 0;
    1791                                f4 = 0;
    1792                                f3 = i1 == e1 ? 0 : d.getDouble(i0, i1 + 1) * m.getDouble(i0, i1 + 1);
    1793                        } else {
    1794                                f2 = i1 < 0 ? 0 : d.getDouble(i0 + 1, i1) * m.getDouble(i0 + 1, i1);
    1795                                if (i1 == e1) {
    1796                                        f4 = 0;
    1797                                        f3 = 0;
    1798                                } else {
    1799                                        f4 = d.getDouble(i0 + 1, i1 + 1) * m.getDouble(i0 + 1, i1 + 1);
    1800                                        f3 = i0 < 0 ? 0 : d.getDouble(i0, i1 + 1) * m.getDouble(i0, i1 + 1);
    1801                                }
    1802                        }
    1803                        r = (1 - u0) * (1 - u1) * f1 + u0 * (1 - u1) * f2 + (1 - u0) * u1 * f3 + u0 * u1 * f4;
    1804                } else { // exactly on axis 1
    1805                        if (u0 > 0) {
    1806                                f2 = i0 == e0 || i1 < 0 ? 0 : d.getDouble(i0 + 1, i1) * m.getDouble(i0 + 1, i1);
    1807                                r = (1 - u0) * f1 + u0 * f2;
    1808                        } else { // exactly on axis 0
    1809                                r = f1;
    1810                        }
    1811                }
    1812                return r;
    1813        }
    1814
    1815        /**
    1816         * Linearly interpolate an array of values at a point in a compound 2D
    1817         * dataset. The dataset is considered to have zero support outside its
    1818         * bounds. Thus points just outside are interpolated from the boundary value
    1819         * to zero.
    1820         *
    1821         * @param values
    1822         *            bilinear interpolated array
    1823         * @param d
    1824         * @param x0
    1825         * @param x1
    1826         */
    1827        public static void interpolate(final double[] values, final CompoundDataset d, final double x0, final double x1) {
    1828                final int[] s = d.getShapeRef();
    1829                assert s.length == 2;
    1830
    1831                final int is = d.getElementsPerItem();
    1832                if (is != values.length)
    1833                        throw new IllegalArgumentException("Output array length must match elements in item");
    1834
    1835                final int e0 = s[0] - 1;
    1836                final int e1 = s[1] - 1;
    1837                final int i0 = (int) Math.floor(x0);
    1838                final int i1 = (int) Math.floor(x1);
    1839                final double u0 = x0 - i0;
    1840                final double u1 = x1 - i1;
    1841                if (i0 < -1 || i0 > e0 || i1 < -1 || i1 > e1) {
    1842                        Arrays.fill(values, 0);
    1843                        return;
    1844                }
    1845                // use bilinear interpolation
    1846                double[] f1 = new double[is];
    1847                if (i0 >= 0 && i1 >= 0)
    1848                        d.getDoubleArray(f1, i0, i1);
    1849
    1850                if (u1 > 0) {
    1851                        if (u0 > 0) {
    1852                                double[] f2 = new double[is];
    1853                                double[] f3 = new double[is];
    1854                                double[] f4 = new double[is];
    1855                                if (i0 != e0) {
    1856                                        if (i1 != e1)
    1857                                                d.getDoubleArray(f3, i0 + 1, i1 + 1);
    1858                                        if (i1 >= 0)
    1859                                                d.getDoubleArray(f4, i0 + 1, i1);
    1860                                }
    1861                                if (i0 >= 0 && i1 != e1)
    1862                                        d.getDoubleArray(f2, i0, i1 + 1);
    1863                                final double t0 = 1 - u0;
    1864                                final double t1 = 1 - u1;
    1865                                final double w1 = t0 * t1;
    1866                                final double w2 = t0 * u1;
    1867                                final double w3 = u0 * u1;
    1868                                final double w4 = u0 * t1;
    1869                                for (int j = 0; j < is; j++)
    1870                                        values[j] = w1 * f1[j] + w2 * f2[j] + w3 * f3[j] + w4 * f4[j];
    1871                        } else {
    1872                                double[] f2 = new double[is];
    1873                                if (i0 >= 0 && i1 != e1)
    1874                                        d.getDoubleArray(f2, i0, i1 + 1);
    1875                                final double t1 = 1 - u1;
    1876                                for (int j = 0; j < is; j++)
    1877                                        values[j] = t1 * f1[j] + u1 * f2[j];
    1878                        }
    1879                } else { // exactly on axis 1
    1880                        if (u0 > 0) {
    1881                                double[] f4 = new double[is];
    1882                                if (i0 != e0 && i1 >= 0)
    1883                                        d.getDoubleArray(f4, i0 + 1, i1);
    1884                                final double t0 = 1 - u0;
    1885                                for (int j = 0; j < is; j++)
    1886                                        values[j] = t0 * f1[j] + u0 * f4[j];
    1887                        } else { // exactly on axis 0
    1888                                if (i0 >= 0 && i1 >= 0)
    1889                                        d.getDoubleArray(values, i0, i1);
    1890                                else
    1891                                        Arrays.fill(values, 0);
    1892                        }
    1893                }
    1894        }
    1895
    1896        /**
    1897         * Linearly interpolate a value at a point in a n-D dataset. The dataset is
    1898         * considered to have zero support outside its bounds. Thus points just
    1899         * outside are interpolated from the boundary value to zero. The number of
    1900         * coordinates must match the rank of the dataset.
    1901         *
    1902         * @param d
    1903         *            input dataset
    1904         * @param x
    1905         *            coordinates
    1906         * @return interpolated value
    1907         */
    1908        public static double interpolate(final Dataset d, final double... x) {
    1909                return interpolate(d, null, x);
    1910        }
    1911
    1912        /**
    1913         * Linearly interpolate a value at a point in a n-D dataset with a mask. The
    1914         * dataset is considered to have zero support outside its bounds. Thus
    1915         * points just outside are interpolated from the boundary value to zero. The
    1916         * number of coordinates must match the rank of the dataset.
    1917         *
    1918         * @param d
    1919         *            input dataset
    1920         * @param m
    1921         *            mask dataset (can be null)
    1922         * @param x
    1923         *            coordinates
    1924         * @return interpolated value
    1925         */
    1926        public static double interpolate(final Dataset d, final Dataset m, final double... x) {
    1927                int r = d.getRank();
    1928                if (r != x.length) {
    1929                        throw new IllegalArgumentException("Number of coordinates must be equal to rank of dataset");
    1930                }
    1931
    1932                switch (r) {
    1933                case 1:
    1934                        return m == null ? interpolate(d, x[0]) : interpolate(d, m, x[0]);
    1935                case 2:
    1936                        return m == null ? interpolate(d, x[0], x[1]) : interpolate(d, m, x[0], x[1]);
    1937                }
    1938
    1939                if (m != null && r != m.getRank()) {
    1940                        throw new IllegalArgumentException("Rank of mask dataset must be equal to rank of dataset");
    1941                }
    1942
    1943                // now do it iteratively
    1944                int[] l = new int[r]; // lower indexes
    1945                double[] f = new double[r]; // fractions
    1946                for (int i = 0; i < r; i++) {
    1947                        double xi = x[i];
    1948                        l[i] = (int) Math.floor(xi);
    1949                        f[i] = xi - l[i];
    1950                }
    1951
    1952                int[] s = d.getShape();
    1953
    1954                int n = 1 << r;
    1955                double[] results = new double[n];
    1956
    1957                // iterate over permutations {l} and {l+1}
    1958                int[] twos = new int[r];
    1959                Arrays.fill(twos, 2);
    1960                PositionIterator it = new PositionIterator(twos);
    1961                int[] ip = it.getPos();
    1962                int j = 0;
    1963                if (m == null) {
    1964                        while (it.hasNext()) {
    1965                                int[] p = l.clone();
    1966                                boolean omit = false;
    1967                                for (int i = 0; i < r; i++) {
    1968                                        int pi = p[i] + ip[i];
    1969                                        if (pi < 0 || pi >= s[i]) {
    1970                                                omit = true;
    1971                                                break;
    1972                                        }
    1973                                        p[i] = pi;
    1974                                }
    1975                                results[j++] = omit ? 0 : d.getDouble(p);
    1976                        }
    1977                } else {
    1978                        while (it.hasNext()) {
    1979                                int[] p = l.clone();
    1980                                boolean omit = false;
    1981                                for (int i = 0; i < r; i++) {
    1982                                        int pi = p[i] + ip[i];
    1983                                        if (pi < 0 || pi >= s[i]) {
    1984                                                omit = true;
    1985                                                break;
    1986                                        }
    1987                                        p[i] = pi;
    1988                                }
    1989                                results[j++] = omit ? 0 : d.getDouble(p) * m.getDouble(p);
    1990                        }
    1991                }
    1992
    1993                // reduce recursively
    1994                for (int i = r - 1; i >= 0; i--) {
    1995                        results = combine(results, f[i], 1 << i);
    1996                }
    1997                return results[0];
    1998        }
    1999
    2000        private static double[] combine(double[] values, double f, int n) {
    2001                double g = 1 - f;
    2002                double[] results = new double[n];
    2003                for (int j = 0; j < n; j++) {
    2004                        int tj = 2 * j;
    2005                        results[j] = g * values[tj] + f * values[tj + 1];
    2006                }
    2007
    2008                return results;
    2009        }
    2010
    2011        /**
    2012         * Linearly interpolate an array of values at a point in a compound n-D
    2013         * dataset. The dataset is considered to have zero support outside its
    2014         * bounds. Thus points just outside are interpolated from the boundary value
    2015         * to zero.
    2016         *
    2017         * @param values
    2018         *            linearly interpolated array
    2019         * @param d
    2020         * @param x
    2021         */
    2022        public static void interpolate(final double[] values, final CompoundDataset d, final double... x) {
    2023                int r = d.getRank();
    2024                if (r != x.length) {
    2025                        throw new IllegalArgumentException("Number of coordinates must be equal to rank of dataset");
    2026                }
    2027
    2028                switch (r) {
    2029                case 1:
    2030                        interpolate(values, d, x[0]);
    2031                        return;
    2032                case 2:
    2033                        interpolate(values, d, x[0], x[1]);
    2034                        return;
    2035                }
    2036
    2037                final int is = d.getElementsPerItem();
    2038                if (is != values.length)
    2039                        throw new IllegalArgumentException("Output array length must match elements in item");
    2040
    2041                // now do it iteratively
    2042                int[] l = new int[r]; // lower indexes
    2043                double[] f = new double[r]; // fractions
    2044                for (int i = 0; i < r; i++) {
    2045                        double xi = x[i];
    2046                        l[i] = (int) Math.floor(xi);
    2047                        f[i] = xi - l[i];
    2048                }
    2049
    2050                int[] s = d.getShape();
    2051
    2052                int n = 1 << r;
    2053                double[][] results = new double[n][is];
    2054
    2055                // iterate over permutations {l} and {l+1}
    2056                int[] twos = new int[r];
    2057                Arrays.fill(twos, 2);
    2058                PositionIterator it = new PositionIterator(twos);
    2059                int[] ip = it.getPos();
    2060                int j = 0;
    2061                while (it.hasNext()) {
    2062                        int[] p = l.clone();
    2063                        boolean omit = false;
    2064                        for (int i = 0; i < r; i++) {
    2065                                int pi = p[i] + ip[i];
    2066                                if (pi < 0 || pi >= s[i]) {
    2067                                        omit = true;
    2068                                        break;
    2069                                }
    2070                                p[i] = pi;
    2071                        }
    2072                        if (!omit) {
    2073                                d.getDoubleArray(results[j++], p);
    2074                        }
    2075                }
    2076
    2077                // reduce recursively
    2078                for (int i = r - 1; i >= 0; i--) {
    2079                        results = combineArray(is, results, f[i], 1 << i);
    2080                }
    2081                for (int k = 0; k < is; k++) {
    2082                        values[k] = results[0][k];
    2083                }
    2084        }
    2085
    2086        private static double[][] combineArray(int is, double[][] values, double f, int n) {
    2087                double g = 1 - f;
    2088                double[][] results = new double[n][is];
    2089                for (int j = 0; j < n; j++) {
    2090                        int tj = 2 * j;
    2091                        for (int k = 0; k < is; k++) {
    2092                                results[j][k] = g * values[tj][k] + f * values[tj + 1][k];
    2093                        }
    2094                }
    2095
    2096                return results;
    2097        }
    2098
    2099        /**
    2100         * Linearly interpolate a value at a point in a 1D dataset. The dataset is
    2101         * considered to have zero support outside its bounds. Thus points just
    2102         * outside are interpolated from the boundary value to zero.
    2103         *
    2104         * @param d
    2105         *            input dataset
    2106         * @param x0
    2107         *            coordinate
    2108         * @return interpolated value
    2109         * @deprecated Use {@link #interpolate(Dataset, double)}
    2110         */
    2111        @Deprecated
    2112        public static double getLinear(final IDataset d, final double x0) {
    2113                return interpolate(DatasetUtils.convertToDataset(d), x0);
    2114        }
    2115
    2116        /**
    2117         * Linearly interpolate a value at a point in a compound 1D dataset. The
    2118         * dataset is considered to have zero support outside its bounds. Thus
    2119         * points just outside are interpolated from the boundary value to zero.
    2120         *
    2121         * @param values
    2122         *            interpolated array
    2123         * @param d
    2124         *            input dataset
    2125         * @param x0
    2126         *            coordinate
    2127         * @deprecated Use {@link #interpolate(double[], CompoundDataset, double)}
    2128         */
    2129        @Deprecated
    2130        public static void getLinear(final double[] values, final CompoundDataset d, final double x0) {
    2131                interpolate(values, d, x0);
    2132        }
    2133
    2134        /**
    2135         * Interpolated a value from 2D dataset
    2136         *
    2137         * @param d
    2138         *            input dataset
    2139         * @param x0
    2140         *            coordinate
    2141         * @param x1
    2142         *            coordinate
    2143         * @return bilinear interpolation
    2144         * @deprecated Use {@link #interpolate(Dataset, double, double)}
    2145         */
    2146        @Deprecated
    2147        public static double getBilinear(final IDataset d, final double x0, final double x1) {
    2148                return interpolate(DatasetUtils.convertToDataset(d), x0, x1);
    2149        }
    2150
    2151        /**
    2152         * Interpolated a value from 2D dataset with mask
    2153         *
    2154         * @param d
    2155         *            input dataset
    2156         * @param m
    2157         *            mask dataset
    2158         * @param x0
    2159         *            coordinate
    2160         * @param x1
    2161         *            coordinate
    2162         * @return bilinear interpolation
    2163         * @deprecated Use {@link #interpolate(Dataset, Dataset, double, double)}
    2164         */
    2165        @Deprecated
    2166        public static double getBilinear(final IDataset d, final IDataset m, final double x0, final double x1) {
    2167                return interpolate(DatasetUtils.convertToDataset(d), DatasetUtils.convertToDataset(m), x0, x1);
    2168        }
    2169
    2170        /**
    2171         * Interpolated a value from 2D compound dataset
    2172         *
    2173         * @param values
    2174         *            bilinear interpolated array
    2175         * @param d
    2176         * @param x0
    2177         * @param x1
    2178         * @deprecated Use
    2179         *             {@link #interpolate(double[], CompoundDataset, double, double)}
    2180         */
    2181        @Deprecated
    2182        public static void getBilinear(final double[] values, final CompoundDataset d, final double x0, final double x1) {
    2183                interpolate(values, d, x0, x1);
    2184        }
    2185
    2186        /**
    2187         * generate binomial coefficients with negative sign:
    2188         * <p>
    2189         *
    2190         * <pre>
    2191         *  (-1)^i n! / ( i! (n-i)! )
    2192         * </pre>
    2193         *
    2194         * @param n
    2195         * @return array of coefficients
    2196         */
    2197        private static int[] bincoeff(final int n) {
    2198                final int[] b = new int[n + 1];
    2199                final int hn = n / 2;
    2200
    2201                int bc = 1;
    2202                b[0] = bc;
    2203                for (int i = 1; i <= hn; i++) {
    2204                        bc = -(bc * (n - i + 1)) / i;
    2205                        b[i] = bc;
    2206                }
    2207                if (n % 2 != 0) {
    2208                        for (int i = hn + 1; i <= n; i++) {
    2209                                b[i] = -b[n - i];
    2210                        }
    2211                } else {
    2212                        for (int i = hn + 1; i <= n; i++) {
    2213                                b[i] = b[n - i];
    2214                        }
    2215                }
    2216                return b;
    2217        }
    2218
    2219        /**
    2220         * 1st order discrete difference of dataset along flattened dataset using
    2221         * finite difference
    2222         *
    2223         * @param a
    2224         *            is 1d dataset
    2225         * @param out
    2226         *            is 1d dataset
    2227         */
    2228        private static void difference(final Dataset a, final Dataset out) {
    2229                final int isize = a.getElementsPerItem();
    2230
    2231                final IndexIterator it = a.getIterator();
    2232                if (!it.hasNext())
    2233                        return;
    2234                int oi = it.index;
    2235
    2236                switch (a.getDType()) {
    2237                case Dataset.INT8:
    2238                        final byte[] i8data = ((ByteDataset) a).getData();
    2239                        final byte[] oi8data = ((ByteDataset) out).getData();
    2240                        for (int i = 0; it.hasNext();) {
    2241                                oi8data[i++] = (byte) (i8data[it.index] - i8data[oi]);
    2242                                oi = it.index;
    2243                        }
    2244                        break;
    2245                case Dataset.INT16:
    2246                        final short[] i16data = ((ShortDataset) a).getData();
    2247                        final short[] oi16data = ((ShortDataset) out).getData();
    2248                        for (int i = 0; it.hasNext();) {
    2249                                oi16data[i++] = (short) (i16data[it.index] - i16data[oi]);
    2250                                oi = it.index;
    2251                        }
    2252                        break;
    2253                case Dataset.INT32:
    2254                        final int[] i32data = ((IntegerDataset) a).getData();
    2255                        final int[] oi32data = ((IntegerDataset) out).getData();
    2256                        for (int i = 0; it.hasNext();) {
    2257                                oi32data[i++] = i32data[it.index] - i32data[oi];
    2258                                oi = it.index;
    2259                        }
    2260                        break;
    2261                case Dataset.INT64:
    2262                        final long[] i64data = ((LongDataset) a).getData();
    2263                        final long[] oi64data = ((LongDataset) out).getData();
    2264                        for (int i = 0; it.hasNext();) {
    2265                                oi64data[i++] = i64data[it.index] - i64data[oi];
    2266                                oi = it.index;
    2267                        }
    2268                        break;
    2269                case Dataset.ARRAYINT8:
    2270                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
    2271                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
    2272                        for (int i = 0; it.hasNext();) {
    2273                                for (int k = 0; k < isize; k++) {
    2274                                        oai8data[i++] = (byte) (ai8data[it.index + k] - ai8data[oi++]);
    2275                                }
    2276                                oi = it.index;
    2277                        }
    2278                        break;
    2279                case Dataset.ARRAYINT16:
    2280                        final short[] ai16data = ((CompoundShortDataset) a).getData();
    2281                        final short[] oai16data = ((CompoundShortDataset) out).getData();
    2282                        for (int i = 0; it.hasNext();) {
    2283                                for (int k = 0; k < isize; k++) {
    2284                                        oai16data[i++] = (short) (ai16data[it.index + k] - ai16data[oi++]);
    2285                                }
    2286                                oi = it.index;
    2287                        }
    2288                        break;
    2289                case Dataset.ARRAYINT32:
    2290                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
    2291                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
    2292                        for (int i = 0; it.hasNext();) {
    2293                                for (int k = 0; k < isize; k++) {
    2294                                        oai32data[i++] = ai32data[it.index + k] - ai32data[oi++];
    2295                                }
    2296                                oi = it.index;
    2297                        }
    2298                        break;
    2299                case Dataset.ARRAYINT64:
    2300                        final long[] ai64data = ((CompoundLongDataset) a).getData();
    2301                        final long[] oai64data = ((CompoundLongDataset) out).getData();
    2302                        for (int i = 0; it.hasNext();) {
    2303                                for (int k = 0; k < isize; k++) {
    2304                                        oai64data[i++] = ai64data[it.index + k] - ai64data[oi++];
    2305                                }
    2306                                oi = it.index;
    2307                        }
    2308                        break;
    2309                case Dataset.FLOAT32:
    2310                        final float[] f32data = ((FloatDataset) a).getData();
    2311                        final float[] of32data = ((FloatDataset) out).getData();
    2312                        for (int i = 0; it.hasNext();) {
    2313                                of32data[i++] = f32data[it.index] - f32data[oi];
    2314                                oi = it.index;
    2315                        }
    2316                        break;
    2317                case Dataset.FLOAT64:
    2318                        final double[] f64data = ((DoubleDataset) a).getData();
    2319                        final double[] of64data = ((DoubleDataset) out).getData();
    2320                        for (int i = 0; it.hasNext();) {
    2321                                of64data[i++] = f64data[it.index] - f64data[oi];
    2322                                oi = it.index;
    2323                        }
    2324                        break;
    2325                case Dataset.COMPLEX64:
    2326                        final float[] c64data = ((ComplexFloatDataset) a).getData();
    2327                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
    2328                        for (int i = 0; it.hasNext();) {
    2329                                oc64data[i++] = c64data[it.index] - c64data[oi];
    2330                                oc64data[i++] = c64data[it.index + 1] - c64data[oi + 1];
    2331                                oi = it.index;
    2332                        }
    2333                        break;
    2334                case Dataset.COMPLEX128:
    2335                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
    2336                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
    2337                        for (int i = 0; it.hasNext();) {
    2338                                oc128data[i++] = c128data[it.index] - c128data[oi];
    2339                                oc128data[i++] = c128data[it.index + 1] - c128data[oi + 1];
    2340                                oi = it.index;
    2341                        }
    2342                        break;
    2343                case Dataset.ARRAYFLOAT32:
    2344                        final float[] af32data = ((CompoundFloatDataset) a).getData();
    2345                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
    2346                        for (int i = 0; it.hasNext();) {
    2347                                for (int k = 0; k < isize; k++) {
    2348                                        oaf32data[i++] = af32data[it.index + k] - af32data[oi++];
    2349                                }
    2350                                oi = it.index;
    2351                        }
    2352                        break;
    2353                case Dataset.ARRAYFLOAT64:
    2354                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
    2355                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
    2356                        for (int i = 0; it.hasNext();) {
    2357                                for (int k = 0; k < isize; k++) {
    2358                                        oaf64data[i++] = af64data[it.index + k] - af64data[oi++];
    2359                                }
    2360                                oi = it.index;
    2361                        }
    2362                        break;
    2363                default:
    2364                        throw new UnsupportedOperationException("difference does not support this dataset type");
    2365                }
    2366        }
    2367
    2368        /**
    2369         * Get next set of indexes
    2370         *
    2371         * @param it
    2372         * @param indexes
    2373         * @return true if there is more
    2374         */
    2375        private static boolean nextIndexes(IndexIterator it, int[] indexes) {
    2376                if (!it.hasNext())
    2377                        return false;
    2378                int m = indexes.length;
    2379                int i = 0;
    2380                for (i = 0; i < m - 1; i++) {
    2381                        indexes[i] = indexes[i + 1];
    2382                }
    2383                indexes[i] = it.index;
    2384                return true;
    2385        }
    2386
    2387        /**
    2388         * General order discrete difference of dataset along flattened dataset
    2389         * using finite difference
    2390         *
    2391         * @param a
    2392         *            is 1d dataset
    2393         * @param out
    2394         *            is 1d dataset
    2395         * @param n
    2396         *            order of difference
    2397         */
    2398        private static void difference(final Dataset a, final Dataset out, final int n) {
    2399                if (n == 1) {
    2400                        difference(a, out);
    2401                        return;
    2402                }
    2403
    2404                final int isize = a.getElementsPerItem();
    2405
    2406                final int[] coeff = bincoeff(n);
    2407                final int m = n + 1;
    2408                final int[] indexes = new int[m]; // store for index values
    2409
    2410                final IndexIterator it = a.getIterator();
    2411                for (int i = 0; i < n; i++) {
    2412                        indexes[i] = it.index;
    2413                        it.hasNext();
    2414                }
    2415                indexes[n] = it.index;
    2416
    2417                switch (a.getDType()) {
    2418                case Dataset.INT8:
    2419                        final byte[] i8data = ((ByteDataset) a).getData();
    2420                        final byte[] oi8data = ((ByteDataset) out).getData();
    2421                        for (int i = 0; nextIndexes(it, indexes);) {
    2422                                int ox = 0;
    2423                                for (int j = 0; j < m; j++) {
    2424                                        ox += i8data[indexes[j]] * coeff[j];
    2425                                }
    2426                                oi8data[i++] = (byte) ox;
    2427                        }
    2428                        break;
    2429                case Dataset.INT16:
    2430                        final short[] i16data = ((ShortDataset) a).getData();
    2431                        final short[] oi16data = ((ShortDataset) out).getData();
    2432                        for (int i = 0; nextIndexes(it, indexes);) {
    2433                                int ox = 0;
    2434                                for (int j = 0; j < m; j++) {
    2435                                        ox += i16data[indexes[j]] * coeff[j];
    2436                                }
    2437                                oi16data[i++] = (short) ox;
    2438                        }
    2439                        break;
    2440                case Dataset.INT32:
    2441                        final int[] i32data = ((IntegerDataset) a).getData();
    2442                        final int[] oi32data = ((IntegerDataset) out).getData();
    2443                        for (int i = 0; nextIndexes(it, indexes);) {
    2444                                int ox = 0;
    2445                                for (int j = 0; j < m; j++) {
    2446                                        ox += i32data[indexes[j]] * coeff[j];
    2447                                }
    2448                                oi32data[i++] = ox;
    2449                        }
    2450                        break;
    2451                case Dataset.INT64:
    2452                        final long[] i64data = ((LongDataset) a).getData();
    2453                        final long[] oi64data = ((LongDataset) out).getData();
    2454                        for (int i = 0; nextIndexes(it, indexes);) {
    2455                                long ox = 0;
    2456                                for (int j = 0; j < m; j++) {
    2457                                        ox += i64data[indexes[j]] * coeff[j];
    2458                                }
    2459                                oi64data[i++] = ox;
    2460                        }
    2461                        break;
    2462                case Dataset.ARRAYINT8:
    2463                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
    2464                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
    2465                        int[] box = new int[isize];
    2466                        for (int i = 0; nextIndexes(it, indexes);) {
    2467                                Arrays.fill(box, 0);
    2468                                for (int j = 0; j < m; j++) {
    2469                                        double c = coeff[j];
    2470                                        int l = indexes[j];
    2471                                        for (int k = 0; k < isize; k++) {
    2472                                                box[k] += ai8data[l++] * c;
    2473                                        }
    2474                                }
    2475                                for (int k = 0; k < isize; k++) {
    2476                                        oai8data[i++] = (byte) box[k];
    2477                                }
    2478                        }
    2479                        break;
    2480                case Dataset.ARRAYINT16:
    2481                        final short[] ai16data = ((CompoundShortDataset) a).getData();
    2482                        final short[] oai16data = ((CompoundShortDataset) out).getData();
    2483                        int[] sox = new int[isize];
    2484                        for (int i = 0; nextIndexes(it, indexes);) {
    2485                                Arrays.fill(sox, 0);
    2486                                for (int j = 0; j < m; j++) {
    2487                                        double c = coeff[j];
    2488                                        int l = indexes[j];
    2489                                        for (int k = 0; k < isize; k++) {
    2490                                                sox[k] += ai16data[l++] * c;
    2491                                        }
    2492                                }
    2493                                for (int k = 0; k < isize; k++) {
    2494                                        oai16data[i++] = (short) sox[k];
    2495                                }
    2496                        }
    2497                        break;
    2498                case Dataset.ARRAYINT32:
    2499                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
    2500                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
    2501                        int[] iox = new int[isize];
    2502                        for (int i = 0; nextIndexes(it, indexes);) {
    2503                                Arrays.fill(iox, 0);
    2504                                for (int j = 0; j < m; j++) {
    2505                                        double c = coeff[j];
    2506                                        int l = indexes[j];
    2507                                        for (int k = 0; k < isize; k++) {
    2508                                                iox[k] += ai32data[l++] * c;
    2509                                        }
    2510                                }
    2511                                for (int k = 0; k < isize; k++) {
    2512                                        oai32data[i++] = iox[k];
    2513                                }
    2514                        }
    2515                        break;
    2516                case Dataset.ARRAYINT64:
    2517                        final long[] ai64data = ((CompoundLongDataset) a).getData();
    2518                        final long[] oai64data = ((CompoundLongDataset) out).getData();
    2519                        long[] lox = new long[isize];
    2520                        for (int i = 0; nextIndexes(it, indexes);) {
    2521                                Arrays.fill(lox, 0);
    2522                                for (int j = 0; j < m; j++) {
    2523                                        double c = coeff[j];
    2524                                        int l = indexes[j];
    2525                                        for (int k = 0; k < isize; k++) {
    2526                                                lox[k] += ai64data[l++] * c;
    2527                                        }
    2528                                }
    2529                                for (int k = 0; k < isize; k++) {
    2530                                        oai64data[i++] = lox[k];
    2531                                }
    2532                        }
    2533                        break;
    2534                case Dataset.FLOAT32:
    2535                        final float[] f32data = ((FloatDataset) a).getData();
    2536                        final float[] of32data = ((FloatDataset) out).getData();
    2537                        for (int i = 0; nextIndexes(it, indexes);) {
    2538                                float ox = 0;
    2539                                for (int j = 0; j < m; j++) {
    2540                                        ox += f32data[indexes[j]] * coeff[j];
    2541                                }
    2542                                of32data[i++] = ox;
    2543                        }
    2544                        break;
    2545                case Dataset.FLOAT64:
    2546                        final double[] f64data = ((DoubleDataset) a).getData();
    2547                        final double[] of64data = ((DoubleDataset) out).getData();
    2548                        for (int i = 0; nextIndexes(it, indexes);) {
    2549                                double ox = 0;
    2550                                for (int j = 0; j < m; j++) {
    2551                                        ox += f64data[indexes[j]] * coeff[j];
    2552                                }
    2553                                of64data[i++] = ox;
    2554                        }
    2555                        break;
    2556                case Dataset.COMPLEX64:
    2557                        final float[] c64data = ((ComplexFloatDataset) a).getData();
    2558                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
    2559                        for (int i = 0; nextIndexes(it, indexes);) {
    2560                                float ox = 0;
    2561                                float oy = 0;
    2562                                for (int j = 0; j < m; j++) {
    2563                                        int l = indexes[j];
    2564                                        ox += c64data[l++] * coeff[j];
    2565                                        oy += c64data[l] * coeff[j];
    2566                                }
    2567                                oc64data[i++] = ox;
    2568                                oc64data[i++] = oy;
    2569                        }
    2570                        break;
    2571                case Dataset.COMPLEX128:
    2572                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
    2573                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
    2574                        for (int i = 0; nextIndexes(it, indexes);) {
    2575                                double ox = 0;
    2576                                double oy = 0;
    2577                                for (int j = 0; j < m; j++) {
    2578                                        int l = indexes[j];
    2579                                        ox += c128data[l++] * coeff[j];
    2580                                        oy += c128data[l] * coeff[j];
    2581                                }
    2582                                oc128data[i++] = ox;
    2583                                oc128data[i++] = oy;
    2584                        }
    2585                        break;
    2586                case Dataset.ARRAYFLOAT32:
    2587                        final float[] af32data = ((CompoundFloatDataset) a).getData();
    2588                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
    2589                        float[] fox = new float[isize];
    2590                        for (int i = 0; nextIndexes(it, indexes);) {
    2591                                Arrays.fill(fox, 0);
    2592                                for (int j = 0; j < m; j++) {
    2593                                        double c = coeff[j];
    2594                                        int l = indexes[j];
    2595                                        for (int k = 0; k < isize; k++) {
    2596                                                fox[k] += af32data[l++] * c;
    2597                                        }
    2598                                }
    2599                                for (int k = 0; k < isize; k++) {
    2600                                        oaf32data[i++] = fox[k];
    2601                                }
    2602                        }
    2603                        break;
    2604                case Dataset.ARRAYFLOAT64:
    2605                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
    2606                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
    2607                        double[] dox = new double[isize];
    2608                        for (int i = 0; nextIndexes(it, indexes);) {
    2609                                Arrays.fill(dox, 0);
    2610                                for (int j = 0; j < m; j++) {
    2611                                        double c = coeff[j];
    2612                                        int l = indexes[j];
    2613                                        for (int k = 0; k < isize; k++) {
    2614                                                dox[k] += af64data[l++] * c;
    2615                                        }
    2616                                }
    2617                                for (int k = 0; k < isize; k++) {
    2618                                        oaf64data[i++] = dox[k];
    2619                                }
    2620                        }
    2621                        break;
    2622                default:
    2623                        throw new UnsupportedOperationException("difference does not support multiple-element dataset");
    2624                }
    2625        }
    2626
    2627        /**
    2628         * Discrete difference of dataset along axis using finite difference
    2629         *
    2630         * @param a
    2631         * @param n
    2632         *            order of difference
    2633         * @param axis
    2634         * @return difference
    2635         */
    2636        public static Dataset difference(Dataset a, final int n, int axis) {
    2637                Dataset ds;
    2638                final Class<? extends Dataset> clazz = a.getClass();
    2639                final int rank = a.getRank();
    2640                final int is = a.getElementsPerItem();
    2641
    2642                if (axis < 0) {
    2643                        axis += rank;
    2644                }
    2645                if (axis < 0 || axis >= rank) {
    2646                        throw new IllegalArgumentException("Axis is out of range");
    2647                }
    2648
    2649                int[] nshape = a.getShape();
    2650                if (nshape[axis] <= n) {
    2651                        nshape[axis] = 0;
    2652                        return DatasetFactory.zeros(is, clazz, nshape);
    2653                }
    2654
    2655                nshape[axis] -= n;
    2656                ds = DatasetFactory.zeros(is, clazz, nshape);
    2657                if (rank == 1) {
    2658                        difference(DatasetUtils.convertToDataset(a), ds, n);
    2659                } else {
    2660                        final Dataset src = DatasetFactory.zeros(is, clazz, a.getShapeRef()[axis]);
    2661                        final Dataset dest = DatasetFactory.zeros(is, clazz, nshape[axis]);
    2662                        final PositionIterator pi = a.getPositionIterator(axis);
    2663                        final int[] pos = pi.getPos();
    2664                        final boolean[] hit = pi.getOmit();
    2665                        while (pi.hasNext()) {
    2666                                a.copyItemsFromAxes(pos, hit, src);
    2667                                difference(src, dest, n);
    2668                                ds.setItemsOnAxes(pos, hit, dest.getBuffer());
    2669                        }
    2670                }
    2671
    2672                return ds;
    2673        }
    2674
    2675        private static double SelectedMean(Dataset data, int Min, int Max) {
    2676
    2677                double result = 0.0;
    2678                for (int i = Min, imax = data.getSize(); i <= Max; i++) {
    2679                        // clip i appropriately, imagine that effectively the two ends
    2680                        // continue
    2681                        // straight out.
    2682                        int pos = i;
    2683                        if (pos < 0) {
    2684                                pos = 0;
    2685                        } else if (pos >= imax) {
    2686                                pos = imax - 1;
    2687                        }
    2688                        result += data.getElementDoubleAbs(pos);
    2689                }
    2690
    2691                // now the sum is complete, average the values.
    2692                result /= (Max - Min) + 1;
    2693                return result;
    2694        }
    2695
    2696        private static void SelectedMeanArray(double[] out, Dataset data, int Min, int Max) {
    2697                final int isize = out.length;
    2698                for (int j = 0; j < isize; j++)
    2699                        out[j] = 0.;
    2700
    2701                for (int i = Min, imax = data.getSize(); i <= Max; i++) {
    2702                        // clip i appropriately, imagine that effectively the two ends
    2703                        // continue
    2704                        // straight out.
    2705                        int pos = i * isize;
    2706                        if (pos < 0) {
    2707                                pos = 0;
    2708                        } else if (pos >= imax) {
    2709                                pos = imax - isize;
    2710                        }
    2711                        for (int j = 0; j < isize; j++)
    2712                                out[j] += data.getElementDoubleAbs(pos + j);
    2713                }
    2714
    2715                // now the sum is complete, average the values.
    2716                double norm = 1. / (Max - Min + 1.);
    2717                for (int j = 0; j < isize; j++)
    2718                        out[j] *= norm;
    2719
    2720        }
    2721
    2722        /**
    2723         * Calculates the derivative of a line described by two datasets (x,y) given
    2724         * a spread of n either side of the point
    2725         *
    2726         * @param x
    2727         *            The x values of the function to take the derivative of.
    2728         * @param y
    2729         *            The y values of the function to take the derivative of.
    2730         * @param n
    2731         *            The spread the derivative is calculated from, i.e. the
    2732         *            smoothing, the higher the value, the more smoothing occurs.
    2733         * @return A dataset which contains all the derivative point for point.
    2734         */
    2735        public static Dataset derivative(Dataset x, Dataset y, int n) {
    2736                if (x.getRank() != 1 || y.getRank() != 1) {
    2737                        throw new IllegalArgumentException("Only one dimensional dataset supported");
    2738                }
    2739                if (y.getSize() > x.getSize()) {
    2740                        throw new IllegalArgumentException("Length of x dataset should be greater than or equal to y's");
    2741                }
    2742                int dtype = y.getDType();
    2743                Dataset result;
    2744                switch (dtype) {
    2745                case Dataset.BOOL:
    2746                case Dataset.INT8:
    2747                case Dataset.INT16:
    2748                case Dataset.ARRAYINT8:
    2749                case Dataset.ARRAYINT16:
    2750                        result = DatasetFactory.zeros(y, FloatDataset.class);
    2751                        break;
    2752                case Dataset.INT32:
    2753                case Dataset.INT64:
    2754                case Dataset.ARRAYINT32:
    2755                case Dataset.ARRAYINT64:
    2756                        result = DatasetFactory.zeros(y, DoubleDataset.class);
    2757                        break;
    2758                case Dataset.FLOAT32:
    2759                case Dataset.FLOAT64:
    2760                case Dataset.COMPLEX64:
    2761                case Dataset.COMPLEX128:
    2762                case Dataset.ARRAYFLOAT32:
    2763                case Dataset.ARRAYFLOAT64:
    2764                        result = DatasetFactory.zeros(y);
    2765                        break;
    2766                default:
    2767                        throw new UnsupportedOperationException("derivative does not support multiple-element dataset");
    2768                }
    2769
    2770                final int isize = y.getElementsPerItem();
    2771                if (isize == 1) {
    2772                        for (int i = 0, imax = x.getSize(); i < imax; i++) {
    2773                                double LeftValue = SelectedMean(y, i - n, i - 1);
    2774                                double RightValue = SelectedMean(y, i + 1, i + n);
    2775                                double LeftPosition = SelectedMean(x, i - n, i - 1);
    2776                                double RightPosition = SelectedMean(x, i + 1, i + n);
    2777
    2778                                // now the values and positions are calculated, the derivative
    2779                                // can be
    2780                                // calculated.
    2781                                result.set(((RightValue - LeftValue) / (RightPosition - LeftPosition)), i);
    2782                        }
    2783                } else {
    2784                        double[] leftValues = new double[isize];
    2785                        double[] rightValues = new double[isize];
    2786                        for (int i = 0, imax = x.getSize(); i < imax; i++) {
    2787                                SelectedMeanArray(leftValues, y, i - n, i - 1);
    2788                                SelectedMeanArray(rightValues, y, i + 1, i + n);
    2789                                double delta = SelectedMean(x, i - n, i - 1);
    2790                                delta = 1. / (SelectedMean(x, i + 1, i + n) - delta);
    2791                                for (int j = 0; j < isize; j++) {
    2792                                        rightValues[j] -= leftValues[j];
    2793                                        rightValues[j] *= delta;
    2794                                }
    2795                                result.set(rightValues, i);
    2796                        }
    2797                }
    2798
    2799                // set the name based on the changes made
    2800                result.setName(y.getName() + "'");
    2801
    2802                return result;
    2803        }
    2804
    2805        /**
    2806         * Discrete difference of dataset along axis using finite central difference
    2807         *
    2808         * @param a
    2809         * @param axis
    2810         * @return difference
    2811         */
    2812        public static Dataset centralDifference(Dataset a, int axis) {
    2813                Dataset ds;
    2814                final Class<? extends Dataset> clazz = a.getClass();
    2815                final int rank = a.getRank();
    2816                final int is = a.getElementsPerItem();
    2817
    2818                if (axis < 0) {
    2819                        axis += rank;
    2820                }
    2821                if (axis < 0 || axis >= rank) {
    2822                        throw new IllegalArgumentException("Axis is out of range");
    2823                }
    2824
    2825                final int len = a.getShapeRef()[axis];
    2826                if (len < 2) {
    2827                        throw new IllegalArgumentException("Dataset should have a size > 1 along given axis");
    2828                }
    2829                ds = DatasetFactory.zeros(is, clazz, a.getShapeRef());
    2830                if (rank == 1) {
    2831                        centralDifference(a, ds);
    2832                } else {
    2833                        final Dataset src = DatasetFactory.zeros(is, clazz, len);
    2834                        final Dataset dest = DatasetFactory.zeros(is, clazz, len);
    2835                        final PositionIterator pi = a.getPositionIterator(axis);
    2836                        final int[] pos = pi.getPos();
    2837                        final boolean[] hit = pi.getOmit();
    2838                        while (pi.hasNext()) {
    2839                                a.copyItemsFromAxes(pos, hit, src);
    2840                                centralDifference(src, dest);
    2841                                ds.setItemsOnAxes(pos, hit, dest.getBuffer());
    2842                        }
    2843                }
    2844
    2845                return ds;
    2846        }
    2847
    2848        /**
    2849         * 1st order discrete difference of dataset along flattened dataset using
    2850         * central difference
    2851         *
    2852         * @param a
    2853         *            is 1d dataset
    2854         * @param out
    2855         *            is 1d dataset
    2856         */
    2857        private static void centralDifference(final Dataset a, final Dataset out) {
    2858                final int isize = a.getElementsPerItem();
    2859                final int dt = a.getDType();
    2860
    2861                final int nlen = (out.getShapeRef()[0] - 1) * isize;
    2862                if (nlen < 1) {
    2863                        throw new IllegalArgumentException("Dataset should have a size > 1 along given axis");
    2864                }
    2865                final IndexIterator it = a.getIterator();
    2866                if (!it.hasNext())
    2867                        return;
    2868                int oi = it.index;
    2869                if (!it.hasNext())
    2870                        return;
    2871                int pi = it.index;
    2872
    2873                switch (dt) {
    2874                case Dataset.INT8:
    2875                        final byte[] i8data = ((ByteDataset) a).getData();
    2876                        final byte[] oi8data = ((ByteDataset) out).getData();
    2877                        oi8data[0] = (byte) (i8data[pi] - i8data[oi]);
    2878                        for (int i = 1; it.hasNext(); i++) {
    2879                                oi8data[i] = (byte) ((i8data[it.index] - i8data[oi]) / 2);
    2880                                oi = pi;
    2881                                pi = it.index;
    2882                        }
    2883                        oi8data[nlen] = (byte) (i8data[pi] - i8data[oi]);
    2884                        break;
    2885                case Dataset.INT16:
    2886                        final short[] i16data = ((ShortDataset) a).getData();
    2887                        final short[] oi16data = ((ShortDataset) out).getData();
    2888                        oi16data[0] = (short) (i16data[pi] - i16data[oi]);
    2889                        for (int i = 1; it.hasNext(); i++) {
    2890                                oi16data[i] = (short) ((i16data[it.index] - i16data[oi]) / 2);
    2891                                oi = pi;
    2892                                pi = it.index;
    2893                        }
    2894                        oi16data[nlen] = (short) (i16data[pi] - i16data[oi]);
    2895                        break;
    2896                case Dataset.INT32:
    2897                        final int[] i32data = ((IntegerDataset) a).getData();
    2898                        final int[] oi32data = ((IntegerDataset) out).getData();
    2899                        oi32data[0] = i32data[pi] - i32data[oi];
    2900                        for (int i = 1; it.hasNext(); i++) {
    2901                                oi32data[i] = (i32data[it.index] - i32data[oi]) / 2;
    2902                                oi = pi;
    2903                                pi = it.index;
    2904                        }
    2905                        oi32data[nlen] = i32data[pi] - i32data[oi];
    2906                        break;
    2907                case Dataset.INT64:
    2908                        final long[] i64data = ((LongDataset) a).getData();
    2909                        final long[] oi64data = ((LongDataset) out).getData();
    2910                        oi64data[0] = i64data[pi] - i64data[oi];
    2911                        for (int i = 1; it.hasNext(); i++) {
    2912                                oi64data[i] = (i64data[it.index] - i64data[oi]) / 2;
    2913                                oi = pi;
    2914                                pi = it.index;
    2915                        }
    2916                        oi64data[nlen] = i64data[pi] - i64data[oi];
    2917                        break;
    2918                case Dataset.ARRAYINT8:
    2919                        final byte[] ai8data = ((CompoundByteDataset) a).getData();
    2920                        final byte[] oai8data = ((CompoundByteDataset) out).getData();
    2921                        for (int k = 0; k < isize; k++) {
    2922                                oai8data[k] = (byte) (ai8data[pi + k] - ai8data[oi + k]);
    2923                        }
    2924                        for (int i = isize; it.hasNext();) {
    2925                                int l = it.index;
    2926                                for (int k = 0; k < isize; k++) {
    2927                                        oai8data[i++] = (byte) ((ai8data[l++] - ai8data[oi++]) / 2);
    2928                                }
    2929                                oi = pi;
    2930                                pi = it.index;
    2931                        }
    2932                        for (int k = 0; k < isize; k++) {
    2933                                oai8data[nlen + k] = (byte) (ai8data[pi + k] - ai8data[oi + k]);
    2934                        }
    2935                        break;
    2936                case Dataset.ARRAYINT16:
    2937                        final short[] ai16data = ((CompoundShortDataset) a).getData();
    2938                        final short[] oai16data = ((CompoundShortDataset) out).getData();
    2939                        for (int k = 0; k < isize; k++) {
    2940                                oai16data[k] = (short) (ai16data[pi + k] - ai16data[oi + k]);
    2941                        }
    2942                        for (int i = isize; it.hasNext();) {
    2943                                int l = it.index;
    2944                                for (int k = 0; k < isize; k++) {
    2945                                        oai16data[i++] = (short) ((ai16data[l++] - ai16data[oi++]) / 2);
    2946                                }
    2947                                oi = pi;
    2948                                pi = it.index;
    2949                        }
    2950                        for (int k = 0; k < isize; k++) {
    2951                                oai16data[nlen + k] = (short) (ai16data[pi + k] - ai16data[oi + k]);
    2952                        }
    2953                        break;
    2954                case Dataset.ARRAYINT32:
    2955                        final int[] ai32data = ((CompoundIntegerDataset) a).getData();
    2956                        final int[] oai32data = ((CompoundIntegerDataset) out).getData();
    2957                        for (int k = 0; k < isize; k++) {
    2958                                oai32data[k] = ai32data[pi + k] - ai32data[oi + k];
    2959                        }
    2960                        for (int i = isize; it.hasNext();) {
    2961                                int l = it.index;
    2962                                for (int k = 0; k < isize; k++) {
    2963                                        oai32data[i++] = (ai32data[l++] - ai32data[oi++]) / 2;
    2964                                }
    2965                                oi = pi;
    2966                                pi = it.index;
    2967                        }
    2968                        for (int k = 0; k < isize; k++) {
    2969                                oai32data[nlen + k] = ai32data[pi + k] - ai32data[oi + k];
    2970                        }
    2971                        break;
    2972                case Dataset.ARRAYINT64:
    2973                        final long[] ai64data = ((CompoundLongDataset) a).getData();
    2974                        final long[] oai64data = ((CompoundLongDataset) out).getData();
    2975                        for (int k = 0; k < isize; k++) {
    2976                                oai64data[k] = ai64data[pi + k] - ai64data[oi + k];
    2977                        }
    2978                        for (int i = isize; it.hasNext();) {
    2979                                int l = it.index;
    2980                                for (int k = 0; k < isize; k++) {
    2981                                        oai64data[i++] = (ai64data[l++] - ai64data[oi++]) / 2;
    2982                                }
    2983                                oi = pi;
    2984                                pi = it.index;
    2985                        }
    2986                        for (int k = 0; k < isize; k++) {
    2987                                oai64data[nlen + k] = ai64data[pi + k] - ai64data[oi + k];
    2988                        }
    2989                        break;
    2990                case Dataset.FLOAT32:
    2991                        final float[] f32data = ((FloatDataset) a).getData();
    2992                        final float[] of32data = ((FloatDataset) out).getData();
    2993                        of32data[0] = f32data[pi] - f32data[oi];
    2994                        for (int i = 1; it.hasNext(); i++) {
    2995                                of32data[i] = (f32data[it.index] - f32data[oi]) * 0.5f;
    2996                                oi = pi;
    2997                                pi = it.index;
    2998                        }
    2999                        of32data[nlen] = f32data[pi] - f32data[oi];
    3000                        break;
    3001                case Dataset.FLOAT64:
    3002                        final double[] f64data = ((DoubleDataset) a).getData();
    3003                        final double[] of64data = ((DoubleDataset) out).getData();
    3004                        of64data[0] = f64data[pi] - f64data[oi];
    3005                        for (int i = 1; it.hasNext(); i++) {
    3006                                of64data[i] = (f64data[it.index] - f64data[oi]) * 0.5f;
    3007                                oi = pi;
    3008                                pi = it.index;
    3009                        }
    3010                        of64data[nlen] = f64data[pi] - f64data[oi];
    3011                        break;
    3012                case Dataset.COMPLEX64:
    3013                        final float[] c64data = ((ComplexFloatDataset) a).getData();
    3014                        final float[] oc64data = ((ComplexFloatDataset) out).getData();
    3015                        oc64data[0] = c64data[pi] - c64data[oi];
    3016                        oc64data[1] = c64data[pi + 1] - c64data[oi + 1];
    3017                        for (int i = 2; it.hasNext();) {
    3018                                oc64data[i++] = (c64data[it.index] - c64data[oi++]) * 0.5f;
    3019                                oc64data[i++] = (c64data[it.index + 1] - c64data[oi]) * 0.5f;
    3020                                oi = pi;
    3021                                pi = it.index;
    3022                        }
    3023                        oc64data[nlen] = c64data[pi] - c64data[oi];
    3024                        oc64data[nlen + 1] = c64data[pi + 1] - c64data[oi + 1];
    3025                        break;
    3026                case Dataset.COMPLEX128:
    3027                        final double[] c128data = ((ComplexDoubleDataset) a).getData();
    3028                        final double[] oc128data = ((ComplexDoubleDataset) out).getData();
    3029                        oc128data[0] = c128data[pi] - c128data[oi];
    3030                        oc128data[1] = c128data[pi + 1] - c128data[oi + 1];
    3031                        for (int i = 2; it.hasNext();) {
    3032                                oc128data[i++] = (c128data[it.index] - c128data[oi++]) * 0.5f;
    3033                                oc128data[i++] = (c128data[it.index + 1] - c128data[oi]) * 0.5f;
    3034                                oi = pi;
    3035                                pi = it.index;
    3036                        }
    3037                        oc128data[nlen] = c128data[pi] - c128data[oi];
    3038                        oc128data[nlen + 1] = c128data[pi + 1] - c128data[oi + 1];
    3039                        break;
    3040                case Dataset.ARRAYFLOAT32:
    3041                        final float[] af32data = ((CompoundFloatDataset) a).getData();
    3042                        final float[] oaf32data = ((CompoundFloatDataset) out).getData();
    3043                        for (int k = 0; k < isize; k++) {
    3044                                oaf32data[k] = af32data[pi + k] - af32data[oi + k];
    3045                        }
    3046                        for (int i = isize; it.hasNext();) {
    3047                                int l = it.index;
    3048                                for (int k = 0; k < isize; k++) {
    3049                                        oaf32data[i++] = (af32data[l++] - af32data[oi++]) * 0.5f;
    3050                                }
    3051                                oi = pi;
    3052                                pi = it.index;
    3053                        }
    3054                        for (int k = 0; k < isize; k++) {
    3055                                oaf32data[nlen + k] = af32data[pi + k] - af32data[oi + k];
    3056                        }
    3057                        break;
    3058                case Dataset.ARRAYFLOAT64:
    3059                        final double[] af64data = ((CompoundDoubleDataset) a).getData();
    3060                        final double[] oaf64data = ((CompoundDoubleDataset) out).getData();
    3061                        for (int k = 0; k < isize; k++) {
    3062                                oaf64data[k] = af64data[pi + k] - af64data[oi + k];
    3063                        }
    3064                        for (int i = isize; it.hasNext();) {
    3065                                int l = it.index;
    3066                                for (int k = 0; k < isize; k++) {
    3067                                        oaf64data[i++] = (af64data[l++] - af64data[oi++]) * 0.5;
    3068                                }
    3069                                oi = pi;
    3070                                pi = it.index;
    3071                        }
    3072                        for (int k = 0; k < isize; k++) {
    3073                                oaf64data[nlen + k] = af64data[pi + k] - af64data[oi + k];
    3074                        }
    3075                        break;
    3076                default:
    3077                        throw new UnsupportedOperationException("difference does not support this dataset type");
    3078                }
    3079        }
    3080
    3081        /**
    3082         * Calculate gradient (or partial derivatives) by central difference
    3083         *
    3084         * @param y
    3085         * @param x
    3086         *            one or more datasets for dependent variables
    3087         * @return a list of datasets (one for each dimension in y)
    3088         */
    3089        public static List<Dataset> gradient(Dataset y, Dataset... x) {
    3090                final int rank = y.getRank();
    3091
    3092                if (x.length > 0) {
    3093                        if (x.length != rank) {
    3094                                throw new IllegalArgumentException(
    3095                                                "Number of dependent datasets must be equal to rank of first argument");
    3096                        }
    3097                        for (int a = 0; a < rank; a++) {
    3098                                int rx = x[a].getRank();
    3099                                if (rx != rank && rx != 1) {
    3100                                        throw new IllegalArgumentException(
    3101                                                        "Dependent datasets must be 1-D or match rank of first argument");
    3102                                }
    3103                                if (rx == 1) {
    3104                                        if (y.getShapeRef()[a] != x[a].getShapeRef()[0]) {
    3105                                                throw new IllegalArgumentException("Length of dependent dataset must match axis length");
    3106                                        }
    3107                                } else {
    3108                                        y.checkCompatibility(x[a]);
    3109                                }
    3110                        }
    3111                }
    3112
    3113                List<Dataset> grad = new ArrayList<Dataset>(rank);
    3114
    3115                for (int a = 0; a < rank; a++) {
    3116                        Dataset g = centralDifference(y, a);
    3117                        grad.add(g);
    3118                }
    3119
    3120                if (x.length > 0) {
    3121                        for (int a = 0; a < rank; a++) {
    3122                                Dataset g = grad.get(a);
    3123                                Dataset dx = x[a];
    3124                                int r = dx.getRank();
    3125                                if (r == rank) {
    3126                                        g.idivide(centralDifference(dx, a));
    3127                                } else {
    3128                                        final int is = dx.getElementsPerItem();
    3129                                        final Dataset bdx = DatasetFactory.zeros(is, dx.getClass(), y.getShapeRef());
    3130                                        final PositionIterator pi = y.getPositionIterator(a);
    3131                                        final int[] pos = pi.getPos();
    3132                                        final boolean[] hit = pi.getOmit();
    3133                                        dx = centralDifference(dx, 0);
    3134
    3135                                        while (pi.hasNext()) {
    3136                                                bdx.setItemsOnAxes(pos, hit, dx.getBuffer());
    3137                                        }
    3138                                        g.idivide(bdx);
    3139                                }
    3140                        }
    3141                }
    3142                return grad;
    3143        }
    3144
    3145        protected static void addFunctionName(final Dataset a, final Dataset b, final Dataset dataset, final String fname) {
    3146                dataset.setName(Operations.createFunctionName(fname, a.getName(), b.getName()));
    3147        }
    3148
    3149        protected static void addFunctionName(final Dataset dataset, final String fname) {
    3150                dataset.setName(Operations.createFunctionName(fname, dataset.getName()));
    3151        }
    3152
    3153        protected static void addBinaryOperatorName(final Dataset a, final Dataset b, final Dataset dataset, final String oname) {
    3154                dataset.setName(Operations.createBinaryOperationName(oname, a.getName(), b.getName()));
    3155        }
    3156
    3157        protected static final long toLong(double d) {
    3158                if (Double.isInfinite(d) || Double.isNaN(d))
    3159                        return 0l;
    3160                return (long) d;
    3161        }
    3162
    3163// Start of generated code
    3164        /**
    3165         * add operator
    3166         * @param a
    3167         * @param b
    3168         * @return {@code a + b}, addition of a and b
    3169         */
    3170        public static Dataset add(final Object a, final Object b) {
    3171                return add(a, b, null);
    3172        }
    3173
    3174        /**
    3175         * add operator
    3176         * @param a
    3177         * @param b
    3178         * @param o output can be null - in which case, a new dataset is created
    3179         * @return {@code a + b}, addition of a and b
    3180         */
    3181        public static Dataset add(final Object a, final Object b, final Dataset o) {
    3182                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    3183                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    3184                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    3185                final Dataset result = it.getOutput();
    3186                final int is = result.getElementsPerItem();
    3187                final int as = da.getElementsPerItem();
    3188                final int bs = db.getElementsPerItem();
    3189                final int dt = result.getDType();
    3190
    3191                switch(dt) {
    3192                case Dataset.INT8:
    3193                        final byte[] oi8data = ((ByteDataset) result).getData();
    3194                        if (it.isOutputDouble()) {
    3195                                while (it.hasNext()) {
    3196                                        final double iax = it.aDouble;
    3197                                        final double ibx = it.bDouble;
    3198                                        byte ox;
    3199                                        ox = (byte) toLong(iax + ibx);
    3200                                        oi8data[it.oIndex] = ox;
    3201                                }
    3202                        } else {
    3203                                while (it.hasNext()) {
    3204                                        final long iax = it.aLong;
    3205                                        final long ibx = it.bLong;
    3206                                        byte ox;
    3207                                        ox = (byte) (iax + ibx);
    3208                                        oi8data[it.oIndex] = ox;
    3209                                }
    3210                        }
    3211                        break;
    3212                case Dataset.INT16:
    3213                        final short[] oi16data = ((ShortDataset) result).getData();
    3214                        if (it.isOutputDouble()) {
    3215                                while (it.hasNext()) {
    3216                                        final double iax = it.aDouble;
    3217                                        final double ibx = it.bDouble;
    3218                                        short ox;
    3219                                        ox = (short) toLong(iax + ibx);
    3220                                        oi16data[it.oIndex] = ox;
    3221                                }
    3222                        } else {
    3223                                while (it.hasNext()) {
    3224                                        final long iax = it.aLong;
    3225                                        final long ibx = it.bLong;
    3226                                        short ox;
    3227                                        ox = (short) (iax + ibx);
    3228                                        oi16data[it.oIndex] = ox;
    3229                                }
    3230                        }
    3231                        break;
    3232                case Dataset.INT64:
    3233                        final long[] oi64data = ((LongDataset) result).getData();
    3234                        if (it.isOutputDouble()) {
    3235                                while (it.hasNext()) {
    3236                                        final double iax = it.aDouble;
    3237                                        final double ibx = it.bDouble;
    3238                                        long ox;
    3239                                        ox = toLong(iax + ibx);
    3240                                        oi64data[it.oIndex] = ox;
    3241                                }
    3242                        } else {
    3243                                while (it.hasNext()) {
    3244                                        final long iax = it.aLong;
    3245                                        final long ibx = it.bLong;
    3246                                        long ox;
    3247                                        ox = (iax + ibx);
    3248                                        oi64data[it.oIndex] = ox;
    3249                                }
    3250                        }
    3251                        break;
    3252                case Dataset.INT32:
    3253                        final int[] oi32data = ((IntegerDataset) result).getData();
    3254                        if (it.isOutputDouble()) {
    3255                                while (it.hasNext()) {
    3256                                        final double iax = it.aDouble;
    3257                                        final double ibx = it.bDouble;
    3258                                        int ox;
    3259                                        ox = (int) toLong(iax + ibx);
    3260                                        oi32data[it.oIndex] = ox;
    3261                                }
    3262                        } else {
    3263                                while (it.hasNext()) {
    3264                                        final long iax = it.aLong;
    3265                                        final long ibx = it.bLong;
    3266                                        int ox;
    3267                                        ox = (int) (iax + ibx);
    3268                                        oi32data[it.oIndex] = ox;
    3269                                }
    3270                        }
    3271                        break;
    3272                case Dataset.ARRAYINT8:
    3273                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    3274                        if (is == 1) {
    3275                                if (it.isOutputDouble()) {
    3276                                        while (it.hasNext()) {
    3277                                                final double iax = it.aDouble;
    3278                                                final double ibx = it.bDouble;
    3279                                                byte ox;
    3280                                                ox = (byte) toLong(iax + ibx);
    3281                                                oai8data[it.oIndex] = ox;
    3282                                        }
    3283                                } else {
    3284                                        while (it.hasNext()) {
    3285                                                final long iax = it.aLong;
    3286                                                final long ibx = it.bLong;
    3287                                                byte ox;
    3288                                                ox = (byte) (iax + ibx);
    3289                                                oai8data[it.oIndex] = ox;
    3290                                        }
    3291                                }
    3292                        } else if (as < bs) {
    3293                                if (it.isOutputDouble()) {
    3294                                        while (it.hasNext()) {
    3295                                                final double iax = it.aDouble;
    3296                                                double ibx = it.bDouble;
    3297                                                byte ox;
    3298                                                ox = (byte) toLong(iax + ibx);
    3299                                                oai8data[it.oIndex] = ox;
    3300                                                for (int j = 1; j < is; j++) {
    3301                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3302                                                        ox = (byte) toLong(iax + ibx);
    3303                                                        oai8data[it.oIndex + j] = ox;
    3304                                                }
    3305                                        }
    3306                                } else {
    3307                                        while (it.hasNext()) {
    3308                                                final long iax = it.aLong;
    3309                                                long ibx = it.bLong;
    3310                                                byte ox;
    3311                                                ox = (byte) (iax + ibx);
    3312                                                oai8data[it.oIndex] = ox;
    3313                                                for (int j = 1; j < is; j++) {
    3314                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3315                                                        ox = (byte) (iax + ibx);
    3316                                                        oai8data[it.oIndex + j] = ox;
    3317                                                }
    3318                                        }
    3319                                }
    3320                        } else if (as > bs) {
    3321                                if (it.isOutputDouble()) {
    3322                                        while (it.hasNext()) {
    3323                                                double iax = it.aDouble;
    3324                                                final double ibx = it.bDouble;
    3325                                                byte ox;
    3326                                                ox = (byte) toLong(iax + ibx);
    3327                                                oai8data[it.oIndex] = ox;
    3328                                                for (int j = 1; j < is; j++) {
    3329                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3330                                                        ox = (byte) toLong(iax + ibx);
    3331                                                        oai8data[it.oIndex + j] = ox;
    3332                                                }
    3333                                        }
    3334                                } else {
    3335                                        while (it.hasNext()) {
    3336                                                long iax = it.aLong;
    3337                                                final long ibx = it.bLong;
    3338                                                byte ox;
    3339                                                ox = (byte) (iax + ibx);
    3340                                                oai8data[it.oIndex] = ox;
    3341                                                for (int j = 1; j < is; j++) {
    3342                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3343                                                        ox = (byte) (iax + ibx);
    3344                                                        oai8data[it.oIndex + j] = ox;
    3345                                                }
    3346                                        }
    3347                                }
    3348                        } else if (as == 1) {
    3349                                if (it.isOutputDouble()) {
    3350                                        while (it.hasNext()) {
    3351                                                final double iax = it.aDouble;
    3352                                                final double ibx = it.bDouble;
    3353                                                byte ox;
    3354                                                ox = (byte) toLong(iax + ibx);
    3355                                                for (int j = 0; j < is; j++) {
    3356                                                        oai8data[it.oIndex + j] = ox;
    3357                                                }
    3358                                        }
    3359                                } else {
    3360                                        while (it.hasNext()) {
    3361                                                final long iax = it.aLong;
    3362                                                final long ibx = it.bLong;
    3363                                                byte ox;
    3364                                                ox = (byte) (iax + ibx);
    3365                                                for (int j = 0; j < is; j++) {
    3366                                                        oai8data[it.oIndex + j] = ox;
    3367                                                }
    3368                                        }
    3369                                }
    3370                        } else {
    3371                                if (it.isOutputDouble()) {
    3372                                        while (it.hasNext()) {
    3373                                                double iax = it.aDouble;
    3374                                                double ibx = it.bDouble;
    3375                                                byte ox;
    3376                                                ox = (byte) toLong(iax + ibx);
    3377                                                oai8data[it.oIndex] = ox;
    3378                                                for (int j = 1; j < is; j++) {
    3379                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3380                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3381                                                        ox = (byte) toLong(iax + ibx);
    3382                                                        oai8data[it.oIndex + j] = ox;
    3383                                                }
    3384                                        }
    3385                                } else {
    3386                                        while (it.hasNext()) {
    3387                                                long iax = it.aLong;
    3388                                                long ibx = it.bLong;
    3389                                                byte ox;
    3390                                                ox = (byte) (iax + ibx);
    3391                                                oai8data[it.oIndex] = ox;
    3392                                                for (int j = 1; j < is; j++) {
    3393                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3394                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3395                                                        ox = (byte) (iax + ibx);
    3396                                                        oai8data[it.oIndex + j] = ox;
    3397                                                }
    3398                                        }
    3399                                }
    3400                        }
    3401                        break;
    3402                case Dataset.ARRAYINT16:
    3403                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    3404                        if (is == 1) {
    3405                                if (it.isOutputDouble()) {
    3406                                        while (it.hasNext()) {
    3407                                                final double iax = it.aDouble;
    3408                                                final double ibx = it.bDouble;
    3409                                                short ox;
    3410                                                ox = (short) toLong(iax + ibx);
    3411                                                oai16data[it.oIndex] = ox;
    3412                                        }
    3413                                } else {
    3414                                        while (it.hasNext()) {
    3415                                                final long iax = it.aLong;
    3416                                                final long ibx = it.bLong;
    3417                                                short ox;
    3418                                                ox = (short) (iax + ibx);
    3419                                                oai16data[it.oIndex] = ox;
    3420                                        }
    3421                                }
    3422                        } else if (as < bs) {
    3423                                if (it.isOutputDouble()) {
    3424                                        while (it.hasNext()) {
    3425                                                final double iax = it.aDouble;
    3426                                                double ibx = it.bDouble;
    3427                                                short ox;
    3428                                                ox = (short) toLong(iax + ibx);
    3429                                                oai16data[it.oIndex] = ox;
    3430                                                for (int j = 1; j < is; j++) {
    3431                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3432                                                        ox = (short) toLong(iax + ibx);
    3433                                                        oai16data[it.oIndex + j] = ox;
    3434                                                }
    3435                                        }
    3436                                } else {
    3437                                        while (it.hasNext()) {
    3438                                                final long iax = it.aLong;
    3439                                                long ibx = it.bLong;
    3440                                                short ox;
    3441                                                ox = (short) (iax + ibx);
    3442                                                oai16data[it.oIndex] = ox;
    3443                                                for (int j = 1; j < is; j++) {
    3444                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3445                                                        ox = (short) (iax + ibx);
    3446                                                        oai16data[it.oIndex + j] = ox;
    3447                                                }
    3448                                        }
    3449                                }
    3450                        } else if (as > bs) {
    3451                                if (it.isOutputDouble()) {
    3452                                        while (it.hasNext()) {
    3453                                                double iax = it.aDouble;
    3454                                                final double ibx = it.bDouble;
    3455                                                short ox;
    3456                                                ox = (short) toLong(iax + ibx);
    3457                                                oai16data[it.oIndex] = ox;
    3458                                                for (int j = 1; j < is; j++) {
    3459                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3460                                                        ox = (short) toLong(iax + ibx);
    3461                                                        oai16data[it.oIndex + j] = ox;
    3462                                                }
    3463                                        }
    3464                                } else {
    3465                                        while (it.hasNext()) {
    3466                                                long iax = it.aLong;
    3467                                                final long ibx = it.bLong;
    3468                                                short ox;
    3469                                                ox = (short) (iax + ibx);
    3470                                                oai16data[it.oIndex] = ox;
    3471                                                for (int j = 1; j < is; j++) {
    3472                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3473                                                        ox = (short) (iax + ibx);
    3474                                                        oai16data[it.oIndex + j] = ox;
    3475                                                }
    3476                                        }
    3477                                }
    3478                        } else if (as == 1) {
    3479                                if (it.isOutputDouble()) {
    3480                                        while (it.hasNext()) {
    3481                                                final double iax = it.aDouble;
    3482                                                final double ibx = it.bDouble;
    3483                                                short ox;
    3484                                                ox = (short) toLong(iax + ibx);
    3485                                                for (int j = 0; j < is; j++) {
    3486                                                        oai16data[it.oIndex + j] = ox;
    3487                                                }
    3488                                        }
    3489                                } else {
    3490                                        while (it.hasNext()) {
    3491                                                final long iax = it.aLong;
    3492                                                final long ibx = it.bLong;
    3493                                                short ox;
    3494                                                ox = (short) (iax + ibx);
    3495                                                for (int j = 0; j < is; j++) {
    3496                                                        oai16data[it.oIndex + j] = ox;
    3497                                                }
    3498                                        }
    3499                                }
    3500                        } else {
    3501                                if (it.isOutputDouble()) {
    3502                                        while (it.hasNext()) {
    3503                                                double iax = it.aDouble;
    3504                                                double ibx = it.bDouble;
    3505                                                short ox;
    3506                                                ox = (short) toLong(iax + ibx);
    3507                                                oai16data[it.oIndex] = ox;
    3508                                                for (int j = 1; j < is; j++) {
    3509                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3510                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3511                                                        ox = (short) toLong(iax + ibx);
    3512                                                        oai16data[it.oIndex + j] = ox;
    3513                                                }
    3514                                        }
    3515                                } else {
    3516                                        while (it.hasNext()) {
    3517                                                long iax = it.aLong;
    3518                                                long ibx = it.bLong;
    3519                                                short ox;
    3520                                                ox = (short) (iax + ibx);
    3521                                                oai16data[it.oIndex] = ox;
    3522                                                for (int j = 1; j < is; j++) {
    3523                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3524                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3525                                                        ox = (short) (iax + ibx);
    3526                                                        oai16data[it.oIndex + j] = ox;
    3527                                                }
    3528                                        }
    3529                                }
    3530                        }
    3531                        break;
    3532                case Dataset.ARRAYINT64:
    3533                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    3534                        if (is == 1) {
    3535                                if (it.isOutputDouble()) {
    3536                                        while (it.hasNext()) {
    3537                                                final double iax = it.aDouble;
    3538                                                final double ibx = it.bDouble;
    3539                                                long ox;
    3540                                                ox = toLong(iax + ibx);
    3541                                                oai64data[it.oIndex] = ox;
    3542                                        }
    3543                                } else {
    3544                                        while (it.hasNext()) {
    3545                                                final long iax = it.aLong;
    3546                                                final long ibx = it.bLong;
    3547                                                long ox;
    3548                                                ox = (iax + ibx);
    3549                                                oai64data[it.oIndex] = ox;
    3550                                        }
    3551                                }
    3552                        } else if (as < bs) {
    3553                                if (it.isOutputDouble()) {
    3554                                        while (it.hasNext()) {
    3555                                                final double iax = it.aDouble;
    3556                                                double ibx = it.bDouble;
    3557                                                long ox;
    3558                                                ox = toLong(iax + ibx);
    3559                                                oai64data[it.oIndex] = ox;
    3560                                                for (int j = 1; j < is; j++) {
    3561                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3562                                                        ox = toLong(iax + ibx);
    3563                                                        oai64data[it.oIndex + j] = ox;
    3564                                                }
    3565                                        }
    3566                                } else {
    3567                                        while (it.hasNext()) {
    3568                                                final long iax = it.aLong;
    3569                                                long ibx = it.bLong;
    3570                                                long ox;
    3571                                                ox = (iax + ibx);
    3572                                                oai64data[it.oIndex] = ox;
    3573                                                for (int j = 1; j < is; j++) {
    3574                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3575                                                        ox = (iax + ibx);
    3576                                                        oai64data[it.oIndex + j] = ox;
    3577                                                }
    3578                                        }
    3579                                }
    3580                        } else if (as > bs) {
    3581                                if (it.isOutputDouble()) {
    3582                                        while (it.hasNext()) {
    3583                                                double iax = it.aDouble;
    3584                                                final double ibx = it.bDouble;
    3585                                                long ox;
    3586                                                ox = toLong(iax + ibx);
    3587                                                oai64data[it.oIndex] = ox;
    3588                                                for (int j = 1; j < is; j++) {
    3589                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3590                                                        ox = toLong(iax + ibx);
    3591                                                        oai64data[it.oIndex + j] = ox;
    3592                                                }
    3593                                        }
    3594                                } else {
    3595                                        while (it.hasNext()) {
    3596                                                long iax = it.aLong;
    3597                                                final long ibx = it.bLong;
    3598                                                long ox;
    3599                                                ox = (iax + ibx);
    3600                                                oai64data[it.oIndex] = ox;
    3601                                                for (int j = 1; j < is; j++) {
    3602                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3603                                                        ox = (iax + ibx);
    3604                                                        oai64data[it.oIndex + j] = ox;
    3605                                                }
    3606                                        }
    3607                                }
    3608                        } else if (as == 1) {
    3609                                if (it.isOutputDouble()) {
    3610                                        while (it.hasNext()) {
    3611                                                final double iax = it.aDouble;
    3612                                                final double ibx = it.bDouble;
    3613                                                long ox;
    3614                                                ox = toLong(iax + ibx);
    3615                                                for (int j = 0; j < is; j++) {
    3616                                                        oai64data[it.oIndex + j] = ox;
    3617                                                }
    3618                                        }
    3619                                } else {
    3620                                        while (it.hasNext()) {
    3621                                                final long iax = it.aLong;
    3622                                                final long ibx = it.bLong;
    3623                                                long ox;
    3624                                                ox = (iax + ibx);
    3625                                                for (int j = 0; j < is; j++) {
    3626                                                        oai64data[it.oIndex + j] = ox;
    3627                                                }
    3628                                        }
    3629                                }
    3630                        } else {
    3631                                if (it.isOutputDouble()) {
    3632                                        while (it.hasNext()) {
    3633                                                double iax = it.aDouble;
    3634                                                double ibx = it.bDouble;
    3635                                                long ox;
    3636                                                ox = toLong(iax + ibx);
    3637                                                oai64data[it.oIndex] = ox;
    3638                                                for (int j = 1; j < is; j++) {
    3639                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3640                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3641                                                        ox = toLong(iax + ibx);
    3642                                                        oai64data[it.oIndex + j] = ox;
    3643                                                }
    3644                                        }
    3645                                } else {
    3646                                        while (it.hasNext()) {
    3647                                                long iax = it.aLong;
    3648                                                long ibx = it.bLong;
    3649                                                long ox;
    3650                                                ox = (iax + ibx);
    3651                                                oai64data[it.oIndex] = ox;
    3652                                                for (int j = 1; j < is; j++) {
    3653                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3654                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3655                                                        ox = (iax + ibx);
    3656                                                        oai64data[it.oIndex + j] = ox;
    3657                                                }
    3658                                        }
    3659                                }
    3660                        }
    3661                        break;
    3662                case Dataset.ARRAYINT32:
    3663                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    3664                        if (is == 1) {
    3665                                if (it.isOutputDouble()) {
    3666                                        while (it.hasNext()) {
    3667                                                final double iax = it.aDouble;
    3668                                                final double ibx = it.bDouble;
    3669                                                int ox;
    3670                                                ox = (int) toLong(iax + ibx);
    3671                                                oai32data[it.oIndex] = ox;
    3672                                        }
    3673                                } else {
    3674                                        while (it.hasNext()) {
    3675                                                final long iax = it.aLong;
    3676                                                final long ibx = it.bLong;
    3677                                                int ox;
    3678                                                ox = (int) (iax + ibx);
    3679                                                oai32data[it.oIndex] = ox;
    3680                                        }
    3681                                }
    3682                        } else if (as < bs) {
    3683                                if (it.isOutputDouble()) {
    3684                                        while (it.hasNext()) {
    3685                                                final double iax = it.aDouble;
    3686                                                double ibx = it.bDouble;
    3687                                                int ox;
    3688                                                ox = (int) toLong(iax + ibx);
    3689                                                oai32data[it.oIndex] = ox;
    3690                                                for (int j = 1; j < is; j++) {
    3691                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3692                                                        ox = (int) toLong(iax + ibx);
    3693                                                        oai32data[it.oIndex + j] = ox;
    3694                                                }
    3695                                        }
    3696                                } else {
    3697                                        while (it.hasNext()) {
    3698                                                final long iax = it.aLong;
    3699                                                long ibx = it.bLong;
    3700                                                int ox;
    3701                                                ox = (int) (iax + ibx);
    3702                                                oai32data[it.oIndex] = ox;
    3703                                                for (int j = 1; j < is; j++) {
    3704                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3705                                                        ox = (int) (iax + ibx);
    3706                                                        oai32data[it.oIndex + j] = ox;
    3707                                                }
    3708                                        }
    3709                                }
    3710                        } else if (as > bs) {
    3711                                if (it.isOutputDouble()) {
    3712                                        while (it.hasNext()) {
    3713                                                double iax = it.aDouble;
    3714                                                final double ibx = it.bDouble;
    3715                                                int ox;
    3716                                                ox = (int) toLong(iax + ibx);
    3717                                                oai32data[it.oIndex] = ox;
    3718                                                for (int j = 1; j < is; j++) {
    3719                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3720                                                        ox = (int) toLong(iax + ibx);
    3721                                                        oai32data[it.oIndex + j] = ox;
    3722                                                }
    3723                                        }
    3724                                } else {
    3725                                        while (it.hasNext()) {
    3726                                                long iax = it.aLong;
    3727                                                final long ibx = it.bLong;
    3728                                                int ox;
    3729                                                ox = (int) (iax + ibx);
    3730                                                oai32data[it.oIndex] = ox;
    3731                                                for (int j = 1; j < is; j++) {
    3732                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3733                                                        ox = (int) (iax + ibx);
    3734                                                        oai32data[it.oIndex + j] = ox;
    3735                                                }
    3736                                        }
    3737                                }
    3738                        } else if (as == 1) {
    3739                                if (it.isOutputDouble()) {
    3740                                        while (it.hasNext()) {
    3741                                                final double iax = it.aDouble;
    3742                                                final double ibx = it.bDouble;
    3743                                                int ox;
    3744                                                ox = (int) toLong(iax + ibx);
    3745                                                for (int j = 0; j < is; j++) {
    3746                                                        oai32data[it.oIndex + j] = ox;
    3747                                                }
    3748                                        }
    3749                                } else {
    3750                                        while (it.hasNext()) {
    3751                                                final long iax = it.aLong;
    3752                                                final long ibx = it.bLong;
    3753                                                int ox;
    3754                                                ox = (int) (iax + ibx);
    3755                                                for (int j = 0; j < is; j++) {
    3756                                                        oai32data[it.oIndex + j] = ox;
    3757                                                }
    3758                                        }
    3759                                }
    3760                        } else {
    3761                                if (it.isOutputDouble()) {
    3762                                        while (it.hasNext()) {
    3763                                                double iax = it.aDouble;
    3764                                                double ibx = it.bDouble;
    3765                                                int ox;
    3766                                                ox = (int) toLong(iax + ibx);
    3767                                                oai32data[it.oIndex] = ox;
    3768                                                for (int j = 1; j < is; j++) {
    3769                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3770                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3771                                                        ox = (int) toLong(iax + ibx);
    3772                                                        oai32data[it.oIndex + j] = ox;
    3773                                                }
    3774                                        }
    3775                                } else {
    3776                                        while (it.hasNext()) {
    3777                                                long iax = it.aLong;
    3778                                                long ibx = it.bLong;
    3779                                                int ox;
    3780                                                ox = (int) (iax + ibx);
    3781                                                oai32data[it.oIndex] = ox;
    3782                                                for (int j = 1; j < is; j++) {
    3783                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3784                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3785                                                        ox = (int) (iax + ibx);
    3786                                                        oai32data[it.oIndex + j] = ox;
    3787                                                }
    3788                                        }
    3789                                }
    3790                        }
    3791                        break;
    3792                case Dataset.FLOAT32:
    3793                        final float[] of32data = ((FloatDataset) result).getData();
    3794                        if (it.isOutputDouble()) {
    3795                                while (it.hasNext()) {
    3796                                        final double iax = it.aDouble;
    3797                                        final double ibx = it.bDouble;
    3798                                        float ox;
    3799                                        ox = (float) (iax + ibx);
    3800                                        of32data[it.oIndex] = ox;
    3801                                }
    3802                        } else {
    3803                                while (it.hasNext()) {
    3804                                        final long iax = it.aLong;
    3805                                        final long ibx = it.bLong;
    3806                                        float ox;
    3807                                        ox = (iax + ibx);
    3808                                        of32data[it.oIndex] = ox;
    3809                                }
    3810                        }
    3811                        break;
    3812                case Dataset.FLOAT64:
    3813                        final double[] of64data = ((DoubleDataset) result).getData();
    3814                        if (it.isOutputDouble()) {
    3815                                while (it.hasNext()) {
    3816                                        final double iax = it.aDouble;
    3817                                        final double ibx = it.bDouble;
    3818                                        double ox;
    3819                                        ox = (iax + ibx);
    3820                                        of64data[it.oIndex] = ox;
    3821                                }
    3822                        } else {
    3823                                while (it.hasNext()) {
    3824                                        final long iax = it.aLong;
    3825                                        final long ibx = it.bLong;
    3826                                        double ox;
    3827                                        ox = (iax + ibx);
    3828                                        of64data[it.oIndex] = ox;
    3829                                }
    3830                        }
    3831                        break;
    3832                case Dataset.ARRAYFLOAT32:
    3833                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    3834                        if (is == 1) {
    3835                                if (it.isOutputDouble()) {
    3836                                        while (it.hasNext()) {
    3837                                                final double iax = it.aDouble;
    3838                                                final double ibx = it.bDouble;
    3839                                                float ox;
    3840                                                ox = (float) (iax + ibx);
    3841                                                oaf32data[it.oIndex] = ox;
    3842                                        }
    3843                                } else {
    3844                                        while (it.hasNext()) {
    3845                                                final long iax = it.aLong;
    3846                                                final long ibx = it.bLong;
    3847                                                float ox;
    3848                                                ox = (iax + ibx);
    3849                                                oaf32data[it.oIndex] = ox;
    3850                                        }
    3851                                }
    3852                        } else if (as < bs) {
    3853                                if (it.isOutputDouble()) {
    3854                                        while (it.hasNext()) {
    3855                                                final double iax = it.aDouble;
    3856                                                double ibx = it.bDouble;
    3857                                                float ox;
    3858                                                ox = (float) (iax + ibx);
    3859                                                oaf32data[it.oIndex] = ox;
    3860                                                for (int j = 1; j < is; j++) {
    3861                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3862                                                        ox = (float) (iax + ibx);
    3863                                                        oaf32data[it.oIndex + j] = ox;
    3864                                                }
    3865                                        }
    3866                                } else {
    3867                                        while (it.hasNext()) {
    3868                                                final long iax = it.aLong;
    3869                                                long ibx = it.bLong;
    3870                                                float ox;
    3871                                                ox = (iax + ibx);
    3872                                                oaf32data[it.oIndex] = ox;
    3873                                                for (int j = 1; j < is; j++) {
    3874                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3875                                                        ox = (iax + ibx);
    3876                                                        oaf32data[it.oIndex + j] = ox;
    3877                                                }
    3878                                        }
    3879                                }
    3880                        } else if (as > bs) {
    3881                                if (it.isOutputDouble()) {
    3882                                        while (it.hasNext()) {
    3883                                                double iax = it.aDouble;
    3884                                                final double ibx = it.bDouble;
    3885                                                float ox;
    3886                                                ox = (float) (iax + ibx);
    3887                                                oaf32data[it.oIndex] = ox;
    3888                                                for (int j = 1; j < is; j++) {
    3889                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3890                                                        ox = (float) (iax + ibx);
    3891                                                        oaf32data[it.oIndex + j] = ox;
    3892                                                }
    3893                                        }
    3894                                } else {
    3895                                        while (it.hasNext()) {
    3896                                                long iax = it.aLong;
    3897                                                final long ibx = it.bLong;
    3898                                                float ox;
    3899                                                ox = (iax + ibx);
    3900                                                oaf32data[it.oIndex] = ox;
    3901                                                for (int j = 1; j < is; j++) {
    3902                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3903                                                        ox = (iax + ibx);
    3904                                                        oaf32data[it.oIndex + j] = ox;
    3905                                                }
    3906                                        }
    3907                                }
    3908                        } else if (as == 1) {
    3909                                if (it.isOutputDouble()) {
    3910                                        while (it.hasNext()) {
    3911                                                final double iax = it.aDouble;
    3912                                                final double ibx = it.bDouble;
    3913                                                float ox;
    3914                                                ox = (float) (iax + ibx);
    3915                                                for (int j = 0; j < is; j++) {
    3916                                                        oaf32data[it.oIndex + j] = ox;
    3917                                                }
    3918                                        }
    3919                                } else {
    3920                                        while (it.hasNext()) {
    3921                                                final long iax = it.aLong;
    3922                                                final long ibx = it.bLong;
    3923                                                float ox;
    3924                                                ox = (iax + ibx);
    3925                                                for (int j = 0; j < is; j++) {
    3926                                                        oaf32data[it.oIndex + j] = ox;
    3927                                                }
    3928                                        }
    3929                                }
    3930                        } else {
    3931                                if (it.isOutputDouble()) {
    3932                                        while (it.hasNext()) {
    3933                                                double iax = it.aDouble;
    3934                                                double ibx = it.bDouble;
    3935                                                float ox;
    3936                                                ox = (float) (iax + ibx);
    3937                                                oaf32data[it.oIndex] = ox;
    3938                                                for (int j = 1; j < is; j++) {
    3939                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    3940                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3941                                                        ox = (float) (iax + ibx);
    3942                                                        oaf32data[it.oIndex + j] = ox;
    3943                                                }
    3944                                        }
    3945                                } else {
    3946                                        while (it.hasNext()) {
    3947                                                long iax = it.aLong;
    3948                                                long ibx = it.bLong;
    3949                                                float ox;
    3950                                                ox = (iax + ibx);
    3951                                                oaf32data[it.oIndex] = ox;
    3952                                                for (int j = 1; j < is; j++) {
    3953                                                        iax = da.getElementLongAbs(it.aIndex + j);
    3954                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    3955                                                        ox = (iax + ibx);
    3956                                                        oaf32data[it.oIndex + j] = ox;
    3957                                                }
    3958                                        }
    3959                                }
    3960                        }
    3961                        break;
    3962                case Dataset.ARRAYFLOAT64:
    3963                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    3964                        if (is == 1) {
    3965                                if (it.isOutputDouble()) {
    3966                                        while (it.hasNext()) {
    3967                                                final double iax = it.aDouble;
    3968                                                final double ibx = it.bDouble;
    3969                                                double ox;
    3970                                                ox = (iax + ibx);
    3971                                                oaf64data[it.oIndex] = ox;
    3972                                        }
    3973                                } else {
    3974                                        while (it.hasNext()) {
    3975                                                final long iax = it.aLong;
    3976                                                final long ibx = it.bLong;
    3977                                                double ox;
    3978                                                ox = (iax + ibx);
    3979                                                oaf64data[it.oIndex] = ox;
    3980                                        }
    3981                                }
    3982                        } else if (as < bs) {
    3983                                if (it.isOutputDouble()) {
    3984                                        while (it.hasNext()) {
    3985                                                final double iax = it.aDouble;
    3986                                                double ibx = it.bDouble;
    3987                                                double ox;
    3988                                                ox = (iax + ibx);
    3989                                                oaf64data[it.oIndex] = ox;
    3990                                                for (int j = 1; j < is; j++) {
    3991                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    3992                                                        ox = (iax + ibx);
    3993                                                        oaf64data[it.oIndex + j] = ox;
    3994                                                }
    3995                                        }
    3996                                } else {
    3997                                        while (it.hasNext()) {
    3998                                                final long iax = it.aLong;
    3999                                                long ibx = it.bLong;
    4000                                                double ox;
    4001                                                ox = (iax + ibx);
    4002                                                oaf64data[it.oIndex] = ox;
    4003                                                for (int j = 1; j < is; j++) {
    4004                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4005                                                        ox = (iax + ibx);
    4006                                                        oaf64data[it.oIndex + j] = ox;
    4007                                                }
    4008                                        }
    4009                                }
    4010                        } else if (as > bs) {
    4011                                if (it.isOutputDouble()) {
    4012                                        while (it.hasNext()) {
    4013                                                double iax = it.aDouble;
    4014                                                final double ibx = it.bDouble;
    4015                                                double ox;
    4016                                                ox = (iax + ibx);
    4017                                                oaf64data[it.oIndex] = ox;
    4018                                                for (int j = 1; j < is; j++) {
    4019                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4020                                                        ox = (iax + ibx);
    4021                                                        oaf64data[it.oIndex + j] = ox;
    4022                                                }
    4023                                        }
    4024                                } else {
    4025                                        while (it.hasNext()) {
    4026                                                long iax = it.aLong;
    4027                                                final long ibx = it.bLong;
    4028                                                double ox;
    4029                                                ox = (iax + ibx);
    4030                                                oaf64data[it.oIndex] = ox;
    4031                                                for (int j = 1; j < is; j++) {
    4032                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4033                                                        ox = (iax + ibx);
    4034                                                        oaf64data[it.oIndex + j] = ox;
    4035                                                }
    4036                                        }
    4037                                }
    4038                        } else if (as == 1) {
    4039                                if (it.isOutputDouble()) {
    4040                                        while (it.hasNext()) {
    4041                                                final double iax = it.aDouble;
    4042                                                final double ibx = it.bDouble;
    4043                                                double ox;
    4044                                                ox = (iax + ibx);
    4045                                                for (int j = 0; j < is; j++) {
    4046                                                        oaf64data[it.oIndex + j] = ox;
    4047                                                }
    4048                                        }
    4049                                } else {
    4050                                        while (it.hasNext()) {
    4051                                                final long iax = it.aLong;
    4052                                                final long ibx = it.bLong;
    4053                                                double ox;
    4054                                                ox = (iax + ibx);
    4055                                                for (int j = 0; j < is; j++) {
    4056                                                        oaf64data[it.oIndex + j] = ox;
    4057                                                }
    4058                                        }
    4059                                }
    4060                        } else {
    4061                                if (it.isOutputDouble()) {
    4062                                        while (it.hasNext()) {
    4063                                                double iax = it.aDouble;
    4064                                                double ibx = it.bDouble;
    4065                                                double ox;
    4066                                                ox = (iax + ibx);
    4067                                                oaf64data[it.oIndex] = ox;
    4068                                                for (int j = 1; j < is; j++) {
    4069                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4070                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4071                                                        ox = (iax + ibx);
    4072                                                        oaf64data[it.oIndex + j] = ox;
    4073                                                }
    4074                                        }
    4075                                } else {
    4076                                        while (it.hasNext()) {
    4077                                                long iax = it.aLong;
    4078                                                long ibx = it.bLong;
    4079                                                double ox;
    4080                                                ox = (iax + ibx);
    4081                                                oaf64data[it.oIndex] = ox;
    4082                                                for (int j = 1; j < is; j++) {
    4083                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4084                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4085                                                        ox = (iax + ibx);
    4086                                                        oaf64data[it.oIndex + j] = ox;
    4087                                                }
    4088                                        }
    4089                                }
    4090                        }
    4091                        break;
    4092                case Dataset.COMPLEX64:
    4093                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    4094                        if (as == 1) {
    4095                                final double iay = 0;
    4096                                while (it.hasNext()) {
    4097                                        final double iax = it.aDouble;
    4098                                        final double ibx = it.bDouble;
    4099                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    4100                                        float ox;
    4101                                        float oy;
    4102                                        ox = (float) (iax + ibx);
    4103                                        oy = (float) (iay + iby);
    4104                                        oc64data[it.oIndex] = ox;
    4105                                        oc64data[it.oIndex + 1] = oy;
    4106                                }
    4107                        } else if (bs == 1) {
    4108                                final double iby = 0;
    4109                                while (it.hasNext()) {
    4110                                        final double iax = it.aDouble;
    4111                                        final double ibx = it.bDouble;
    4112                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    4113                                        float ox;
    4114                                        float oy;
    4115                                        ox = (float) (iax + ibx);
    4116                                        oy = (float) (iay + iby);
    4117                                        oc64data[it.oIndex] = ox;
    4118                                        oc64data[it.oIndex + 1] = oy;
    4119                                }
    4120                        } else {
    4121                                while (it.hasNext()) {
    4122                                        final double iax = it.aDouble;
    4123                                        final double ibx = it.bDouble;
    4124                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    4125                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    4126                                        float ox;
    4127                                        float oy;
    4128                                        ox = (float) (iax + ibx);
    4129                                        oy = (float) (iay + iby);
    4130                                        oc64data[it.oIndex] = ox;
    4131                                        oc64data[it.oIndex + 1] = oy;
    4132                                }
    4133                        }
    4134                        break;
    4135                case Dataset.COMPLEX128:
    4136                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    4137                        if (as == 1) {
    4138                                final double iay = 0;
    4139                                while (it.hasNext()) {
    4140                                        final double iax = it.aDouble;
    4141                                        final double ibx = it.bDouble;
    4142                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    4143                                        double ox;
    4144                                        double oy;
    4145                                        ox = (iax + ibx);
    4146                                        oy = (iay + iby);
    4147                                        oc128data[it.oIndex] = ox;
    4148                                        oc128data[it.oIndex + 1] = oy;
    4149                                }
    4150                        } else if (bs == 1) {
    4151                                final double iby = 0;
    4152                                while (it.hasNext()) {
    4153                                        final double iax = it.aDouble;
    4154                                        final double ibx = it.bDouble;
    4155                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    4156                                        double ox;
    4157                                        double oy;
    4158                                        ox = (iax + ibx);
    4159                                        oy = (iay + iby);
    4160                                        oc128data[it.oIndex] = ox;
    4161                                        oc128data[it.oIndex + 1] = oy;
    4162                                }
    4163                        } else {
    4164                                while (it.hasNext()) {
    4165                                        final double iax = it.aDouble;
    4166                                        final double ibx = it.bDouble;
    4167                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    4168                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    4169                                        double ox;
    4170                                        double oy;
    4171                                        ox = (iax + ibx);
    4172                                        oy = (iay + iby);
    4173                                        oc128data[it.oIndex] = ox;
    4174                                        oc128data[it.oIndex + 1] = oy;
    4175                                }
    4176                        }
    4177                        break;
    4178                default:
    4179                        throw new IllegalArgumentException("add supports integer, compound integer, real, compound real, complex datasets only");
    4180                }
    4181
    4182                addBinaryOperatorName(da, db, result, "+");
    4183                return result;
    4184        }
    4185
    4186        /**
    4187         * subtract operator
    4188         * @param a
    4189         * @param b
    4190         * @return {@code a - b}, subtraction of a by b
    4191         */
    4192        public static Dataset subtract(final Object a, final Object b) {
    4193                return subtract(a, b, null);
    4194        }
    4195
    4196        /**
    4197         * subtract operator
    4198         * @param a
    4199         * @param b
    4200         * @param o output can be null - in which case, a new dataset is created
    4201         * @return {@code a - b}, subtraction of a by b
    4202         */
    4203        public static Dataset subtract(final Object a, final Object b, final Dataset o) {
    4204                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    4205                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    4206                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    4207                final Dataset result = it.getOutput();
    4208                final int is = result.getElementsPerItem();
    4209                final int as = da.getElementsPerItem();
    4210                final int bs = db.getElementsPerItem();
    4211                final int dt = result.getDType();
    4212
    4213                switch(dt) {
    4214                case Dataset.INT8:
    4215                        final byte[] oi8data = ((ByteDataset) result).getData();
    4216                        if (it.isOutputDouble()) {
    4217                                while (it.hasNext()) {
    4218                                        final double iax = it.aDouble;
    4219                                        final double ibx = it.bDouble;
    4220                                        byte ox;
    4221                                        ox = (byte) toLong(iax - ibx);
    4222                                        oi8data[it.oIndex] = ox;
    4223                                }
    4224                        } else {
    4225                                while (it.hasNext()) {
    4226                                        final long iax = it.aLong;
    4227                                        final long ibx = it.bLong;
    4228                                        byte ox;
    4229                                        ox = (byte) (iax - ibx);
    4230                                        oi8data[it.oIndex] = ox;
    4231                                }
    4232                        }
    4233                        break;
    4234                case Dataset.INT16:
    4235                        final short[] oi16data = ((ShortDataset) result).getData();
    4236                        if (it.isOutputDouble()) {
    4237                                while (it.hasNext()) {
    4238                                        final double iax = it.aDouble;
    4239                                        final double ibx = it.bDouble;
    4240                                        short ox;
    4241                                        ox = (short) toLong(iax - ibx);
    4242                                        oi16data[it.oIndex] = ox;
    4243                                }
    4244                        } else {
    4245                                while (it.hasNext()) {
    4246                                        final long iax = it.aLong;
    4247                                        final long ibx = it.bLong;
    4248                                        short ox;
    4249                                        ox = (short) (iax - ibx);
    4250                                        oi16data[it.oIndex] = ox;
    4251                                }
    4252                        }
    4253                        break;
    4254                case Dataset.INT64:
    4255                        final long[] oi64data = ((LongDataset) result).getData();
    4256                        if (it.isOutputDouble()) {
    4257                                while (it.hasNext()) {
    4258                                        final double iax = it.aDouble;
    4259                                        final double ibx = it.bDouble;
    4260                                        long ox;
    4261                                        ox = toLong(iax - ibx);
    4262                                        oi64data[it.oIndex] = ox;
    4263                                }
    4264                        } else {
    4265                                while (it.hasNext()) {
    4266                                        final long iax = it.aLong;
    4267                                        final long ibx = it.bLong;
    4268                                        long ox;
    4269                                        ox = (iax - ibx);
    4270                                        oi64data[it.oIndex] = ox;
    4271                                }
    4272                        }
    4273                        break;
    4274                case Dataset.INT32:
    4275                        final int[] oi32data = ((IntegerDataset) result).getData();
    4276                        if (it.isOutputDouble()) {
    4277                                while (it.hasNext()) {
    4278                                        final double iax = it.aDouble;
    4279                                        final double ibx = it.bDouble;
    4280                                        int ox;
    4281                                        ox = (int) toLong(iax - ibx);
    4282                                        oi32data[it.oIndex] = ox;
    4283                                }
    4284                        } else {
    4285                                while (it.hasNext()) {
    4286                                        final long iax = it.aLong;
    4287                                        final long ibx = it.bLong;
    4288                                        int ox;
    4289                                        ox = (int) (iax - ibx);
    4290                                        oi32data[it.oIndex] = ox;
    4291                                }
    4292                        }
    4293                        break;
    4294                case Dataset.ARRAYINT8:
    4295                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    4296                        if (is == 1) {
    4297                                if (it.isOutputDouble()) {
    4298                                        while (it.hasNext()) {
    4299                                                final double iax = it.aDouble;
    4300                                                final double ibx = it.bDouble;
    4301                                                byte ox;
    4302                                                ox = (byte) toLong(iax - ibx);
    4303                                                oai8data[it.oIndex] = ox;
    4304                                        }
    4305                                } else {
    4306                                        while (it.hasNext()) {
    4307                                                final long iax = it.aLong;
    4308                                                final long ibx = it.bLong;
    4309                                                byte ox;
    4310                                                ox = (byte) (iax - ibx);
    4311                                                oai8data[it.oIndex] = ox;
    4312                                        }
    4313                                }
    4314                        } else if (as < bs) {
    4315                                if (it.isOutputDouble()) {
    4316                                        while (it.hasNext()) {
    4317                                                final double iax = it.aDouble;
    4318                                                double ibx = it.bDouble;
    4319                                                byte ox;
    4320                                                ox = (byte) toLong(iax - ibx);
    4321                                                oai8data[it.oIndex] = ox;
    4322                                                for (int j = 1; j < is; j++) {
    4323                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4324                                                        ox = (byte) toLong(iax - ibx);
    4325                                                        oai8data[it.oIndex + j] = ox;
    4326                                                }
    4327                                        }
    4328                                } else {
    4329                                        while (it.hasNext()) {
    4330                                                final long iax = it.aLong;
    4331                                                long ibx = it.bLong;
    4332                                                byte ox;
    4333                                                ox = (byte) (iax - ibx);
    4334                                                oai8data[it.oIndex] = ox;
    4335                                                for (int j = 1; j < is; j++) {
    4336                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4337                                                        ox = (byte) (iax - ibx);
    4338                                                        oai8data[it.oIndex + j] = ox;
    4339                                                }
    4340                                        }
    4341                                }
    4342                        } else if (as > bs) {
    4343                                if (it.isOutputDouble()) {
    4344                                        while (it.hasNext()) {
    4345                                                double iax = it.aDouble;
    4346                                                final double ibx = it.bDouble;
    4347                                                byte ox;
    4348                                                ox = (byte) toLong(iax - ibx);
    4349                                                oai8data[it.oIndex] = ox;
    4350                                                for (int j = 1; j < is; j++) {
    4351                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4352                                                        ox = (byte) toLong(iax - ibx);
    4353                                                        oai8data[it.oIndex + j] = ox;
    4354                                                }
    4355                                        }
    4356                                } else {
    4357                                        while (it.hasNext()) {
    4358                                                long iax = it.aLong;
    4359                                                final long ibx = it.bLong;
    4360                                                byte ox;
    4361                                                ox = (byte) (iax - ibx);
    4362                                                oai8data[it.oIndex] = ox;
    4363                                                for (int j = 1; j < is; j++) {
    4364                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4365                                                        ox = (byte) (iax - ibx);
    4366                                                        oai8data[it.oIndex + j] = ox;
    4367                                                }
    4368                                        }
    4369                                }
    4370                        } else if (as == 1) {
    4371                                if (it.isOutputDouble()) {
    4372                                        while (it.hasNext()) {
    4373                                                final double iax = it.aDouble;
    4374                                                final double ibx = it.bDouble;
    4375                                                byte ox;
    4376                                                ox = (byte) toLong(iax - ibx);
    4377                                                for (int j = 0; j < is; j++) {
    4378                                                        oai8data[it.oIndex + j] = ox;
    4379                                                }
    4380                                        }
    4381                                } else {
    4382                                        while (it.hasNext()) {
    4383                                                final long iax = it.aLong;
    4384                                                final long ibx = it.bLong;
    4385                                                byte ox;
    4386                                                ox = (byte) (iax - ibx);
    4387                                                for (int j = 0; j < is; j++) {
    4388                                                        oai8data[it.oIndex + j] = ox;
    4389                                                }
    4390                                        }
    4391                                }
    4392                        } else {
    4393                                if (it.isOutputDouble()) {
    4394                                        while (it.hasNext()) {
    4395                                                double iax = it.aDouble;
    4396                                                double ibx = it.bDouble;
    4397                                                byte ox;
    4398                                                ox = (byte) toLong(iax - ibx);
    4399                                                oai8data[it.oIndex] = ox;
    4400                                                for (int j = 1; j < is; j++) {
    4401                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4402                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4403                                                        ox = (byte) toLong(iax - ibx);
    4404                                                        oai8data[it.oIndex + j] = ox;
    4405                                                }
    4406                                        }
    4407                                } else {
    4408                                        while (it.hasNext()) {
    4409                                                long iax = it.aLong;
    4410                                                long ibx = it.bLong;
    4411                                                byte ox;
    4412                                                ox = (byte) (iax - ibx);
    4413                                                oai8data[it.oIndex] = ox;
    4414                                                for (int j = 1; j < is; j++) {
    4415                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4416                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4417                                                        ox = (byte) (iax - ibx);
    4418                                                        oai8data[it.oIndex + j] = ox;
    4419                                                }
    4420                                        }
    4421                                }
    4422                        }
    4423                        break;
    4424                case Dataset.ARRAYINT16:
    4425                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    4426                        if (is == 1) {
    4427                                if (it.isOutputDouble()) {
    4428                                        while (it.hasNext()) {
    4429                                                final double iax = it.aDouble;
    4430                                                final double ibx = it.bDouble;
    4431                                                short ox;
    4432                                                ox = (short) toLong(iax - ibx);
    4433                                                oai16data[it.oIndex] = ox;
    4434                                        }
    4435                                } else {
    4436                                        while (it.hasNext()) {
    4437                                                final long iax = it.aLong;
    4438                                                final long ibx = it.bLong;
    4439                                                short ox;
    4440                                                ox = (short) (iax - ibx);
    4441                                                oai16data[it.oIndex] = ox;
    4442                                        }
    4443                                }
    4444                        } else if (as < bs) {
    4445                                if (it.isOutputDouble()) {
    4446                                        while (it.hasNext()) {
    4447                                                final double iax = it.aDouble;
    4448                                                double ibx = it.bDouble;
    4449                                                short ox;
    4450                                                ox = (short) toLong(iax - ibx);
    4451                                                oai16data[it.oIndex] = ox;
    4452                                                for (int j = 1; j < is; j++) {
    4453                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4454                                                        ox = (short) toLong(iax - ibx);
    4455                                                        oai16data[it.oIndex + j] = ox;
    4456                                                }
    4457                                        }
    4458                                } else {
    4459                                        while (it.hasNext()) {
    4460                                                final long iax = it.aLong;
    4461                                                long ibx = it.bLong;
    4462                                                short ox;
    4463                                                ox = (short) (iax - ibx);
    4464                                                oai16data[it.oIndex] = ox;
    4465                                                for (int j = 1; j < is; j++) {
    4466                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4467                                                        ox = (short) (iax - ibx);
    4468                                                        oai16data[it.oIndex + j] = ox;
    4469                                                }
    4470                                        }
    4471                                }
    4472                        } else if (as > bs) {
    4473                                if (it.isOutputDouble()) {
    4474                                        while (it.hasNext()) {
    4475                                                double iax = it.aDouble;
    4476                                                final double ibx = it.bDouble;
    4477                                                short ox;
    4478                                                ox = (short) toLong(iax - ibx);
    4479                                                oai16data[it.oIndex] = ox;
    4480                                                for (int j = 1; j < is; j++) {
    4481                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4482                                                        ox = (short) toLong(iax - ibx);
    4483                                                        oai16data[it.oIndex + j] = ox;
    4484                                                }
    4485                                        }
    4486                                } else {
    4487                                        while (it.hasNext()) {
    4488                                                long iax = it.aLong;
    4489                                                final long ibx = it.bLong;
    4490                                                short ox;
    4491                                                ox = (short) (iax - ibx);
    4492                                                oai16data[it.oIndex] = ox;
    4493                                                for (int j = 1; j < is; j++) {
    4494                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4495                                                        ox = (short) (iax - ibx);
    4496                                                        oai16data[it.oIndex + j] = ox;
    4497                                                }
    4498                                        }
    4499                                }
    4500                        } else if (as == 1) {
    4501                                if (it.isOutputDouble()) {
    4502                                        while (it.hasNext()) {
    4503                                                final double iax = it.aDouble;
    4504                                                final double ibx = it.bDouble;
    4505                                                short ox;
    4506                                                ox = (short) toLong(iax - ibx);
    4507                                                for (int j = 0; j < is; j++) {
    4508                                                        oai16data[it.oIndex + j] = ox;
    4509                                                }
    4510                                        }
    4511                                } else {
    4512                                        while (it.hasNext()) {
    4513                                                final long iax = it.aLong;
    4514                                                final long ibx = it.bLong;
    4515                                                short ox;
    4516                                                ox = (short) (iax - ibx);
    4517                                                for (int j = 0; j < is; j++) {
    4518                                                        oai16data[it.oIndex + j] = ox;
    4519                                                }
    4520                                        }
    4521                                }
    4522                        } else {
    4523                                if (it.isOutputDouble()) {
    4524                                        while (it.hasNext()) {
    4525                                                double iax = it.aDouble;
    4526                                                double ibx = it.bDouble;
    4527                                                short ox;
    4528                                                ox = (short) toLong(iax - ibx);
    4529                                                oai16data[it.oIndex] = ox;
    4530                                                for (int j = 1; j < is; j++) {
    4531                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4532                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4533                                                        ox = (short) toLong(iax - ibx);
    4534                                                        oai16data[it.oIndex + j] = ox;
    4535                                                }
    4536                                        }
    4537                                } else {
    4538                                        while (it.hasNext()) {
    4539                                                long iax = it.aLong;
    4540                                                long ibx = it.bLong;
    4541                                                short ox;
    4542                                                ox = (short) (iax - ibx);
    4543                                                oai16data[it.oIndex] = ox;
    4544                                                for (int j = 1; j < is; j++) {
    4545                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4546                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4547                                                        ox = (short) (iax - ibx);
    4548                                                        oai16data[it.oIndex + j] = ox;
    4549                                                }
    4550                                        }
    4551                                }
    4552                        }
    4553                        break;
    4554                case Dataset.ARRAYINT64:
    4555                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    4556                        if (is == 1) {
    4557                                if (it.isOutputDouble()) {
    4558                                        while (it.hasNext()) {
    4559                                                final double iax = it.aDouble;
    4560                                                final double ibx = it.bDouble;
    4561                                                long ox;
    4562                                                ox = toLong(iax - ibx);
    4563                                                oai64data[it.oIndex] = ox;
    4564                                        }
    4565                                } else {
    4566                                        while (it.hasNext()) {
    4567                                                final long iax = it.aLong;
    4568                                                final long ibx = it.bLong;
    4569                                                long ox;
    4570                                                ox = (iax - ibx);
    4571                                                oai64data[it.oIndex] = ox;
    4572                                        }
    4573                                }
    4574                        } else if (as < bs) {
    4575                                if (it.isOutputDouble()) {
    4576                                        while (it.hasNext()) {
    4577                                                final double iax = it.aDouble;
    4578                                                double ibx = it.bDouble;
    4579                                                long ox;
    4580                                                ox = toLong(iax - ibx);
    4581                                                oai64data[it.oIndex] = ox;
    4582                                                for (int j = 1; j < is; j++) {
    4583                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4584                                                        ox = toLong(iax - ibx);
    4585                                                        oai64data[it.oIndex + j] = ox;
    4586                                                }
    4587                                        }
    4588                                } else {
    4589                                        while (it.hasNext()) {
    4590                                                final long iax = it.aLong;
    4591                                                long ibx = it.bLong;
    4592                                                long ox;
    4593                                                ox = (iax - ibx);
    4594                                                oai64data[it.oIndex] = ox;
    4595                                                for (int j = 1; j < is; j++) {
    4596                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4597                                                        ox = (iax - ibx);
    4598                                                        oai64data[it.oIndex + j] = ox;
    4599                                                }
    4600                                        }
    4601                                }
    4602                        } else if (as > bs) {
    4603                                if (it.isOutputDouble()) {
    4604                                        while (it.hasNext()) {
    4605                                                double iax = it.aDouble;
    4606                                                final double ibx = it.bDouble;
    4607                                                long ox;
    4608                                                ox = toLong(iax - ibx);
    4609                                                oai64data[it.oIndex] = ox;
    4610                                                for (int j = 1; j < is; j++) {
    4611                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4612                                                        ox = toLong(iax - ibx);
    4613                                                        oai64data[it.oIndex + j] = ox;
    4614                                                }
    4615                                        }
    4616                                } else {
    4617                                        while (it.hasNext()) {
    4618                                                long iax = it.aLong;
    4619                                                final long ibx = it.bLong;
    4620                                                long ox;
    4621                                                ox = (iax - ibx);
    4622                                                oai64data[it.oIndex] = ox;
    4623                                                for (int j = 1; j < is; j++) {
    4624                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4625                                                        ox = (iax - ibx);
    4626                                                        oai64data[it.oIndex + j] = ox;
    4627                                                }
    4628                                        }
    4629                                }
    4630                        } else if (as == 1) {
    4631                                if (it.isOutputDouble()) {
    4632                                        while (it.hasNext()) {
    4633                                                final double iax = it.aDouble;
    4634                                                final double ibx = it.bDouble;
    4635                                                long ox;
    4636                                                ox = toLong(iax - ibx);
    4637                                                for (int j = 0; j < is; j++) {
    4638                                                        oai64data[it.oIndex + j] = ox;
    4639                                                }
    4640                                        }
    4641                                } else {
    4642                                        while (it.hasNext()) {
    4643                                                final long iax = it.aLong;
    4644                                                final long ibx = it.bLong;
    4645                                                long ox;
    4646                                                ox = (iax - ibx);
    4647                                                for (int j = 0; j < is; j++) {
    4648                                                        oai64data[it.oIndex + j] = ox;
    4649                                                }
    4650                                        }
    4651                                }
    4652                        } else {
    4653                                if (it.isOutputDouble()) {
    4654                                        while (it.hasNext()) {
    4655                                                double iax = it.aDouble;
    4656                                                double ibx = it.bDouble;
    4657                                                long ox;
    4658                                                ox = toLong(iax - ibx);
    4659                                                oai64data[it.oIndex] = ox;
    4660                                                for (int j = 1; j < is; j++) {
    4661                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4662                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4663                                                        ox = toLong(iax - ibx);
    4664                                                        oai64data[it.oIndex + j] = ox;
    4665                                                }
    4666                                        }
    4667                                } else {
    4668                                        while (it.hasNext()) {
    4669                                                long iax = it.aLong;
    4670                                                long ibx = it.bLong;
    4671                                                long ox;
    4672                                                ox = (iax - ibx);
    4673                                                oai64data[it.oIndex] = ox;
    4674                                                for (int j = 1; j < is; j++) {
    4675                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4676                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4677                                                        ox = (iax - ibx);
    4678                                                        oai64data[it.oIndex + j] = ox;
    4679                                                }
    4680                                        }
    4681                                }
    4682                        }
    4683                        break;
    4684                case Dataset.ARRAYINT32:
    4685                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    4686                        if (is == 1) {
    4687                                if (it.isOutputDouble()) {
    4688                                        while (it.hasNext()) {
    4689                                                final double iax = it.aDouble;
    4690                                                final double ibx = it.bDouble;
    4691                                                int ox;
    4692                                                ox = (int) toLong(iax - ibx);
    4693                                                oai32data[it.oIndex] = ox;
    4694                                        }
    4695                                } else {
    4696                                        while (it.hasNext()) {
    4697                                                final long iax = it.aLong;
    4698                                                final long ibx = it.bLong;
    4699                                                int ox;
    4700                                                ox = (int) (iax - ibx);
    4701                                                oai32data[it.oIndex] = ox;
    4702                                        }
    4703                                }
    4704                        } else if (as < bs) {
    4705                                if (it.isOutputDouble()) {
    4706                                        while (it.hasNext()) {
    4707                                                final double iax = it.aDouble;
    4708                                                double ibx = it.bDouble;
    4709                                                int ox;
    4710                                                ox = (int) toLong(iax - ibx);
    4711                                                oai32data[it.oIndex] = ox;
    4712                                                for (int j = 1; j < is; j++) {
    4713                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4714                                                        ox = (int) toLong(iax - ibx);
    4715                                                        oai32data[it.oIndex + j] = ox;
    4716                                                }
    4717                                        }
    4718                                } else {
    4719                                        while (it.hasNext()) {
    4720                                                final long iax = it.aLong;
    4721                                                long ibx = it.bLong;
    4722                                                int ox;
    4723                                                ox = (int) (iax - ibx);
    4724                                                oai32data[it.oIndex] = ox;
    4725                                                for (int j = 1; j < is; j++) {
    4726                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4727                                                        ox = (int) (iax - ibx);
    4728                                                        oai32data[it.oIndex + j] = ox;
    4729                                                }
    4730                                        }
    4731                                }
    4732                        } else if (as > bs) {
    4733                                if (it.isOutputDouble()) {
    4734                                        while (it.hasNext()) {
    4735                                                double iax = it.aDouble;
    4736                                                final double ibx = it.bDouble;
    4737                                                int ox;
    4738                                                ox = (int) toLong(iax - ibx);
    4739                                                oai32data[it.oIndex] = ox;
    4740                                                for (int j = 1; j < is; j++) {
    4741                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4742                                                        ox = (int) toLong(iax - ibx);
    4743                                                        oai32data[it.oIndex + j] = ox;
    4744                                                }
    4745                                        }
    4746                                } else {
    4747                                        while (it.hasNext()) {
    4748                                                long iax = it.aLong;
    4749                                                final long ibx = it.bLong;
    4750                                                int ox;
    4751                                                ox = (int) (iax - ibx);
    4752                                                oai32data[it.oIndex] = ox;
    4753                                                for (int j = 1; j < is; j++) {
    4754                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4755                                                        ox = (int) (iax - ibx);
    4756                                                        oai32data[it.oIndex + j] = ox;
    4757                                                }
    4758                                        }
    4759                                }
    4760                        } else if (as == 1) {
    4761                                if (it.isOutputDouble()) {
    4762                                        while (it.hasNext()) {
    4763                                                final double iax = it.aDouble;
    4764                                                final double ibx = it.bDouble;
    4765                                                int ox;
    4766                                                ox = (int) toLong(iax - ibx);
    4767                                                for (int j = 0; j < is; j++) {
    4768                                                        oai32data[it.oIndex + j] = ox;
    4769                                                }
    4770                                        }
    4771                                } else {
    4772                                        while (it.hasNext()) {
    4773                                                final long iax = it.aLong;
    4774                                                final long ibx = it.bLong;
    4775                                                int ox;
    4776                                                ox = (int) (iax - ibx);
    4777                                                for (int j = 0; j < is; j++) {
    4778                                                        oai32data[it.oIndex + j] = ox;
    4779                                                }
    4780                                        }
    4781                                }
    4782                        } else {
    4783                                if (it.isOutputDouble()) {
    4784                                        while (it.hasNext()) {
    4785                                                double iax = it.aDouble;
    4786                                                double ibx = it.bDouble;
    4787                                                int ox;
    4788                                                ox = (int) toLong(iax - ibx);
    4789                                                oai32data[it.oIndex] = ox;
    4790                                                for (int j = 1; j < is; j++) {
    4791                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4792                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4793                                                        ox = (int) toLong(iax - ibx);
    4794                                                        oai32data[it.oIndex + j] = ox;
    4795                                                }
    4796                                        }
    4797                                } else {
    4798                                        while (it.hasNext()) {
    4799                                                long iax = it.aLong;
    4800                                                long ibx = it.bLong;
    4801                                                int ox;
    4802                                                ox = (int) (iax - ibx);
    4803                                                oai32data[it.oIndex] = ox;
    4804                                                for (int j = 1; j < is; j++) {
    4805                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4806                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4807                                                        ox = (int) (iax - ibx);
    4808                                                        oai32data[it.oIndex + j] = ox;
    4809                                                }
    4810                                        }
    4811                                }
    4812                        }
    4813                        break;
    4814                case Dataset.FLOAT32:
    4815                        final float[] of32data = ((FloatDataset) result).getData();
    4816                        if (it.isOutputDouble()) {
    4817                                while (it.hasNext()) {
    4818                                        final double iax = it.aDouble;
    4819                                        final double ibx = it.bDouble;
    4820                                        float ox;
    4821                                        ox = (float) (iax - ibx);
    4822                                        of32data[it.oIndex] = ox;
    4823                                }
    4824                        } else {
    4825                                while (it.hasNext()) {
    4826                                        final long iax = it.aLong;
    4827                                        final long ibx = it.bLong;
    4828                                        float ox;
    4829                                        ox = (iax - ibx);
    4830                                        of32data[it.oIndex] = ox;
    4831                                }
    4832                        }
    4833                        break;
    4834                case Dataset.FLOAT64:
    4835                        final double[] of64data = ((DoubleDataset) result).getData();
    4836                        if (it.isOutputDouble()) {
    4837                                while (it.hasNext()) {
    4838                                        final double iax = it.aDouble;
    4839                                        final double ibx = it.bDouble;
    4840                                        double ox;
    4841                                        ox = (iax - ibx);
    4842                                        of64data[it.oIndex] = ox;
    4843                                }
    4844                        } else {
    4845                                while (it.hasNext()) {
    4846                                        final long iax = it.aLong;
    4847                                        final long ibx = it.bLong;
    4848                                        double ox;
    4849                                        ox = (iax - ibx);
    4850                                        of64data[it.oIndex] = ox;
    4851                                }
    4852                        }
    4853                        break;
    4854                case Dataset.ARRAYFLOAT32:
    4855                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    4856                        if (is == 1) {
    4857                                if (it.isOutputDouble()) {
    4858                                        while (it.hasNext()) {
    4859                                                final double iax = it.aDouble;
    4860                                                final double ibx = it.bDouble;
    4861                                                float ox;
    4862                                                ox = (float) (iax - ibx);
    4863                                                oaf32data[it.oIndex] = ox;
    4864                                        }
    4865                                } else {
    4866                                        while (it.hasNext()) {
    4867                                                final long iax = it.aLong;
    4868                                                final long ibx = it.bLong;
    4869                                                float ox;
    4870                                                ox = (iax - ibx);
    4871                                                oaf32data[it.oIndex] = ox;
    4872                                        }
    4873                                }
    4874                        } else if (as < bs) {
    4875                                if (it.isOutputDouble()) {
    4876                                        while (it.hasNext()) {
    4877                                                final double iax = it.aDouble;
    4878                                                double ibx = it.bDouble;
    4879                                                float ox;
    4880                                                ox = (float) (iax - ibx);
    4881                                                oaf32data[it.oIndex] = ox;
    4882                                                for (int j = 1; j < is; j++) {
    4883                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4884                                                        ox = (float) (iax - ibx);
    4885                                                        oaf32data[it.oIndex + j] = ox;
    4886                                                }
    4887                                        }
    4888                                } else {
    4889                                        while (it.hasNext()) {
    4890                                                final long iax = it.aLong;
    4891                                                long ibx = it.bLong;
    4892                                                float ox;
    4893                                                ox = (iax - ibx);
    4894                                                oaf32data[it.oIndex] = ox;
    4895                                                for (int j = 1; j < is; j++) {
    4896                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4897                                                        ox = (iax - ibx);
    4898                                                        oaf32data[it.oIndex + j] = ox;
    4899                                                }
    4900                                        }
    4901                                }
    4902                        } else if (as > bs) {
    4903                                if (it.isOutputDouble()) {
    4904                                        while (it.hasNext()) {
    4905                                                double iax = it.aDouble;
    4906                                                final double ibx = it.bDouble;
    4907                                                float ox;
    4908                                                ox = (float) (iax - ibx);
    4909                                                oaf32data[it.oIndex] = ox;
    4910                                                for (int j = 1; j < is; j++) {
    4911                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4912                                                        ox = (float) (iax - ibx);
    4913                                                        oaf32data[it.oIndex + j] = ox;
    4914                                                }
    4915                                        }
    4916                                } else {
    4917                                        while (it.hasNext()) {
    4918                                                long iax = it.aLong;
    4919                                                final long ibx = it.bLong;
    4920                                                float ox;
    4921                                                ox = (iax - ibx);
    4922                                                oaf32data[it.oIndex] = ox;
    4923                                                for (int j = 1; j < is; j++) {
    4924                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4925                                                        ox = (iax - ibx);
    4926                                                        oaf32data[it.oIndex + j] = ox;
    4927                                                }
    4928                                        }
    4929                                }
    4930                        } else if (as == 1) {
    4931                                if (it.isOutputDouble()) {
    4932                                        while (it.hasNext()) {
    4933                                                final double iax = it.aDouble;
    4934                                                final double ibx = it.bDouble;
    4935                                                float ox;
    4936                                                ox = (float) (iax - ibx);
    4937                                                for (int j = 0; j < is; j++) {
    4938                                                        oaf32data[it.oIndex + j] = ox;
    4939                                                }
    4940                                        }
    4941                                } else {
    4942                                        while (it.hasNext()) {
    4943                                                final long iax = it.aLong;
    4944                                                final long ibx = it.bLong;
    4945                                                float ox;
    4946                                                ox = (iax - ibx);
    4947                                                for (int j = 0; j < is; j++) {
    4948                                                        oaf32data[it.oIndex + j] = ox;
    4949                                                }
    4950                                        }
    4951                                }
    4952                        } else {
    4953                                if (it.isOutputDouble()) {
    4954                                        while (it.hasNext()) {
    4955                                                double iax = it.aDouble;
    4956                                                double ibx = it.bDouble;
    4957                                                float ox;
    4958                                                ox = (float) (iax - ibx);
    4959                                                oaf32data[it.oIndex] = ox;
    4960                                                for (int j = 1; j < is; j++) {
    4961                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    4962                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    4963                                                        ox = (float) (iax - ibx);
    4964                                                        oaf32data[it.oIndex + j] = ox;
    4965                                                }
    4966                                        }
    4967                                } else {
    4968                                        while (it.hasNext()) {
    4969                                                long iax = it.aLong;
    4970                                                long ibx = it.bLong;
    4971                                                float ox;
    4972                                                ox = (iax - ibx);
    4973                                                oaf32data[it.oIndex] = ox;
    4974                                                for (int j = 1; j < is; j++) {
    4975                                                        iax = da.getElementLongAbs(it.aIndex + j);
    4976                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    4977                                                        ox = (iax - ibx);
    4978                                                        oaf32data[it.oIndex + j] = ox;
    4979                                                }
    4980                                        }
    4981                                }
    4982                        }
    4983                        break;
    4984                case Dataset.ARRAYFLOAT64:
    4985                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    4986                        if (is == 1) {
    4987                                if (it.isOutputDouble()) {
    4988                                        while (it.hasNext()) {
    4989                                                final double iax = it.aDouble;
    4990                                                final double ibx = it.bDouble;
    4991                                                double ox;
    4992                                                ox = (iax - ibx);
    4993                                                oaf64data[it.oIndex] = ox;
    4994                                        }
    4995                                } else {
    4996                                        while (it.hasNext()) {
    4997                                                final long iax = it.aLong;
    4998                                                final long ibx = it.bLong;
    4999                                                double ox;
    5000                                                ox = (iax - ibx);
    5001                                                oaf64data[it.oIndex] = ox;
    5002                                        }
    5003                                }
    5004                        } else if (as < bs) {
    5005                                if (it.isOutputDouble()) {
    5006                                        while (it.hasNext()) {
    5007                                                final double iax = it.aDouble;
    5008                                                double ibx = it.bDouble;
    5009                                                double ox;
    5010                                                ox = (iax - ibx);
    5011                                                oaf64data[it.oIndex] = ox;
    5012                                                for (int j = 1; j < is; j++) {
    5013                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5014                                                        ox = (iax - ibx);
    5015                                                        oaf64data[it.oIndex + j] = ox;
    5016                                                }
    5017                                        }
    5018                                } else {
    5019                                        while (it.hasNext()) {
    5020                                                final long iax = it.aLong;
    5021                                                long ibx = it.bLong;
    5022                                                double ox;
    5023                                                ox = (iax - ibx);
    5024                                                oaf64data[it.oIndex] = ox;
    5025                                                for (int j = 1; j < is; j++) {
    5026                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5027                                                        ox = (iax - ibx);
    5028                                                        oaf64data[it.oIndex + j] = ox;
    5029                                                }
    5030                                        }
    5031                                }
    5032                        } else if (as > bs) {
    5033                                if (it.isOutputDouble()) {
    5034                                        while (it.hasNext()) {
    5035                                                double iax = it.aDouble;
    5036                                                final double ibx = it.bDouble;
    5037                                                double ox;
    5038                                                ox = (iax - ibx);
    5039                                                oaf64data[it.oIndex] = ox;
    5040                                                for (int j = 1; j < is; j++) {
    5041                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5042                                                        ox = (iax - ibx);
    5043                                                        oaf64data[it.oIndex + j] = ox;
    5044                                                }
    5045                                        }
    5046                                } else {
    5047                                        while (it.hasNext()) {
    5048                                                long iax = it.aLong;
    5049                                                final long ibx = it.bLong;
    5050                                                double ox;
    5051                                                ox = (iax - ibx);
    5052                                                oaf64data[it.oIndex] = ox;
    5053                                                for (int j = 1; j < is; j++) {
    5054                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5055                                                        ox = (iax - ibx);
    5056                                                        oaf64data[it.oIndex + j] = ox;
    5057                                                }
    5058                                        }
    5059                                }
    5060                        } else if (as == 1) {
    5061                                if (it.isOutputDouble()) {
    5062                                        while (it.hasNext()) {
    5063                                                final double iax = it.aDouble;
    5064                                                final double ibx = it.bDouble;
    5065                                                double ox;
    5066                                                ox = (iax - ibx);
    5067                                                for (int j = 0; j < is; j++) {
    5068                                                        oaf64data[it.oIndex + j] = ox;
    5069                                                }
    5070                                        }
    5071                                } else {
    5072                                        while (it.hasNext()) {
    5073                                                final long iax = it.aLong;
    5074                                                final long ibx = it.bLong;
    5075                                                double ox;
    5076                                                ox = (iax - ibx);
    5077                                                for (int j = 0; j < is; j++) {
    5078                                                        oaf64data[it.oIndex + j] = ox;
    5079                                                }
    5080                                        }
    5081                                }
    5082                        } else {
    5083                                if (it.isOutputDouble()) {
    5084                                        while (it.hasNext()) {
    5085                                                double iax = it.aDouble;
    5086                                                double ibx = it.bDouble;
    5087                                                double ox;
    5088                                                ox = (iax - ibx);
    5089                                                oaf64data[it.oIndex] = ox;
    5090                                                for (int j = 1; j < is; j++) {
    5091                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5092                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5093                                                        ox = (iax - ibx);
    5094                                                        oaf64data[it.oIndex + j] = ox;
    5095                                                }
    5096                                        }
    5097                                } else {
    5098                                        while (it.hasNext()) {
    5099                                                long iax = it.aLong;
    5100                                                long ibx = it.bLong;
    5101                                                double ox;
    5102                                                ox = (iax - ibx);
    5103                                                oaf64data[it.oIndex] = ox;
    5104                                                for (int j = 1; j < is; j++) {
    5105                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5106                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5107                                                        ox = (iax - ibx);
    5108                                                        oaf64data[it.oIndex + j] = ox;
    5109                                                }
    5110                                        }
    5111                                }
    5112                        }
    5113                        break;
    5114                case Dataset.COMPLEX64:
    5115                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    5116                        if (as == 1) {
    5117                                final double iay = 0;
    5118                                while (it.hasNext()) {
    5119                                        final double iax = it.aDouble;
    5120                                        final double ibx = it.bDouble;
    5121                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    5122                                        float ox;
    5123                                        float oy;
    5124                                        ox = (float) (iax - ibx);
    5125                                        oy = (float) (iay - iby);
    5126                                        oc64data[it.oIndex] = ox;
    5127                                        oc64data[it.oIndex + 1] = oy;
    5128                                }
    5129                        } else if (bs == 1) {
    5130                                final double iby = 0;
    5131                                while (it.hasNext()) {
    5132                                        final double iax = it.aDouble;
    5133                                        final double ibx = it.bDouble;
    5134                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    5135                                        float ox;
    5136                                        float oy;
    5137                                        ox = (float) (iax - ibx);
    5138                                        oy = (float) (iay - iby);
    5139                                        oc64data[it.oIndex] = ox;
    5140                                        oc64data[it.oIndex + 1] = oy;
    5141                                }
    5142                        } else {
    5143                                while (it.hasNext()) {
    5144                                        final double iax = it.aDouble;
    5145                                        final double ibx = it.bDouble;
    5146                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    5147                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    5148                                        float ox;
    5149                                        float oy;
    5150                                        ox = (float) (iax - ibx);
    5151                                        oy = (float) (iay - iby);
    5152                                        oc64data[it.oIndex] = ox;
    5153                                        oc64data[it.oIndex + 1] = oy;
    5154                                }
    5155                        }
    5156                        break;
    5157                case Dataset.COMPLEX128:
    5158                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    5159                        if (as == 1) {
    5160                                final double iay = 0;
    5161                                while (it.hasNext()) {
    5162                                        final double iax = it.aDouble;
    5163                                        final double ibx = it.bDouble;
    5164                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    5165                                        double ox;
    5166                                        double oy;
    5167                                        ox = (iax - ibx);
    5168                                        oy = (iay - iby);
    5169                                        oc128data[it.oIndex] = ox;
    5170                                        oc128data[it.oIndex + 1] = oy;
    5171                                }
    5172                        } else if (bs == 1) {
    5173                                final double iby = 0;
    5174                                while (it.hasNext()) {
    5175                                        final double iax = it.aDouble;
    5176                                        final double ibx = it.bDouble;
    5177                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    5178                                        double ox;
    5179                                        double oy;
    5180                                        ox = (iax - ibx);
    5181                                        oy = (iay - iby);
    5182                                        oc128data[it.oIndex] = ox;
    5183                                        oc128data[it.oIndex + 1] = oy;
    5184                                }
    5185                        } else {
    5186                                while (it.hasNext()) {
    5187                                        final double iax = it.aDouble;
    5188                                        final double ibx = it.bDouble;
    5189                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    5190                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    5191                                        double ox;
    5192                                        double oy;
    5193                                        ox = (iax - ibx);
    5194                                        oy = (iay - iby);
    5195                                        oc128data[it.oIndex] = ox;
    5196                                        oc128data[it.oIndex + 1] = oy;
    5197                                }
    5198                        }
    5199                        break;
    5200                default:
    5201                        throw new IllegalArgumentException("subtract supports integer, compound integer, real, compound real, complex datasets only");
    5202                }
    5203
    5204                addBinaryOperatorName(da, db, result, "-");
    5205                return result;
    5206        }
    5207
    5208        /**
    5209         * multiply operator
    5210         * @param a
    5211         * @param b
    5212         * @return {@code a * b}, product of a and b
    5213         */
    5214        public static Dataset multiply(final Object a, final Object b) {
    5215                return multiply(a, b, null);
    5216        }
    5217
    5218        /**
    5219         * multiply operator
    5220         * @param a
    5221         * @param b
    5222         * @param o output can be null - in which case, a new dataset is created
    5223         * @return {@code a * b}, product of a and b
    5224         */
    5225        public static Dataset multiply(final Object a, final Object b, final Dataset o) {
    5226                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    5227                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    5228                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    5229                final Dataset result = it.getOutput();
    5230                final int is = result.getElementsPerItem();
    5231                final int as = da.getElementsPerItem();
    5232                final int bs = db.getElementsPerItem();
    5233                final int dt = result.getDType();
    5234
    5235                switch(dt) {
    5236                case Dataset.INT8:
    5237                        final byte[] oi8data = ((ByteDataset) result).getData();
    5238                        if (it.isOutputDouble()) {
    5239                                while (it.hasNext()) {
    5240                                        final double iax = it.aDouble;
    5241                                        final double ibx = it.bDouble;
    5242                                        byte ox;
    5243                                        ox = (byte) toLong(iax * ibx);
    5244                                        oi8data[it.oIndex] = ox;
    5245                                }
    5246                        } else {
    5247                                while (it.hasNext()) {
    5248                                        final long iax = it.aLong;
    5249                                        final long ibx = it.bLong;
    5250                                        byte ox;
    5251                                        ox = (byte) (iax * ibx);
    5252                                        oi8data[it.oIndex] = ox;
    5253                                }
    5254                        }
    5255                        break;
    5256                case Dataset.INT16:
    5257                        final short[] oi16data = ((ShortDataset) result).getData();
    5258                        if (it.isOutputDouble()) {
    5259                                while (it.hasNext()) {
    5260                                        final double iax = it.aDouble;
    5261                                        final double ibx = it.bDouble;
    5262                                        short ox;
    5263                                        ox = (short) toLong(iax * ibx);
    5264                                        oi16data[it.oIndex] = ox;
    5265                                }
    5266                        } else {
    5267                                while (it.hasNext()) {
    5268                                        final long iax = it.aLong;
    5269                                        final long ibx = it.bLong;
    5270                                        short ox;
    5271                                        ox = (short) (iax * ibx);
    5272                                        oi16data[it.oIndex] = ox;
    5273                                }
    5274                        }
    5275                        break;
    5276                case Dataset.INT64:
    5277                        final long[] oi64data = ((LongDataset) result).getData();
    5278                        if (it.isOutputDouble()) {
    5279                                while (it.hasNext()) {
    5280                                        final double iax = it.aDouble;
    5281                                        final double ibx = it.bDouble;
    5282                                        long ox;
    5283                                        ox = toLong(iax * ibx);
    5284                                        oi64data[it.oIndex] = ox;
    5285                                }
    5286                        } else {
    5287                                while (it.hasNext()) {
    5288                                        final long iax = it.aLong;
    5289                                        final long ibx = it.bLong;
    5290                                        long ox;
    5291                                        ox = (iax * ibx);
    5292                                        oi64data[it.oIndex] = ox;
    5293                                }
    5294                        }
    5295                        break;
    5296                case Dataset.INT32:
    5297                        final int[] oi32data = ((IntegerDataset) result).getData();
    5298                        if (it.isOutputDouble()) {
    5299                                while (it.hasNext()) {
    5300                                        final double iax = it.aDouble;
    5301                                        final double ibx = it.bDouble;
    5302                                        int ox;
    5303                                        ox = (int) toLong(iax * ibx);
    5304                                        oi32data[it.oIndex] = ox;
    5305                                }
    5306                        } else {
    5307                                while (it.hasNext()) {
    5308                                        final long iax = it.aLong;
    5309                                        final long ibx = it.bLong;
    5310                                        int ox;
    5311                                        ox = (int) (iax * ibx);
    5312                                        oi32data[it.oIndex] = ox;
    5313                                }
    5314                        }
    5315                        break;
    5316                case Dataset.ARRAYINT8:
    5317                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    5318                        if (is == 1) {
    5319                                if (it.isOutputDouble()) {
    5320                                        while (it.hasNext()) {
    5321                                                final double iax = it.aDouble;
    5322                                                final double ibx = it.bDouble;
    5323                                                byte ox;
    5324                                                ox = (byte) toLong(iax * ibx);
    5325                                                oai8data[it.oIndex] = ox;
    5326                                        }
    5327                                } else {
    5328                                        while (it.hasNext()) {
    5329                                                final long iax = it.aLong;
    5330                                                final long ibx = it.bLong;
    5331                                                byte ox;
    5332                                                ox = (byte) (iax * ibx);
    5333                                                oai8data[it.oIndex] = ox;
    5334                                        }
    5335                                }
    5336                        } else if (as < bs) {
    5337                                if (it.isOutputDouble()) {
    5338                                        while (it.hasNext()) {
    5339                                                final double iax = it.aDouble;
    5340                                                double ibx = it.bDouble;
    5341                                                byte ox;
    5342                                                ox = (byte) toLong(iax * ibx);
    5343                                                oai8data[it.oIndex] = ox;
    5344                                                for (int j = 1; j < is; j++) {
    5345                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5346                                                        ox = (byte) toLong(iax * ibx);
    5347                                                        oai8data[it.oIndex + j] = ox;
    5348                                                }
    5349                                        }
    5350                                } else {
    5351                                        while (it.hasNext()) {
    5352                                                final long iax = it.aLong;
    5353                                                long ibx = it.bLong;
    5354                                                byte ox;
    5355                                                ox = (byte) (iax * ibx);
    5356                                                oai8data[it.oIndex] = ox;
    5357                                                for (int j = 1; j < is; j++) {
    5358                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5359                                                        ox = (byte) (iax * ibx);
    5360                                                        oai8data[it.oIndex + j] = ox;
    5361                                                }
    5362                                        }
    5363                                }
    5364                        } else if (as > bs) {
    5365                                if (it.isOutputDouble()) {
    5366                                        while (it.hasNext()) {
    5367                                                double iax = it.aDouble;
    5368                                                final double ibx = it.bDouble;
    5369                                                byte ox;
    5370                                                ox = (byte) toLong(iax * ibx);
    5371                                                oai8data[it.oIndex] = ox;
    5372                                                for (int j = 1; j < is; j++) {
    5373                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5374                                                        ox = (byte) toLong(iax * ibx);
    5375                                                        oai8data[it.oIndex + j] = ox;
    5376                                                }
    5377                                        }
    5378                                } else {
    5379                                        while (it.hasNext()) {
    5380                                                long iax = it.aLong;
    5381                                                final long ibx = it.bLong;
    5382                                                byte ox;
    5383                                                ox = (byte) (iax * ibx);
    5384                                                oai8data[it.oIndex] = ox;
    5385                                                for (int j = 1; j < is; j++) {
    5386                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5387                                                        ox = (byte) (iax * ibx);
    5388                                                        oai8data[it.oIndex + j] = ox;
    5389                                                }
    5390                                        }
    5391                                }
    5392                        } else if (as == 1) {
    5393                                if (it.isOutputDouble()) {
    5394                                        while (it.hasNext()) {
    5395                                                final double iax = it.aDouble;
    5396                                                final double ibx = it.bDouble;
    5397                                                byte ox;
    5398                                                ox = (byte) toLong(iax * ibx);
    5399                                                for (int j = 0; j < is; j++) {
    5400                                                        oai8data[it.oIndex + j] = ox;
    5401                                                }
    5402                                        }
    5403                                } else {
    5404                                        while (it.hasNext()) {
    5405                                                final long iax = it.aLong;
    5406                                                final long ibx = it.bLong;
    5407                                                byte ox;
    5408                                                ox = (byte) (iax * ibx);
    5409                                                for (int j = 0; j < is; j++) {
    5410                                                        oai8data[it.oIndex + j] = ox;
    5411                                                }
    5412                                        }
    5413                                }
    5414                        } else {
    5415                                if (it.isOutputDouble()) {
    5416                                        while (it.hasNext()) {
    5417                                                double iax = it.aDouble;
    5418                                                double ibx = it.bDouble;
    5419                                                byte ox;
    5420                                                ox = (byte) toLong(iax * ibx);
    5421                                                oai8data[it.oIndex] = ox;
    5422                                                for (int j = 1; j < is; j++) {
    5423                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5424                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5425                                                        ox = (byte) toLong(iax * ibx);
    5426                                                        oai8data[it.oIndex + j] = ox;
    5427                                                }
    5428                                        }
    5429                                } else {
    5430                                        while (it.hasNext()) {
    5431                                                long iax = it.aLong;
    5432                                                long ibx = it.bLong;
    5433                                                byte ox;
    5434                                                ox = (byte) (iax * ibx);
    5435                                                oai8data[it.oIndex] = ox;
    5436                                                for (int j = 1; j < is; j++) {
    5437                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5438                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5439                                                        ox = (byte) (iax * ibx);
    5440                                                        oai8data[it.oIndex + j] = ox;
    5441                                                }
    5442                                        }
    5443                                }
    5444                        }
    5445                        break;
    5446                case Dataset.ARRAYINT16:
    5447                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    5448                        if (is == 1) {
    5449                                if (it.isOutputDouble()) {
    5450                                        while (it.hasNext()) {
    5451                                                final double iax = it.aDouble;
    5452                                                final double ibx = it.bDouble;
    5453                                                short ox;
    5454                                                ox = (short) toLong(iax * ibx);
    5455                                                oai16data[it.oIndex] = ox;
    5456                                        }
    5457                                } else {
    5458                                        while (it.hasNext()) {
    5459                                                final long iax = it.aLong;
    5460                                                final long ibx = it.bLong;
    5461                                                short ox;
    5462                                                ox = (short) (iax * ibx);
    5463                                                oai16data[it.oIndex] = ox;
    5464                                        }
    5465                                }
    5466                        } else if (as < bs) {
    5467                                if (it.isOutputDouble()) {
    5468                                        while (it.hasNext()) {
    5469                                                final double iax = it.aDouble;
    5470                                                double ibx = it.bDouble;
    5471                                                short ox;
    5472                                                ox = (short) toLong(iax * ibx);
    5473                                                oai16data[it.oIndex] = ox;
    5474                                                for (int j = 1; j < is; j++) {
    5475                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5476                                                        ox = (short) toLong(iax * ibx);
    5477                                                        oai16data[it.oIndex + j] = ox;
    5478                                                }
    5479                                        }
    5480                                } else {
    5481                                        while (it.hasNext()) {
    5482                                                final long iax = it.aLong;
    5483                                                long ibx = it.bLong;
    5484                                                short ox;
    5485                                                ox = (short) (iax * ibx);
    5486                                                oai16data[it.oIndex] = ox;
    5487                                                for (int j = 1; j < is; j++) {
    5488                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5489                                                        ox = (short) (iax * ibx);
    5490                                                        oai16data[it.oIndex + j] = ox;
    5491                                                }
    5492                                        }
    5493                                }
    5494                        } else if (as > bs) {
    5495                                if (it.isOutputDouble()) {
    5496                                        while (it.hasNext()) {
    5497                                                double iax = it.aDouble;
    5498                                                final double ibx = it.bDouble;
    5499                                                short ox;
    5500                                                ox = (short) toLong(iax * ibx);
    5501                                                oai16data[it.oIndex] = ox;
    5502                                                for (int j = 1; j < is; j++) {
    5503                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5504                                                        ox = (short) toLong(iax * ibx);
    5505                                                        oai16data[it.oIndex + j] = ox;
    5506                                                }
    5507                                        }
    5508                                } else {
    5509                                        while (it.hasNext()) {
    5510                                                long iax = it.aLong;
    5511                                                final long ibx = it.bLong;
    5512                                                short ox;
    5513                                                ox = (short) (iax * ibx);
    5514                                                oai16data[it.oIndex] = ox;
    5515                                                for (int j = 1; j < is; j++) {
    5516                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5517                                                        ox = (short) (iax * ibx);
    5518                                                        oai16data[it.oIndex + j] = ox;
    5519                                                }
    5520                                        }
    5521                                }
    5522                        } else if (as == 1) {
    5523                                if (it.isOutputDouble()) {
    5524                                        while (it.hasNext()) {
    5525                                                final double iax = it.aDouble;
    5526                                                final double ibx = it.bDouble;
    5527                                                short ox;
    5528                                                ox = (short) toLong(iax * ibx);
    5529                                                for (int j = 0; j < is; j++) {
    5530                                                        oai16data[it.oIndex + j] = ox;
    5531                                                }
    5532                                        }
    5533                                } else {
    5534                                        while (it.hasNext()) {
    5535                                                final long iax = it.aLong;
    5536                                                final long ibx = it.bLong;
    5537                                                short ox;
    5538                                                ox = (short) (iax * ibx);
    5539                                                for (int j = 0; j < is; j++) {
    5540                                                        oai16data[it.oIndex + j] = ox;
    5541                                                }
    5542                                        }
    5543                                }
    5544                        } else {
    5545                                if (it.isOutputDouble()) {
    5546                                        while (it.hasNext()) {
    5547                                                double iax = it.aDouble;
    5548                                                double ibx = it.bDouble;
    5549                                                short ox;
    5550                                                ox = (short) toLong(iax * ibx);
    5551                                                oai16data[it.oIndex] = ox;
    5552                                                for (int j = 1; j < is; j++) {
    5553                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5554                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5555                                                        ox = (short) toLong(iax * ibx);
    5556                                                        oai16data[it.oIndex + j] = ox;
    5557                                                }
    5558                                        }
    5559                                } else {
    5560                                        while (it.hasNext()) {
    5561                                                long iax = it.aLong;
    5562                                                long ibx = it.bLong;
    5563                                                short ox;
    5564                                                ox = (short) (iax * ibx);
    5565                                                oai16data[it.oIndex] = ox;
    5566                                                for (int j = 1; j < is; j++) {
    5567                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5568                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5569                                                        ox = (short) (iax * ibx);
    5570                                                        oai16data[it.oIndex + j] = ox;
    5571                                                }
    5572                                        }
    5573                                }
    5574                        }
    5575                        break;
    5576                case Dataset.ARRAYINT64:
    5577                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    5578                        if (is == 1) {
    5579                                if (it.isOutputDouble()) {
    5580                                        while (it.hasNext()) {
    5581                                                final double iax = it.aDouble;
    5582                                                final double ibx = it.bDouble;
    5583                                                long ox;
    5584                                                ox = toLong(iax * ibx);
    5585                                                oai64data[it.oIndex] = ox;
    5586                                        }
    5587                                } else {
    5588                                        while (it.hasNext()) {
    5589                                                final long iax = it.aLong;
    5590                                                final long ibx = it.bLong;
    5591                                                long ox;
    5592                                                ox = (iax * ibx);
    5593                                                oai64data[it.oIndex] = ox;
    5594                                        }
    5595                                }
    5596                        } else if (as < bs) {
    5597                                if (it.isOutputDouble()) {
    5598                                        while (it.hasNext()) {
    5599                                                final double iax = it.aDouble;
    5600                                                double ibx = it.bDouble;
    5601                                                long ox;
    5602                                                ox = toLong(iax * ibx);
    5603                                                oai64data[it.oIndex] = ox;
    5604                                                for (int j = 1; j < is; j++) {
    5605                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5606                                                        ox = toLong(iax * ibx);
    5607                                                        oai64data[it.oIndex + j] = ox;
    5608                                                }
    5609                                        }
    5610                                } else {
    5611                                        while (it.hasNext()) {
    5612                                                final long iax = it.aLong;
    5613                                                long ibx = it.bLong;
    5614                                                long ox;
    5615                                                ox = (iax * ibx);
    5616                                                oai64data[it.oIndex] = ox;
    5617                                                for (int j = 1; j < is; j++) {
    5618                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5619                                                        ox = (iax * ibx);
    5620                                                        oai64data[it.oIndex + j] = ox;
    5621                                                }
    5622                                        }
    5623                                }
    5624                        } else if (as > bs) {
    5625                                if (it.isOutputDouble()) {
    5626                                        while (it.hasNext()) {
    5627                                                double iax = it.aDouble;
    5628                                                final double ibx = it.bDouble;
    5629                                                long ox;
    5630                                                ox = toLong(iax * ibx);
    5631                                                oai64data[it.oIndex] = ox;
    5632                                                for (int j = 1; j < is; j++) {
    5633                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5634                                                        ox = toLong(iax * ibx);
    5635                                                        oai64data[it.oIndex + j] = ox;
    5636                                                }
    5637                                        }
    5638                                } else {
    5639                                        while (it.hasNext()) {
    5640                                                long iax = it.aLong;
    5641                                                final long ibx = it.bLong;
    5642                                                long ox;
    5643                                                ox = (iax * ibx);
    5644                                                oai64data[it.oIndex] = ox;
    5645                                                for (int j = 1; j < is; j++) {
    5646                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5647                                                        ox = (iax * ibx);
    5648                                                        oai64data[it.oIndex + j] = ox;
    5649                                                }
    5650                                        }
    5651                                }
    5652                        } else if (as == 1) {
    5653                                if (it.isOutputDouble()) {
    5654                                        while (it.hasNext()) {
    5655                                                final double iax = it.aDouble;
    5656                                                final double ibx = it.bDouble;
    5657                                                long ox;
    5658                                                ox = toLong(iax * ibx);
    5659                                                for (int j = 0; j < is; j++) {
    5660                                                        oai64data[it.oIndex + j] = ox;
    5661                                                }
    5662                                        }
    5663                                } else {
    5664                                        while (it.hasNext()) {
    5665                                                final long iax = it.aLong;
    5666                                                final long ibx = it.bLong;
    5667                                                long ox;
    5668                                                ox = (iax * ibx);
    5669                                                for (int j = 0; j < is; j++) {
    5670                                                        oai64data[it.oIndex + j] = ox;
    5671                                                }
    5672                                        }
    5673                                }
    5674                        } else {
    5675                                if (it.isOutputDouble()) {
    5676                                        while (it.hasNext()) {
    5677                                                double iax = it.aDouble;
    5678                                                double ibx = it.bDouble;
    5679                                                long ox;
    5680                                                ox = toLong(iax * ibx);
    5681                                                oai64data[it.oIndex] = ox;
    5682                                                for (int j = 1; j < is; j++) {
    5683                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5684                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5685                                                        ox = toLong(iax * ibx);
    5686                                                        oai64data[it.oIndex + j] = ox;
    5687                                                }
    5688                                        }
    5689                                } else {
    5690                                        while (it.hasNext()) {
    5691                                                long iax = it.aLong;
    5692                                                long ibx = it.bLong;
    5693                                                long ox;
    5694                                                ox = (iax * ibx);
    5695                                                oai64data[it.oIndex] = ox;
    5696                                                for (int j = 1; j < is; j++) {
    5697                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5698                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5699                                                        ox = (iax * ibx);
    5700                                                        oai64data[it.oIndex + j] = ox;
    5701                                                }
    5702                                        }
    5703                                }
    5704                        }
    5705                        break;
    5706                case Dataset.ARRAYINT32:
    5707                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    5708                        if (is == 1) {
    5709                                if (it.isOutputDouble()) {
    5710                                        while (it.hasNext()) {
    5711                                                final double iax = it.aDouble;
    5712                                                final double ibx = it.bDouble;
    5713                                                int ox;
    5714                                                ox = (int) toLong(iax * ibx);
    5715                                                oai32data[it.oIndex] = ox;
    5716                                        }
    5717                                } else {
    5718                                        while (it.hasNext()) {
    5719                                                final long iax = it.aLong;
    5720                                                final long ibx = it.bLong;
    5721                                                int ox;
    5722                                                ox = (int) (iax * ibx);
    5723                                                oai32data[it.oIndex] = ox;
    5724                                        }
    5725                                }
    5726                        } else if (as < bs) {
    5727                                if (it.isOutputDouble()) {
    5728                                        while (it.hasNext()) {
    5729                                                final double iax = it.aDouble;
    5730                                                double ibx = it.bDouble;
    5731                                                int ox;
    5732                                                ox = (int) toLong(iax * ibx);
    5733                                                oai32data[it.oIndex] = ox;
    5734                                                for (int j = 1; j < is; j++) {
    5735                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5736                                                        ox = (int) toLong(iax * ibx);
    5737                                                        oai32data[it.oIndex + j] = ox;
    5738                                                }
    5739                                        }
    5740                                } else {
    5741                                        while (it.hasNext()) {
    5742                                                final long iax = it.aLong;
    5743                                                long ibx = it.bLong;
    5744                                                int ox;
    5745                                                ox = (int) (iax * ibx);
    5746                                                oai32data[it.oIndex] = ox;
    5747                                                for (int j = 1; j < is; j++) {
    5748                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5749                                                        ox = (int) (iax * ibx);
    5750                                                        oai32data[it.oIndex + j] = ox;
    5751                                                }
    5752                                        }
    5753                                }
    5754                        } else if (as > bs) {
    5755                                if (it.isOutputDouble()) {
    5756                                        while (it.hasNext()) {
    5757                                                double iax = it.aDouble;
    5758                                                final double ibx = it.bDouble;
    5759                                                int ox;
    5760                                                ox = (int) toLong(iax * ibx);
    5761                                                oai32data[it.oIndex] = ox;
    5762                                                for (int j = 1; j < is; j++) {
    5763                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5764                                                        ox = (int) toLong(iax * ibx);
    5765                                                        oai32data[it.oIndex + j] = ox;
    5766                                                }
    5767                                        }
    5768                                } else {
    5769                                        while (it.hasNext()) {
    5770                                                long iax = it.aLong;
    5771                                                final long ibx = it.bLong;
    5772                                                int ox;
    5773                                                ox = (int) (iax * ibx);
    5774                                                oai32data[it.oIndex] = ox;
    5775                                                for (int j = 1; j < is; j++) {
    5776                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5777                                                        ox = (int) (iax * ibx);
    5778                                                        oai32data[it.oIndex + j] = ox;
    5779                                                }
    5780                                        }
    5781                                }
    5782                        } else if (as == 1) {
    5783                                if (it.isOutputDouble()) {
    5784                                        while (it.hasNext()) {
    5785                                                final double iax = it.aDouble;
    5786                                                final double ibx = it.bDouble;
    5787                                                int ox;
    5788                                                ox = (int) toLong(iax * ibx);
    5789                                                for (int j = 0; j < is; j++) {
    5790                                                        oai32data[it.oIndex + j] = ox;
    5791                                                }
    5792                                        }
    5793                                } else {
    5794                                        while (it.hasNext()) {
    5795                                                final long iax = it.aLong;
    5796                                                final long ibx = it.bLong;
    5797                                                int ox;
    5798                                                ox = (int) (iax * ibx);
    5799                                                for (int j = 0; j < is; j++) {
    5800                                                        oai32data[it.oIndex + j] = ox;
    5801                                                }
    5802                                        }
    5803                                }
    5804                        } else {
    5805                                if (it.isOutputDouble()) {
    5806                                        while (it.hasNext()) {
    5807                                                double iax = it.aDouble;
    5808                                                double ibx = it.bDouble;
    5809                                                int ox;
    5810                                                ox = (int) toLong(iax * ibx);
    5811                                                oai32data[it.oIndex] = ox;
    5812                                                for (int j = 1; j < is; j++) {
    5813                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5814                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5815                                                        ox = (int) toLong(iax * ibx);
    5816                                                        oai32data[it.oIndex + j] = ox;
    5817                                                }
    5818                                        }
    5819                                } else {
    5820                                        while (it.hasNext()) {
    5821                                                long iax = it.aLong;
    5822                                                long ibx = it.bLong;
    5823                                                int ox;
    5824                                                ox = (int) (iax * ibx);
    5825                                                oai32data[it.oIndex] = ox;
    5826                                                for (int j = 1; j < is; j++) {
    5827                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5828                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5829                                                        ox = (int) (iax * ibx);
    5830                                                        oai32data[it.oIndex + j] = ox;
    5831                                                }
    5832                                        }
    5833                                }
    5834                        }
    5835                        break;
    5836                case Dataset.FLOAT32:
    5837                        final float[] of32data = ((FloatDataset) result).getData();
    5838                        if (it.isOutputDouble()) {
    5839                                while (it.hasNext()) {
    5840                                        final double iax = it.aDouble;
    5841                                        final double ibx = it.bDouble;
    5842                                        float ox;
    5843                                        ox = (float) (iax * ibx);
    5844                                        of32data[it.oIndex] = ox;
    5845                                }
    5846                        } else {
    5847                                while (it.hasNext()) {
    5848                                        final long iax = it.aLong;
    5849                                        final long ibx = it.bLong;
    5850                                        float ox;
    5851                                        ox = (iax * ibx);
    5852                                        of32data[it.oIndex] = ox;
    5853                                }
    5854                        }
    5855                        break;
    5856                case Dataset.FLOAT64:
    5857                        final double[] of64data = ((DoubleDataset) result).getData();
    5858                        if (it.isOutputDouble()) {
    5859                                while (it.hasNext()) {
    5860                                        final double iax = it.aDouble;
    5861                                        final double ibx = it.bDouble;
    5862                                        double ox;
    5863                                        ox = (iax * ibx);
    5864                                        of64data[it.oIndex] = ox;
    5865                                }
    5866                        } else {
    5867                                while (it.hasNext()) {
    5868                                        final long iax = it.aLong;
    5869                                        final long ibx = it.bLong;
    5870                                        double ox;
    5871                                        ox = (iax * ibx);
    5872                                        of64data[it.oIndex] = ox;
    5873                                }
    5874                        }
    5875                        break;
    5876                case Dataset.ARRAYFLOAT32:
    5877                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    5878                        if (is == 1) {
    5879                                if (it.isOutputDouble()) {
    5880                                        while (it.hasNext()) {
    5881                                                final double iax = it.aDouble;
    5882                                                final double ibx = it.bDouble;
    5883                                                float ox;
    5884                                                ox = (float) (iax * ibx);
    5885                                                oaf32data[it.oIndex] = ox;
    5886                                        }
    5887                                } else {
    5888                                        while (it.hasNext()) {
    5889                                                final long iax = it.aLong;
    5890                                                final long ibx = it.bLong;
    5891                                                float ox;
    5892                                                ox = (iax * ibx);
    5893                                                oaf32data[it.oIndex] = ox;
    5894                                        }
    5895                                }
    5896                        } else if (as < bs) {
    5897                                if (it.isOutputDouble()) {
    5898                                        while (it.hasNext()) {
    5899                                                final double iax = it.aDouble;
    5900                                                double ibx = it.bDouble;
    5901                                                float ox;
    5902                                                ox = (float) (iax * ibx);
    5903                                                oaf32data[it.oIndex] = ox;
    5904                                                for (int j = 1; j < is; j++) {
    5905                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5906                                                        ox = (float) (iax * ibx);
    5907                                                        oaf32data[it.oIndex + j] = ox;
    5908                                                }
    5909                                        }
    5910                                } else {
    5911                                        while (it.hasNext()) {
    5912                                                final long iax = it.aLong;
    5913                                                long ibx = it.bLong;
    5914                                                float ox;
    5915                                                ox = (iax * ibx);
    5916                                                oaf32data[it.oIndex] = ox;
    5917                                                for (int j = 1; j < is; j++) {
    5918                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5919                                                        ox = (iax * ibx);
    5920                                                        oaf32data[it.oIndex + j] = ox;
    5921                                                }
    5922                                        }
    5923                                }
    5924                        } else if (as > bs) {
    5925                                if (it.isOutputDouble()) {
    5926                                        while (it.hasNext()) {
    5927                                                double iax = it.aDouble;
    5928                                                final double ibx = it.bDouble;
    5929                                                float ox;
    5930                                                ox = (float) (iax * ibx);
    5931                                                oaf32data[it.oIndex] = ox;
    5932                                                for (int j = 1; j < is; j++) {
    5933                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5934                                                        ox = (float) (iax * ibx);
    5935                                                        oaf32data[it.oIndex + j] = ox;
    5936                                                }
    5937                                        }
    5938                                } else {
    5939                                        while (it.hasNext()) {
    5940                                                long iax = it.aLong;
    5941                                                final long ibx = it.bLong;
    5942                                                float ox;
    5943                                                ox = (iax * ibx);
    5944                                                oaf32data[it.oIndex] = ox;
    5945                                                for (int j = 1; j < is; j++) {
    5946                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5947                                                        ox = (iax * ibx);
    5948                                                        oaf32data[it.oIndex + j] = ox;
    5949                                                }
    5950                                        }
    5951                                }
    5952                        } else if (as == 1) {
    5953                                if (it.isOutputDouble()) {
    5954                                        while (it.hasNext()) {
    5955                                                final double iax = it.aDouble;
    5956                                                final double ibx = it.bDouble;
    5957                                                float ox;
    5958                                                ox = (float) (iax * ibx);
    5959                                                for (int j = 0; j < is; j++) {
    5960                                                        oaf32data[it.oIndex + j] = ox;
    5961                                                }
    5962                                        }
    5963                                } else {
    5964                                        while (it.hasNext()) {
    5965                                                final long iax = it.aLong;
    5966                                                final long ibx = it.bLong;
    5967                                                float ox;
    5968                                                ox = (iax * ibx);
    5969                                                for (int j = 0; j < is; j++) {
    5970                                                        oaf32data[it.oIndex + j] = ox;
    5971                                                }
    5972                                        }
    5973                                }
    5974                        } else {
    5975                                if (it.isOutputDouble()) {
    5976                                        while (it.hasNext()) {
    5977                                                double iax = it.aDouble;
    5978                                                double ibx = it.bDouble;
    5979                                                float ox;
    5980                                                ox = (float) (iax * ibx);
    5981                                                oaf32data[it.oIndex] = ox;
    5982                                                for (int j = 1; j < is; j++) {
    5983                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    5984                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    5985                                                        ox = (float) (iax * ibx);
    5986                                                        oaf32data[it.oIndex + j] = ox;
    5987                                                }
    5988                                        }
    5989                                } else {
    5990                                        while (it.hasNext()) {
    5991                                                long iax = it.aLong;
    5992                                                long ibx = it.bLong;
    5993                                                float ox;
    5994                                                ox = (iax * ibx);
    5995                                                oaf32data[it.oIndex] = ox;
    5996                                                for (int j = 1; j < is; j++) {
    5997                                                        iax = da.getElementLongAbs(it.aIndex + j);
    5998                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    5999                                                        ox = (iax * ibx);
    6000                                                        oaf32data[it.oIndex + j] = ox;
    6001                                                }
    6002                                        }
    6003                                }
    6004                        }
    6005                        break;
    6006                case Dataset.ARRAYFLOAT64:
    6007                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    6008                        if (is == 1) {
    6009                                if (it.isOutputDouble()) {
    6010                                        while (it.hasNext()) {
    6011                                                final double iax = it.aDouble;
    6012                                                final double ibx = it.bDouble;
    6013                                                double ox;
    6014                                                ox = (iax * ibx);
    6015                                                oaf64data[it.oIndex] = ox;
    6016                                        }
    6017                                } else {
    6018                                        while (it.hasNext()) {
    6019                                                final long iax = it.aLong;
    6020                                                final long ibx = it.bLong;
    6021                                                double ox;
    6022                                                ox = (iax * ibx);
    6023                                                oaf64data[it.oIndex] = ox;
    6024                                        }
    6025                                }
    6026                        } else if (as < bs) {
    6027                                if (it.isOutputDouble()) {
    6028                                        while (it.hasNext()) {
    6029                                                final double iax = it.aDouble;
    6030                                                double ibx = it.bDouble;
    6031                                                double ox;
    6032                                                ox = (iax * ibx);
    6033                                                oaf64data[it.oIndex] = ox;
    6034                                                for (int j = 1; j < is; j++) {
    6035                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6036                                                        ox = (iax * ibx);
    6037                                                        oaf64data[it.oIndex + j] = ox;
    6038                                                }
    6039                                        }
    6040                                } else {
    6041                                        while (it.hasNext()) {
    6042                                                final long iax = it.aLong;
    6043                                                long ibx = it.bLong;
    6044                                                double ox;
    6045                                                ox = (iax * ibx);
    6046                                                oaf64data[it.oIndex] = ox;
    6047                                                for (int j = 1; j < is; j++) {
    6048                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6049                                                        ox = (iax * ibx);
    6050                                                        oaf64data[it.oIndex + j] = ox;
    6051                                                }
    6052                                        }
    6053                                }
    6054                        } else if (as > bs) {
    6055                                if (it.isOutputDouble()) {
    6056                                        while (it.hasNext()) {
    6057                                                double iax = it.aDouble;
    6058                                                final double ibx = it.bDouble;
    6059                                                double ox;
    6060                                                ox = (iax * ibx);
    6061                                                oaf64data[it.oIndex] = ox;
    6062                                                for (int j = 1; j < is; j++) {
    6063                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6064                                                        ox = (iax * ibx);
    6065                                                        oaf64data[it.oIndex + j] = ox;
    6066                                                }
    6067                                        }
    6068                                } else {
    6069                                        while (it.hasNext()) {
    6070                                                long iax = it.aLong;
    6071                                                final long ibx = it.bLong;
    6072                                                double ox;
    6073                                                ox = (iax * ibx);
    6074                                                oaf64data[it.oIndex] = ox;
    6075                                                for (int j = 1; j < is; j++) {
    6076                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6077                                                        ox = (iax * ibx);
    6078                                                        oaf64data[it.oIndex + j] = ox;
    6079                                                }
    6080                                        }
    6081                                }
    6082                        } else if (as == 1) {
    6083                                if (it.isOutputDouble()) {
    6084                                        while (it.hasNext()) {
    6085                                                final double iax = it.aDouble;
    6086                                                final double ibx = it.bDouble;
    6087                                                double ox;
    6088                                                ox = (iax * ibx);
    6089                                                for (int j = 0; j < is; j++) {
    6090                                                        oaf64data[it.oIndex + j] = ox;
    6091                                                }
    6092                                        }
    6093                                } else {
    6094                                        while (it.hasNext()) {
    6095                                                final long iax = it.aLong;
    6096                                                final long ibx = it.bLong;
    6097                                                double ox;
    6098                                                ox = (iax * ibx);
    6099                                                for (int j = 0; j < is; j++) {
    6100                                                        oaf64data[it.oIndex + j] = ox;
    6101                                                }
    6102                                        }
    6103                                }
    6104                        } else {
    6105                                if (it.isOutputDouble()) {
    6106                                        while (it.hasNext()) {
    6107                                                double iax = it.aDouble;
    6108                                                double ibx = it.bDouble;
    6109                                                double ox;
    6110                                                ox = (iax * ibx);
    6111                                                oaf64data[it.oIndex] = ox;
    6112                                                for (int j = 1; j < is; j++) {
    6113                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6114                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6115                                                        ox = (iax * ibx);
    6116                                                        oaf64data[it.oIndex + j] = ox;
    6117                                                }
    6118                                        }
    6119                                } else {
    6120                                        while (it.hasNext()) {
    6121                                                long iax = it.aLong;
    6122                                                long ibx = it.bLong;
    6123                                                double ox;
    6124                                                ox = (iax * ibx);
    6125                                                oaf64data[it.oIndex] = ox;
    6126                                                for (int j = 1; j < is; j++) {
    6127                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6128                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6129                                                        ox = (iax * ibx);
    6130                                                        oaf64data[it.oIndex + j] = ox;
    6131                                                }
    6132                                        }
    6133                                }
    6134                        }
    6135                        break;
    6136                case Dataset.COMPLEX64:
    6137                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    6138                        if (as == 1) {
    6139                                final double iay = 0;
    6140                                while (it.hasNext()) {
    6141                                        final double iax = it.aDouble;
    6142                                        final double ibx = it.bDouble;
    6143                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    6144                                        float ox;
    6145                                        float oy;
    6146                                        ox = (float) (iax * ibx - iay * iby);
    6147                                        oy = (float) (iax * iby + iay * ibx);
    6148                                        oc64data[it.oIndex] = ox;
    6149                                        oc64data[it.oIndex + 1] = oy;
    6150                                }
    6151                        } else if (bs == 1) {
    6152                                final double iby = 0;
    6153                                while (it.hasNext()) {
    6154                                        final double iax = it.aDouble;
    6155                                        final double ibx = it.bDouble;
    6156                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    6157                                        float ox;
    6158                                        float oy;
    6159                                        ox = (float) (iax * ibx - iay * iby);
    6160                                        oy = (float) (iax * iby + iay * ibx);
    6161                                        oc64data[it.oIndex] = ox;
    6162                                        oc64data[it.oIndex + 1] = oy;
    6163                                }
    6164                        } else {
    6165                                while (it.hasNext()) {
    6166                                        final double iax = it.aDouble;
    6167                                        final double ibx = it.bDouble;
    6168                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    6169                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    6170                                        float ox;
    6171                                        float oy;
    6172                                        ox = (float) (iax * ibx - iay * iby);
    6173                                        oy = (float) (iax * iby + iay * ibx);
    6174                                        oc64data[it.oIndex] = ox;
    6175                                        oc64data[it.oIndex + 1] = oy;
    6176                                }
    6177                        }
    6178                        break;
    6179                case Dataset.COMPLEX128:
    6180                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    6181                        if (as == 1) {
    6182                                final double iay = 0;
    6183                                while (it.hasNext()) {
    6184                                        final double iax = it.aDouble;
    6185                                        final double ibx = it.bDouble;
    6186                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    6187                                        double ox;
    6188                                        double oy;
    6189                                        ox = (iax * ibx - iay * iby);
    6190                                        oy = (iax * iby + iay * ibx);
    6191                                        oc128data[it.oIndex] = ox;
    6192                                        oc128data[it.oIndex + 1] = oy;
    6193                                }
    6194                        } else if (bs == 1) {
    6195                                final double iby = 0;
    6196                                while (it.hasNext()) {
    6197                                        final double iax = it.aDouble;
    6198                                        final double ibx = it.bDouble;
    6199                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    6200                                        double ox;
    6201                                        double oy;
    6202                                        ox = (iax * ibx - iay * iby);
    6203                                        oy = (iax * iby + iay * ibx);
    6204                                        oc128data[it.oIndex] = ox;
    6205                                        oc128data[it.oIndex + 1] = oy;
    6206                                }
    6207                        } else {
    6208                                while (it.hasNext()) {
    6209                                        final double iax = it.aDouble;
    6210                                        final double ibx = it.bDouble;
    6211                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    6212                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    6213                                        double ox;
    6214                                        double oy;
    6215                                        ox = (iax * ibx - iay * iby);
    6216                                        oy = (iax * iby + iay * ibx);
    6217                                        oc128data[it.oIndex] = ox;
    6218                                        oc128data[it.oIndex + 1] = oy;
    6219                                }
    6220                        }
    6221                        break;
    6222                default:
    6223                        throw new IllegalArgumentException("multiply supports integer, compound integer, real, compound real, complex datasets only");
    6224                }
    6225
    6226                addBinaryOperatorName(da, db, result, "*");
    6227                return result;
    6228        }
    6229
    6230        /**
    6231         * divide operator
    6232         * @param a
    6233         * @param b
    6234         * @return {@code a / b}, division of a by b
    6235         */
    6236        public static Dataset divide(final Object a, final Object b) {
    6237                return divide(a, b, null);
    6238        }
    6239
    6240        /**
    6241         * divide operator
    6242         * @param a
    6243         * @param b
    6244         * @param o output can be null - in which case, a new dataset is created
    6245         * @return {@code a / b}, division of a by b
    6246         */
    6247        public static Dataset divide(final Object a, final Object b, final Dataset o) {
    6248                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    6249                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    6250                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    6251                final Dataset result = it.getOutput();
    6252                final int is = result.getElementsPerItem();
    6253                final int as = da.getElementsPerItem();
    6254                final int bs = db.getElementsPerItem();
    6255                final int dt = result.getDType();
    6256
    6257                switch(dt) {
    6258                case Dataset.INT8:
    6259                        final byte[] oi8data = ((ByteDataset) result).getData();
    6260                        if (it.isOutputDouble()) {
    6261                                while (it.hasNext()) {
    6262                                        final double iax = it.aDouble;
    6263                                        final double ibx = it.bDouble;
    6264                                        byte ox;
    6265                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6266                                        oi8data[it.oIndex] = ox;
    6267                                }
    6268                        } else {
    6269                                while (it.hasNext()) {
    6270                                        final long iax = it.aLong;
    6271                                        final long ibx = it.bLong;
    6272                                        byte ox;
    6273                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6274                                        oi8data[it.oIndex] = ox;
    6275                                }
    6276                        }
    6277                        break;
    6278                case Dataset.INT16:
    6279                        final short[] oi16data = ((ShortDataset) result).getData();
    6280                        if (it.isOutputDouble()) {
    6281                                while (it.hasNext()) {
    6282                                        final double iax = it.aDouble;
    6283                                        final double ibx = it.bDouble;
    6284                                        short ox;
    6285                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6286                                        oi16data[it.oIndex] = ox;
    6287                                }
    6288                        } else {
    6289                                while (it.hasNext()) {
    6290                                        final long iax = it.aLong;
    6291                                        final long ibx = it.bLong;
    6292                                        short ox;
    6293                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6294                                        oi16data[it.oIndex] = ox;
    6295                                }
    6296                        }
    6297                        break;
    6298                case Dataset.INT64:
    6299                        final long[] oi64data = ((LongDataset) result).getData();
    6300                        if (it.isOutputDouble()) {
    6301                                while (it.hasNext()) {
    6302                                        final double iax = it.aDouble;
    6303                                        final double ibx = it.bDouble;
    6304                                        long ox;
    6305                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6306                                        oi64data[it.oIndex] = ox;
    6307                                }
    6308                        } else {
    6309                                while (it.hasNext()) {
    6310                                        final long iax = it.aLong;
    6311                                        final long ibx = it.bLong;
    6312                                        long ox;
    6313                                        ox = (ibx == 0 ? 0 : iax / ibx);
    6314                                        oi64data[it.oIndex] = ox;
    6315                                }
    6316                        }
    6317                        break;
    6318                case Dataset.INT32:
    6319                        final int[] oi32data = ((IntegerDataset) result).getData();
    6320                        if (it.isOutputDouble()) {
    6321                                while (it.hasNext()) {
    6322                                        final double iax = it.aDouble;
    6323                                        final double ibx = it.bDouble;
    6324                                        int ox;
    6325                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6326                                        oi32data[it.oIndex] = ox;
    6327                                }
    6328                        } else {
    6329                                while (it.hasNext()) {
    6330                                        final long iax = it.aLong;
    6331                                        final long ibx = it.bLong;
    6332                                        int ox;
    6333                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6334                                        oi32data[it.oIndex] = ox;
    6335                                }
    6336                        }
    6337                        break;
    6338                case Dataset.ARRAYINT8:
    6339                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    6340                        if (is == 1) {
    6341                                if (it.isOutputDouble()) {
    6342                                        while (it.hasNext()) {
    6343                                                final double iax = it.aDouble;
    6344                                                final double ibx = it.bDouble;
    6345                                                byte ox;
    6346                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6347                                                oai8data[it.oIndex] = ox;
    6348                                        }
    6349                                } else {
    6350                                        while (it.hasNext()) {
    6351                                                final long iax = it.aLong;
    6352                                                final long ibx = it.bLong;
    6353                                                byte ox;
    6354                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6355                                                oai8data[it.oIndex] = ox;
    6356                                        }
    6357                                }
    6358                        } else if (as < bs) {
    6359                                if (it.isOutputDouble()) {
    6360                                        while (it.hasNext()) {
    6361                                                final double iax = it.aDouble;
    6362                                                double ibx = it.bDouble;
    6363                                                byte ox;
    6364                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6365                                                oai8data[it.oIndex] = ox;
    6366                                                for (int j = 1; j < is; j++) {
    6367                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6368                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6369                                                        oai8data[it.oIndex + j] = ox;
    6370                                                }
    6371                                        }
    6372                                } else {
    6373                                        while (it.hasNext()) {
    6374                                                final long iax = it.aLong;
    6375                                                long ibx = it.bLong;
    6376                                                byte ox;
    6377                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6378                                                oai8data[it.oIndex] = ox;
    6379                                                for (int j = 1; j < is; j++) {
    6380                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6381                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6382                                                        oai8data[it.oIndex + j] = ox;
    6383                                                }
    6384                                        }
    6385                                }
    6386                        } else if (as > bs) {
    6387                                if (it.isOutputDouble()) {
    6388                                        while (it.hasNext()) {
    6389                                                double iax = it.aDouble;
    6390                                                final double ibx = it.bDouble;
    6391                                                byte ox;
    6392                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6393                                                oai8data[it.oIndex] = ox;
    6394                                                for (int j = 1; j < is; j++) {
    6395                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6396                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6397                                                        oai8data[it.oIndex + j] = ox;
    6398                                                }
    6399                                        }
    6400                                } else {
    6401                                        while (it.hasNext()) {
    6402                                                long iax = it.aLong;
    6403                                                final long ibx = it.bLong;
    6404                                                byte ox;
    6405                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6406                                                oai8data[it.oIndex] = ox;
    6407                                                for (int j = 1; j < is; j++) {
    6408                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6409                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6410                                                        oai8data[it.oIndex + j] = ox;
    6411                                                }
    6412                                        }
    6413                                }
    6414                        } else if (as == 1) {
    6415                                if (it.isOutputDouble()) {
    6416                                        while (it.hasNext()) {
    6417                                                final double iax = it.aDouble;
    6418                                                final double ibx = it.bDouble;
    6419                                                byte ox;
    6420                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6421                                                for (int j = 0; j < is; j++) {
    6422                                                        oai8data[it.oIndex + j] = ox;
    6423                                                }
    6424                                        }
    6425                                } else {
    6426                                        while (it.hasNext()) {
    6427                                                final long iax = it.aLong;
    6428                                                final long ibx = it.bLong;
    6429                                                byte ox;
    6430                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6431                                                for (int j = 0; j < is; j++) {
    6432                                                        oai8data[it.oIndex + j] = ox;
    6433                                                }
    6434                                        }
    6435                                }
    6436                        } else {
    6437                                if (it.isOutputDouble()) {
    6438                                        while (it.hasNext()) {
    6439                                                double iax = it.aDouble;
    6440                                                double ibx = it.bDouble;
    6441                                                byte ox;
    6442                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6443                                                oai8data[it.oIndex] = ox;
    6444                                                for (int j = 1; j < is; j++) {
    6445                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6446                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6447                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    6448                                                        oai8data[it.oIndex + j] = ox;
    6449                                                }
    6450                                        }
    6451                                } else {
    6452                                        while (it.hasNext()) {
    6453                                                long iax = it.aLong;
    6454                                                long ibx = it.bLong;
    6455                                                byte ox;
    6456                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6457                                                oai8data[it.oIndex] = ox;
    6458                                                for (int j = 1; j < is; j++) {
    6459                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6460                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6461                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    6462                                                        oai8data[it.oIndex + j] = ox;
    6463                                                }
    6464                                        }
    6465                                }
    6466                        }
    6467                        break;
    6468                case Dataset.ARRAYINT16:
    6469                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    6470                        if (is == 1) {
    6471                                if (it.isOutputDouble()) {
    6472                                        while (it.hasNext()) {
    6473                                                final double iax = it.aDouble;
    6474                                                final double ibx = it.bDouble;
    6475                                                short ox;
    6476                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6477                                                oai16data[it.oIndex] = ox;
    6478                                        }
    6479                                } else {
    6480                                        while (it.hasNext()) {
    6481                                                final long iax = it.aLong;
    6482                                                final long ibx = it.bLong;
    6483                                                short ox;
    6484                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6485                                                oai16data[it.oIndex] = ox;
    6486                                        }
    6487                                }
    6488                        } else if (as < bs) {
    6489                                if (it.isOutputDouble()) {
    6490                                        while (it.hasNext()) {
    6491                                                final double iax = it.aDouble;
    6492                                                double ibx = it.bDouble;
    6493                                                short ox;
    6494                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6495                                                oai16data[it.oIndex] = ox;
    6496                                                for (int j = 1; j < is; j++) {
    6497                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6498                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6499                                                        oai16data[it.oIndex + j] = ox;
    6500                                                }
    6501                                        }
    6502                                } else {
    6503                                        while (it.hasNext()) {
    6504                                                final long iax = it.aLong;
    6505                                                long ibx = it.bLong;
    6506                                                short ox;
    6507                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6508                                                oai16data[it.oIndex] = ox;
    6509                                                for (int j = 1; j < is; j++) {
    6510                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6511                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6512                                                        oai16data[it.oIndex + j] = ox;
    6513                                                }
    6514                                        }
    6515                                }
    6516                        } else if (as > bs) {
    6517                                if (it.isOutputDouble()) {
    6518                                        while (it.hasNext()) {
    6519                                                double iax = it.aDouble;
    6520                                                final double ibx = it.bDouble;
    6521                                                short ox;
    6522                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6523                                                oai16data[it.oIndex] = ox;
    6524                                                for (int j = 1; j < is; j++) {
    6525                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6526                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6527                                                        oai16data[it.oIndex + j] = ox;
    6528                                                }
    6529                                        }
    6530                                } else {
    6531                                        while (it.hasNext()) {
    6532                                                long iax = it.aLong;
    6533                                                final long ibx = it.bLong;
    6534                                                short ox;
    6535                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6536                                                oai16data[it.oIndex] = ox;
    6537                                                for (int j = 1; j < is; j++) {
    6538                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6539                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6540                                                        oai16data[it.oIndex + j] = ox;
    6541                                                }
    6542                                        }
    6543                                }
    6544                        } else if (as == 1) {
    6545                                if (it.isOutputDouble()) {
    6546                                        while (it.hasNext()) {
    6547                                                final double iax = it.aDouble;
    6548                                                final double ibx = it.bDouble;
    6549                                                short ox;
    6550                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6551                                                for (int j = 0; j < is; j++) {
    6552                                                        oai16data[it.oIndex + j] = ox;
    6553                                                }
    6554                                        }
    6555                                } else {
    6556                                        while (it.hasNext()) {
    6557                                                final long iax = it.aLong;
    6558                                                final long ibx = it.bLong;
    6559                                                short ox;
    6560                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6561                                                for (int j = 0; j < is; j++) {
    6562                                                        oai16data[it.oIndex + j] = ox;
    6563                                                }
    6564                                        }
    6565                                }
    6566                        } else {
    6567                                if (it.isOutputDouble()) {
    6568                                        while (it.hasNext()) {
    6569                                                double iax = it.aDouble;
    6570                                                double ibx = it.bDouble;
    6571                                                short ox;
    6572                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6573                                                oai16data[it.oIndex] = ox;
    6574                                                for (int j = 1; j < is; j++) {
    6575                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6576                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6577                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    6578                                                        oai16data[it.oIndex + j] = ox;
    6579                                                }
    6580                                        }
    6581                                } else {
    6582                                        while (it.hasNext()) {
    6583                                                long iax = it.aLong;
    6584                                                long ibx = it.bLong;
    6585                                                short ox;
    6586                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6587                                                oai16data[it.oIndex] = ox;
    6588                                                for (int j = 1; j < is; j++) {
    6589                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6590                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6591                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    6592                                                        oai16data[it.oIndex + j] = ox;
    6593                                                }
    6594                                        }
    6595                                }
    6596                        }
    6597                        break;
    6598                case Dataset.ARRAYINT64:
    6599                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    6600                        if (is == 1) {
    6601                                if (it.isOutputDouble()) {
    6602                                        while (it.hasNext()) {
    6603                                                final double iax = it.aDouble;
    6604                                                final double ibx = it.bDouble;
    6605                                                long ox;
    6606                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6607                                                oai64data[it.oIndex] = ox;
    6608                                        }
    6609                                } else {
    6610                                        while (it.hasNext()) {
    6611                                                final long iax = it.aLong;
    6612                                                final long ibx = it.bLong;
    6613                                                long ox;
    6614                                                ox = (ibx == 0 ? 0 : iax / ibx);
    6615                                                oai64data[it.oIndex] = ox;
    6616                                        }
    6617                                }
    6618                        } else if (as < bs) {
    6619                                if (it.isOutputDouble()) {
    6620                                        while (it.hasNext()) {
    6621                                                final double iax = it.aDouble;
    6622                                                double ibx = it.bDouble;
    6623                                                long ox;
    6624                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6625                                                oai64data[it.oIndex] = ox;
    6626                                                for (int j = 1; j < is; j++) {
    6627                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6628                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6629                                                        oai64data[it.oIndex + j] = ox;
    6630                                                }
    6631                                        }
    6632                                } else {
    6633                                        while (it.hasNext()) {
    6634                                                final long iax = it.aLong;
    6635                                                long ibx = it.bLong;
    6636                                                long ox;
    6637                                                ox = (ibx == 0 ? 0 : iax / ibx);
    6638                                                oai64data[it.oIndex] = ox;
    6639                                                for (int j = 1; j < is; j++) {
    6640                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6641                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    6642                                                        oai64data[it.oIndex + j] = ox;
    6643                                                }
    6644                                        }
    6645                                }
    6646                        } else if (as > bs) {
    6647                                if (it.isOutputDouble()) {
    6648                                        while (it.hasNext()) {
    6649                                                double iax = it.aDouble;
    6650                                                final double ibx = it.bDouble;
    6651                                                long ox;
    6652                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6653                                                oai64data[it.oIndex] = ox;
    6654                                                for (int j = 1; j < is; j++) {
    6655                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6656                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6657                                                        oai64data[it.oIndex + j] = ox;
    6658                                                }
    6659                                        }
    6660                                } else {
    6661                                        while (it.hasNext()) {
    6662                                                long iax = it.aLong;
    6663                                                final long ibx = it.bLong;
    6664                                                long ox;
    6665                                                ox = (ibx == 0 ? 0 : iax / ibx);
    6666                                                oai64data[it.oIndex] = ox;
    6667                                                for (int j = 1; j < is; j++) {
    6668                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6669                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    6670                                                        oai64data[it.oIndex + j] = ox;
    6671                                                }
    6672                                        }
    6673                                }
    6674                        } else if (as == 1) {
    6675                                if (it.isOutputDouble()) {
    6676                                        while (it.hasNext()) {
    6677                                                final double iax = it.aDouble;
    6678                                                final double ibx = it.bDouble;
    6679                                                long ox;
    6680                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6681                                                for (int j = 0; j < is; j++) {
    6682                                                        oai64data[it.oIndex + j] = ox;
    6683                                                }
    6684                                        }
    6685                                } else {
    6686                                        while (it.hasNext()) {
    6687                                                final long iax = it.aLong;
    6688                                                final long ibx = it.bLong;
    6689                                                long ox;
    6690                                                ox = (ibx == 0 ? 0 : iax / ibx);
    6691                                                for (int j = 0; j < is; j++) {
    6692                                                        oai64data[it.oIndex + j] = ox;
    6693                                                }
    6694                                        }
    6695                                }
    6696                        } else {
    6697                                if (it.isOutputDouble()) {
    6698                                        while (it.hasNext()) {
    6699                                                double iax = it.aDouble;
    6700                                                double ibx = it.bDouble;
    6701                                                long ox;
    6702                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6703                                                oai64data[it.oIndex] = ox;
    6704                                                for (int j = 1; j < is; j++) {
    6705                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6706                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6707                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    6708                                                        oai64data[it.oIndex + j] = ox;
    6709                                                }
    6710                                        }
    6711                                } else {
    6712                                        while (it.hasNext()) {
    6713                                                long iax = it.aLong;
    6714                                                long ibx = it.bLong;
    6715                                                long ox;
    6716                                                ox = (ibx == 0 ? 0 : iax / ibx);
    6717                                                oai64data[it.oIndex] = ox;
    6718                                                for (int j = 1; j < is; j++) {
    6719                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6720                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6721                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    6722                                                        oai64data[it.oIndex + j] = ox;
    6723                                                }
    6724                                        }
    6725                                }
    6726                        }
    6727                        break;
    6728                case Dataset.ARRAYINT32:
    6729                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    6730                        if (is == 1) {
    6731                                if (it.isOutputDouble()) {
    6732                                        while (it.hasNext()) {
    6733                                                final double iax = it.aDouble;
    6734                                                final double ibx = it.bDouble;
    6735                                                int ox;
    6736                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6737                                                oai32data[it.oIndex] = ox;
    6738                                        }
    6739                                } else {
    6740                                        while (it.hasNext()) {
    6741                                                final long iax = it.aLong;
    6742                                                final long ibx = it.bLong;
    6743                                                int ox;
    6744                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6745                                                oai32data[it.oIndex] = ox;
    6746                                        }
    6747                                }
    6748                        } else if (as < bs) {
    6749                                if (it.isOutputDouble()) {
    6750                                        while (it.hasNext()) {
    6751                                                final double iax = it.aDouble;
    6752                                                double ibx = it.bDouble;
    6753                                                int ox;
    6754                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6755                                                oai32data[it.oIndex] = ox;
    6756                                                for (int j = 1; j < is; j++) {
    6757                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6758                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6759                                                        oai32data[it.oIndex + j] = ox;
    6760                                                }
    6761                                        }
    6762                                } else {
    6763                                        while (it.hasNext()) {
    6764                                                final long iax = it.aLong;
    6765                                                long ibx = it.bLong;
    6766                                                int ox;
    6767                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6768                                                oai32data[it.oIndex] = ox;
    6769                                                for (int j = 1; j < is; j++) {
    6770                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6771                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6772                                                        oai32data[it.oIndex + j] = ox;
    6773                                                }
    6774                                        }
    6775                                }
    6776                        } else if (as > bs) {
    6777                                if (it.isOutputDouble()) {
    6778                                        while (it.hasNext()) {
    6779                                                double iax = it.aDouble;
    6780                                                final double ibx = it.bDouble;
    6781                                                int ox;
    6782                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6783                                                oai32data[it.oIndex] = ox;
    6784                                                for (int j = 1; j < is; j++) {
    6785                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6786                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6787                                                        oai32data[it.oIndex + j] = ox;
    6788                                                }
    6789                                        }
    6790                                } else {
    6791                                        while (it.hasNext()) {
    6792                                                long iax = it.aLong;
    6793                                                final long ibx = it.bLong;
    6794                                                int ox;
    6795                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6796                                                oai32data[it.oIndex] = ox;
    6797                                                for (int j = 1; j < is; j++) {
    6798                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6799                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6800                                                        oai32data[it.oIndex + j] = ox;
    6801                                                }
    6802                                        }
    6803                                }
    6804                        } else if (as == 1) {
    6805                                if (it.isOutputDouble()) {
    6806                                        while (it.hasNext()) {
    6807                                                final double iax = it.aDouble;
    6808                                                final double ibx = it.bDouble;
    6809                                                int ox;
    6810                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6811                                                for (int j = 0; j < is; j++) {
    6812                                                        oai32data[it.oIndex + j] = ox;
    6813                                                }
    6814                                        }
    6815                                } else {
    6816                                        while (it.hasNext()) {
    6817                                                final long iax = it.aLong;
    6818                                                final long ibx = it.bLong;
    6819                                                int ox;
    6820                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6821                                                for (int j = 0; j < is; j++) {
    6822                                                        oai32data[it.oIndex + j] = ox;
    6823                                                }
    6824                                        }
    6825                                }
    6826                        } else {
    6827                                if (it.isOutputDouble()) {
    6828                                        while (it.hasNext()) {
    6829                                                double iax = it.aDouble;
    6830                                                double ibx = it.bDouble;
    6831                                                int ox;
    6832                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6833                                                oai32data[it.oIndex] = ox;
    6834                                                for (int j = 1; j < is; j++) {
    6835                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6836                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6837                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    6838                                                        oai32data[it.oIndex + j] = ox;
    6839                                                }
    6840                                        }
    6841                                } else {
    6842                                        while (it.hasNext()) {
    6843                                                long iax = it.aLong;
    6844                                                long ibx = it.bLong;
    6845                                                int ox;
    6846                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6847                                                oai32data[it.oIndex] = ox;
    6848                                                for (int j = 1; j < is; j++) {
    6849                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6850                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6851                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    6852                                                        oai32data[it.oIndex + j] = ox;
    6853                                                }
    6854                                        }
    6855                                }
    6856                        }
    6857                        break;
    6858                case Dataset.FLOAT32:
    6859                        final float[] of32data = ((FloatDataset) result).getData();
    6860                        if (it.isOutputDouble()) {
    6861                                while (it.hasNext()) {
    6862                                        final double iax = it.aDouble;
    6863                                        final double ibx = it.bDouble;
    6864                                        float ox;
    6865                                        ox = (float) (iax / ibx);
    6866                                        of32data[it.oIndex] = ox;
    6867                                }
    6868                        } else {
    6869                                while (it.hasNext()) {
    6870                                        final long iax = it.aLong;
    6871                                        final long ibx = it.bLong;
    6872                                        float ox;
    6873                                        ox = (iax / ibx);
    6874                                        of32data[it.oIndex] = ox;
    6875                                }
    6876                        }
    6877                        break;
    6878                case Dataset.FLOAT64:
    6879                        final double[] of64data = ((DoubleDataset) result).getData();
    6880                        if (it.isOutputDouble()) {
    6881                                while (it.hasNext()) {
    6882                                        final double iax = it.aDouble;
    6883                                        final double ibx = it.bDouble;
    6884                                        double ox;
    6885                                        ox = (iax / ibx);
    6886                                        of64data[it.oIndex] = ox;
    6887                                }
    6888                        } else {
    6889                                while (it.hasNext()) {
    6890                                        final long iax = it.aLong;
    6891                                        final long ibx = it.bLong;
    6892                                        double ox;
    6893                                        ox = (iax / ibx);
    6894                                        of64data[it.oIndex] = ox;
    6895                                }
    6896                        }
    6897                        break;
    6898                case Dataset.ARRAYFLOAT32:
    6899                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    6900                        if (is == 1) {
    6901                                if (it.isOutputDouble()) {
    6902                                        while (it.hasNext()) {
    6903                                                final double iax = it.aDouble;
    6904                                                final double ibx = it.bDouble;
    6905                                                float ox;
    6906                                                ox = (float) (iax / ibx);
    6907                                                oaf32data[it.oIndex] = ox;
    6908                                        }
    6909                                } else {
    6910                                        while (it.hasNext()) {
    6911                                                final long iax = it.aLong;
    6912                                                final long ibx = it.bLong;
    6913                                                float ox;
    6914                                                ox = (iax / ibx);
    6915                                                oaf32data[it.oIndex] = ox;
    6916                                        }
    6917                                }
    6918                        } else if (as < bs) {
    6919                                if (it.isOutputDouble()) {
    6920                                        while (it.hasNext()) {
    6921                                                final double iax = it.aDouble;
    6922                                                double ibx = it.bDouble;
    6923                                                float ox;
    6924                                                ox = (float) (iax / ibx);
    6925                                                oaf32data[it.oIndex] = ox;
    6926                                                for (int j = 1; j < is; j++) {
    6927                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    6928                                                        ox = (float) (iax / ibx);
    6929                                                        oaf32data[it.oIndex + j] = ox;
    6930                                                }
    6931                                        }
    6932                                } else {
    6933                                        while (it.hasNext()) {
    6934                                                final long iax = it.aLong;
    6935                                                long ibx = it.bLong;
    6936                                                float ox;
    6937                                                ox = (iax / ibx);
    6938                                                oaf32data[it.oIndex] = ox;
    6939                                                for (int j = 1; j < is; j++) {
    6940                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    6941                                                        ox = (iax / ibx);
    6942                                                        oaf32data[it.oIndex + j] = ox;
    6943                                                }
    6944                                        }
    6945                                }
    6946                        } else if (as > bs) {
    6947                                if (it.isOutputDouble()) {
    6948                                        while (it.hasNext()) {
    6949                                                double iax = it.aDouble;
    6950                                                final double ibx = it.bDouble;
    6951                                                float ox;
    6952                                                ox = (float) (iax / ibx);
    6953                                                oaf32data[it.oIndex] = ox;
    6954                                                for (int j = 1; j < is; j++) {
    6955                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    6956                                                        ox = (float) (iax / ibx);
    6957                                                        oaf32data[it.oIndex + j] = ox;
    6958                                                }
    6959                                        }
    6960                                } else {
    6961                                        while (it.hasNext()) {
    6962                                                long iax = it.aLong;
    6963                                                final long ibx = it.bLong;
    6964                                                float ox;
    6965                                                ox = (iax / ibx);
    6966                                                oaf32data[it.oIndex] = ox;
    6967                                                for (int j = 1; j < is; j++) {
    6968                                                        iax = da.getElementLongAbs(it.aIndex + j);
    6969                                                        ox = (iax / ibx);
    6970                                                        oaf32data[it.oIndex + j] = ox;
    6971                                                }
    6972                                        }
    6973                                }
    6974                        } else if (as == 1) {
    6975                                if (it.isOutputDouble()) {
    6976                                        while (it.hasNext()) {
    6977                                                final double iax = it.aDouble;
    6978                                                final double ibx = it.bDouble;
    6979                                                float ox;
    6980                                                ox = (float) (iax / ibx);
    6981                                                for (int j = 0; j < is; j++) {
    6982                                                        oaf32data[it.oIndex + j] = ox;
    6983                                                }
    6984                                        }
    6985                                } else {
    6986                                        while (it.hasNext()) {
    6987                                                final long iax = it.aLong;
    6988                                                final long ibx = it.bLong;
    6989                                                float ox;
    6990                                                ox = (iax / ibx);
    6991                                                for (int j = 0; j < is; j++) {
    6992                                                        oaf32data[it.oIndex + j] = ox;
    6993                                                }
    6994                                        }
    6995                                }
    6996                        } else {
    6997                                if (it.isOutputDouble()) {
    6998                                        while (it.hasNext()) {
    6999                                                double iax = it.aDouble;
    7000                                                double ibx = it.bDouble;
    7001                                                float ox;
    7002                                                ox = (float) (iax / ibx);
    7003                                                oaf32data[it.oIndex] = ox;
    7004                                                for (int j = 1; j < is; j++) {
    7005                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7006                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7007                                                        ox = (float) (iax / ibx);
    7008                                                        oaf32data[it.oIndex + j] = ox;
    7009                                                }
    7010                                        }
    7011                                } else {
    7012                                        while (it.hasNext()) {
    7013                                                long iax = it.aLong;
    7014                                                long ibx = it.bLong;
    7015                                                float ox;
    7016                                                ox = (iax / ibx);
    7017                                                oaf32data[it.oIndex] = ox;
    7018                                                for (int j = 1; j < is; j++) {
    7019                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7020                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7021                                                        ox = (iax / ibx);
    7022                                                        oaf32data[it.oIndex + j] = ox;
    7023                                                }
    7024                                        }
    7025                                }
    7026                        }
    7027                        break;
    7028                case Dataset.ARRAYFLOAT64:
    7029                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    7030                        if (is == 1) {
    7031                                if (it.isOutputDouble()) {
    7032                                        while (it.hasNext()) {
    7033                                                final double iax = it.aDouble;
    7034                                                final double ibx = it.bDouble;
    7035                                                double ox;
    7036                                                ox = (iax / ibx);
    7037                                                oaf64data[it.oIndex] = ox;
    7038                                        }
    7039                                } else {
    7040                                        while (it.hasNext()) {
    7041                                                final long iax = it.aLong;
    7042                                                final long ibx = it.bLong;
    7043                                                double ox;
    7044                                                ox = (iax / ibx);
    7045                                                oaf64data[it.oIndex] = ox;
    7046                                        }
    7047                                }
    7048                        } else if (as < bs) {
    7049                                if (it.isOutputDouble()) {
    7050                                        while (it.hasNext()) {
    7051                                                final double iax = it.aDouble;
    7052                                                double ibx = it.bDouble;
    7053                                                double ox;
    7054                                                ox = (iax / ibx);
    7055                                                oaf64data[it.oIndex] = ox;
    7056                                                for (int j = 1; j < is; j++) {
    7057                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7058                                                        ox = (iax / ibx);
    7059                                                        oaf64data[it.oIndex + j] = ox;
    7060                                                }
    7061                                        }
    7062                                } else {
    7063                                        while (it.hasNext()) {
    7064                                                final long iax = it.aLong;
    7065                                                long ibx = it.bLong;
    7066                                                double ox;
    7067                                                ox = (iax / ibx);
    7068                                                oaf64data[it.oIndex] = ox;
    7069                                                for (int j = 1; j < is; j++) {
    7070                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7071                                                        ox = (iax / ibx);
    7072                                                        oaf64data[it.oIndex + j] = ox;
    7073                                                }
    7074                                        }
    7075                                }
    7076                        } else if (as > bs) {
    7077                                if (it.isOutputDouble()) {
    7078                                        while (it.hasNext()) {
    7079                                                double iax = it.aDouble;
    7080                                                final double ibx = it.bDouble;
    7081                                                double ox;
    7082                                                ox = (iax / ibx);
    7083                                                oaf64data[it.oIndex] = ox;
    7084                                                for (int j = 1; j < is; j++) {
    7085                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7086                                                        ox = (iax / ibx);
    7087                                                        oaf64data[it.oIndex + j] = ox;
    7088                                                }
    7089                                        }
    7090                                } else {
    7091                                        while (it.hasNext()) {
    7092                                                long iax = it.aLong;
    7093                                                final long ibx = it.bLong;
    7094                                                double ox;
    7095                                                ox = (iax / ibx);
    7096                                                oaf64data[it.oIndex] = ox;
    7097                                                for (int j = 1; j < is; j++) {
    7098                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7099                                                        ox = (iax / ibx);
    7100                                                        oaf64data[it.oIndex + j] = ox;
    7101                                                }
    7102                                        }
    7103                                }
    7104                        } else if (as == 1) {
    7105                                if (it.isOutputDouble()) {
    7106                                        while (it.hasNext()) {
    7107                                                final double iax = it.aDouble;
    7108                                                final double ibx = it.bDouble;
    7109                                                double ox;
    7110                                                ox = (iax / ibx);
    7111                                                for (int j = 0; j < is; j++) {
    7112                                                        oaf64data[it.oIndex + j] = ox;
    7113                                                }
    7114                                        }
    7115                                } else {
    7116                                        while (it.hasNext()) {
    7117                                                final long iax = it.aLong;
    7118                                                final long ibx = it.bLong;
    7119                                                double ox;
    7120                                                ox = (iax / ibx);
    7121                                                for (int j = 0; j < is; j++) {
    7122                                                        oaf64data[it.oIndex + j] = ox;
    7123                                                }
    7124                                        }
    7125                                }
    7126                        } else {
    7127                                if (it.isOutputDouble()) {
    7128                                        while (it.hasNext()) {
    7129                                                double iax = it.aDouble;
    7130                                                double ibx = it.bDouble;
    7131                                                double ox;
    7132                                                ox = (iax / ibx);
    7133                                                oaf64data[it.oIndex] = ox;
    7134                                                for (int j = 1; j < is; j++) {
    7135                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7136                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7137                                                        ox = (iax / ibx);
    7138                                                        oaf64data[it.oIndex + j] = ox;
    7139                                                }
    7140                                        }
    7141                                } else {
    7142                                        while (it.hasNext()) {
    7143                                                long iax = it.aLong;
    7144                                                long ibx = it.bLong;
    7145                                                double ox;
    7146                                                ox = (iax / ibx);
    7147                                                oaf64data[it.oIndex] = ox;
    7148                                                for (int j = 1; j < is; j++) {
    7149                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7150                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7151                                                        ox = (iax / ibx);
    7152                                                        oaf64data[it.oIndex + j] = ox;
    7153                                                }
    7154                                        }
    7155                                }
    7156                        }
    7157                        break;
    7158                case Dataset.COMPLEX64:
    7159                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    7160                        if (as == 1) {
    7161                                final double iay = 0;
    7162                                while (it.hasNext()) {
    7163                                        final double iax = it.aDouble;
    7164                                        final double ibx = it.bDouble;
    7165                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    7166                                        float ox;
    7167                                        float oy;
    7168                                        float q;
    7169                                        float den;
    7170                                        if (iby == 0) {
    7171                                                ox = (float) (iax / ibx);
    7172                                                oy = (float) (iay / ibx);
    7173                                        } else if (ibx == 0) {
    7174                                                ox = (float) (iay / iby);
    7175                                                oy = (float) (-iax / iby);
    7176                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    7177                                                q = (float) (ibx / iby);
    7178                                                den = (float) (ibx * q + iby);
    7179                                                ox = (float) ((iax * q + iay) / den);
    7180                                                oy = (float) ((iay * q - ibx) / den);
    7181                                        } else {
    7182                                                q = (float) (iby / ibx);
    7183                                                den = (float) (iby * q + ibx);
    7184                                                ox = (float) ((iay * q + iax) / den);
    7185                                                oy = (float) ((iay - iax * q) / den);
    7186                                        }
    7187                                        oc64data[it.oIndex] = ox;
    7188                                        oc64data[it.oIndex + 1] = oy;
    7189                                }
    7190                        } else if (bs == 1) {
    7191                                final double iby = 0;
    7192                                while (it.hasNext()) {
    7193                                        final double iax = it.aDouble;
    7194                                        final double ibx = it.bDouble;
    7195                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    7196                                        float ox;
    7197                                        float oy;
    7198                                        float q;
    7199                                        float den;
    7200                                        if (iby == 0) {
    7201                                                ox = (float) (iax / ibx);
    7202                                                oy = (float) (iay / ibx);
    7203                                        } else if (ibx == 0) {
    7204                                                ox = (float) (iay / iby);
    7205                                                oy = (float) (-iax / iby);
    7206                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    7207                                                q = (float) (ibx / iby);
    7208                                                den = (float) (ibx * q + iby);
    7209                                                ox = (float) ((iax * q + iay) / den);
    7210                                                oy = (float) ((iay * q - ibx) / den);
    7211                                        } else {
    7212                                                q = (float) (iby / ibx);
    7213                                                den = (float) (iby * q + ibx);
    7214                                                ox = (float) ((iay * q + iax) / den);
    7215                                                oy = (float) ((iay - iax * q) / den);
    7216                                        }
    7217                                        oc64data[it.oIndex] = ox;
    7218                                        oc64data[it.oIndex + 1] = oy;
    7219                                }
    7220                        } else {
    7221                                while (it.hasNext()) {
    7222                                        final double iax = it.aDouble;
    7223                                        final double ibx = it.bDouble;
    7224                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    7225                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    7226                                        float ox;
    7227                                        float oy;
    7228                                        float q;
    7229                                        float den;
    7230                                        if (iby == 0) {
    7231                                                ox = (float) (iax / ibx);
    7232                                                oy = (float) (iay / ibx);
    7233                                        } else if (ibx == 0) {
    7234                                                ox = (float) (iay / iby);
    7235                                                oy = (float) (-iax / iby);
    7236                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    7237                                                q = (float) (ibx / iby);
    7238                                                den = (float) (ibx * q + iby);
    7239                                                ox = (float) ((iax * q + iay) / den);
    7240                                                oy = (float) ((iay * q - ibx) / den);
    7241                                        } else {
    7242                                                q = (float) (iby / ibx);
    7243                                                den = (float) (iby * q + ibx);
    7244                                                ox = (float) ((iay * q + iax) / den);
    7245                                                oy = (float) ((iay - iax * q) / den);
    7246                                        }
    7247                                        oc64data[it.oIndex] = ox;
    7248                                        oc64data[it.oIndex + 1] = oy;
    7249                                }
    7250                        }
    7251                        break;
    7252                case Dataset.COMPLEX128:
    7253                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    7254                        if (as == 1) {
    7255                                final double iay = 0;
    7256                                while (it.hasNext()) {
    7257                                        final double iax = it.aDouble;
    7258                                        final double ibx = it.bDouble;
    7259                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    7260                                        double ox;
    7261                                        double oy;
    7262                                        double q;
    7263                                        double den;
    7264                                        if (iby == 0) {
    7265                                                ox = (iax / ibx);
    7266                                                oy = (iay / ibx);
    7267                                        } else if (ibx == 0) {
    7268                                                ox = (iay / iby);
    7269                                                oy = (-iax / iby);
    7270                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    7271                                                q = (ibx / iby);
    7272                                                den = (ibx * q + iby);
    7273                                                ox = ((iax * q + iay) / den);
    7274                                                oy = ((iay * q - ibx) / den);
    7275                                        } else {
    7276                                                q = (iby / ibx);
    7277                                                den = (iby * q + ibx);
    7278                                                ox = ((iay * q + iax) / den);
    7279                                                oy = ((iay - iax * q) / den);
    7280                                        }
    7281                                        oc128data[it.oIndex] = ox;
    7282                                        oc128data[it.oIndex + 1] = oy;
    7283                                }
    7284                        } else if (bs == 1) {
    7285                                final double iby = 0;
    7286                                while (it.hasNext()) {
    7287                                        final double iax = it.aDouble;
    7288                                        final double ibx = it.bDouble;
    7289                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    7290                                        double ox;
    7291                                        double oy;
    7292                                        double q;
    7293                                        double den;
    7294                                        if (iby == 0) {
    7295                                                ox = (iax / ibx);
    7296                                                oy = (iay / ibx);
    7297                                        } else if (ibx == 0) {
    7298                                                ox = (iay / iby);
    7299                                                oy = (-iax / iby);
    7300                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    7301                                                q = (ibx / iby);
    7302                                                den = (ibx * q + iby);
    7303                                                ox = ((iax * q + iay) / den);
    7304                                                oy = ((iay * q - ibx) / den);
    7305                                        } else {
    7306                                                q = (iby / ibx);
    7307                                                den = (iby * q + ibx);
    7308                                                ox = ((iay * q + iax) / den);
    7309                                                oy = ((iay - iax * q) / den);
    7310                                        }
    7311                                        oc128data[it.oIndex] = ox;
    7312                                        oc128data[it.oIndex + 1] = oy;
    7313                                }
    7314                        } else {
    7315                                while (it.hasNext()) {
    7316                                        final double iax = it.aDouble;
    7317                                        final double ibx = it.bDouble;
    7318                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    7319                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    7320                                        double ox;
    7321                                        double oy;
    7322                                        double q;
    7323                                        double den;
    7324                                        if (iby == 0) {
    7325                                                ox = (iax / ibx);
    7326                                                oy = (iay / ibx);
    7327                                        } else if (ibx == 0) {
    7328                                                ox = (iay / iby);
    7329                                                oy = (-iax / iby);
    7330                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    7331                                                q = (ibx / iby);
    7332                                                den = (ibx * q + iby);
    7333                                                ox = ((iax * q + iay) / den);
    7334                                                oy = ((iay * q - ibx) / den);
    7335                                        } else {
    7336                                                q = (iby / ibx);
    7337                                                den = (iby * q + ibx);
    7338                                                ox = ((iay * q + iax) / den);
    7339                                                oy = ((iay - iax * q) / den);
    7340                                        }
    7341                                        oc128data[it.oIndex] = ox;
    7342                                        oc128data[it.oIndex + 1] = oy;
    7343                                }
    7344                        }
    7345                        break;
    7346                default:
    7347                        throw new IllegalArgumentException("divide supports integer, compound integer, real, compound real, complex datasets only");
    7348                }
    7349
    7350                addBinaryOperatorName(da, db, result, "/");
    7351                return result;
    7352        }
    7353
    7354        /**
    7355         * dividez operator
    7356         * @param a
    7357         * @param b
    7358         * @return {@code a / b}, division of a by b
    7359         */
    7360        public static Dataset dividez(final Object a, final Object b) {
    7361                return dividez(a, b, null);
    7362        }
    7363
    7364        /**
    7365         * dividez operator
    7366         * @param a
    7367         * @param b
    7368         * @param o output can be null - in which case, a new dataset is created
    7369         * @return {@code a / b}, division of a by b
    7370         */
    7371        public static Dataset dividez(final Object a, final Object b, final Dataset o) {
    7372                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    7373                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    7374                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    7375                final Dataset result = it.getOutput();
    7376                final int is = result.getElementsPerItem();
    7377                final int as = da.getElementsPerItem();
    7378                final int bs = db.getElementsPerItem();
    7379                final int dt = result.getDType();
    7380
    7381                switch(dt) {
    7382                case Dataset.INT8:
    7383                        final byte[] oi8data = ((ByteDataset) result).getData();
    7384                        if (it.isOutputDouble()) {
    7385                                while (it.hasNext()) {
    7386                                        final double iax = it.aDouble;
    7387                                        final double ibx = it.bDouble;
    7388                                        byte ox;
    7389                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7390                                        oi8data[it.oIndex] = ox;
    7391                                }
    7392                        } else {
    7393                                while (it.hasNext()) {
    7394                                        final long iax = it.aLong;
    7395                                        final long ibx = it.bLong;
    7396                                        byte ox;
    7397                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7398                                        oi8data[it.oIndex] = ox;
    7399                                }
    7400                        }
    7401                        break;
    7402                case Dataset.INT16:
    7403                        final short[] oi16data = ((ShortDataset) result).getData();
    7404                        if (it.isOutputDouble()) {
    7405                                while (it.hasNext()) {
    7406                                        final double iax = it.aDouble;
    7407                                        final double ibx = it.bDouble;
    7408                                        short ox;
    7409                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7410                                        oi16data[it.oIndex] = ox;
    7411                                }
    7412                        } else {
    7413                                while (it.hasNext()) {
    7414                                        final long iax = it.aLong;
    7415                                        final long ibx = it.bLong;
    7416                                        short ox;
    7417                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7418                                        oi16data[it.oIndex] = ox;
    7419                                }
    7420                        }
    7421                        break;
    7422                case Dataset.INT64:
    7423                        final long[] oi64data = ((LongDataset) result).getData();
    7424                        if (it.isOutputDouble()) {
    7425                                while (it.hasNext()) {
    7426                                        final double iax = it.aDouble;
    7427                                        final double ibx = it.bDouble;
    7428                                        long ox;
    7429                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7430                                        oi64data[it.oIndex] = ox;
    7431                                }
    7432                        } else {
    7433                                while (it.hasNext()) {
    7434                                        final long iax = it.aLong;
    7435                                        final long ibx = it.bLong;
    7436                                        long ox;
    7437                                        ox = (ibx == 0 ? 0 : iax / ibx);
    7438                                        oi64data[it.oIndex] = ox;
    7439                                }
    7440                        }
    7441                        break;
    7442                case Dataset.INT32:
    7443                        final int[] oi32data = ((IntegerDataset) result).getData();
    7444                        if (it.isOutputDouble()) {
    7445                                while (it.hasNext()) {
    7446                                        final double iax = it.aDouble;
    7447                                        final double ibx = it.bDouble;
    7448                                        int ox;
    7449                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7450                                        oi32data[it.oIndex] = ox;
    7451                                }
    7452                        } else {
    7453                                while (it.hasNext()) {
    7454                                        final long iax = it.aLong;
    7455                                        final long ibx = it.bLong;
    7456                                        int ox;
    7457                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7458                                        oi32data[it.oIndex] = ox;
    7459                                }
    7460                        }
    7461                        break;
    7462                case Dataset.ARRAYINT8:
    7463                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    7464                        if (is == 1) {
    7465                                if (it.isOutputDouble()) {
    7466                                        while (it.hasNext()) {
    7467                                                final double iax = it.aDouble;
    7468                                                final double ibx = it.bDouble;
    7469                                                byte ox;
    7470                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7471                                                oai8data[it.oIndex] = ox;
    7472                                        }
    7473                                } else {
    7474                                        while (it.hasNext()) {
    7475                                                final long iax = it.aLong;
    7476                                                final long ibx = it.bLong;
    7477                                                byte ox;
    7478                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7479                                                oai8data[it.oIndex] = ox;
    7480                                        }
    7481                                }
    7482                        } else if (as < bs) {
    7483                                if (it.isOutputDouble()) {
    7484                                        while (it.hasNext()) {
    7485                                                final double iax = it.aDouble;
    7486                                                double ibx = it.bDouble;
    7487                                                byte ox;
    7488                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7489                                                oai8data[it.oIndex] = ox;
    7490                                                for (int j = 1; j < is; j++) {
    7491                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7492                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7493                                                        oai8data[it.oIndex + j] = ox;
    7494                                                }
    7495                                        }
    7496                                } else {
    7497                                        while (it.hasNext()) {
    7498                                                final long iax = it.aLong;
    7499                                                long ibx = it.bLong;
    7500                                                byte ox;
    7501                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7502                                                oai8data[it.oIndex] = ox;
    7503                                                for (int j = 1; j < is; j++) {
    7504                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7505                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7506                                                        oai8data[it.oIndex + j] = ox;
    7507                                                }
    7508                                        }
    7509                                }
    7510                        } else if (as > bs) {
    7511                                if (it.isOutputDouble()) {
    7512                                        while (it.hasNext()) {
    7513                                                double iax = it.aDouble;
    7514                                                final double ibx = it.bDouble;
    7515                                                byte ox;
    7516                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7517                                                oai8data[it.oIndex] = ox;
    7518                                                for (int j = 1; j < is; j++) {
    7519                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7520                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7521                                                        oai8data[it.oIndex + j] = ox;
    7522                                                }
    7523                                        }
    7524                                } else {
    7525                                        while (it.hasNext()) {
    7526                                                long iax = it.aLong;
    7527                                                final long ibx = it.bLong;
    7528                                                byte ox;
    7529                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7530                                                oai8data[it.oIndex] = ox;
    7531                                                for (int j = 1; j < is; j++) {
    7532                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7533                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7534                                                        oai8data[it.oIndex + j] = ox;
    7535                                                }
    7536                                        }
    7537                                }
    7538                        } else if (as == 1) {
    7539                                if (it.isOutputDouble()) {
    7540                                        while (it.hasNext()) {
    7541                                                final double iax = it.aDouble;
    7542                                                final double ibx = it.bDouble;
    7543                                                byte ox;
    7544                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7545                                                for (int j = 0; j < is; j++) {
    7546                                                        oai8data[it.oIndex + j] = ox;
    7547                                                }
    7548                                        }
    7549                                } else {
    7550                                        while (it.hasNext()) {
    7551                                                final long iax = it.aLong;
    7552                                                final long ibx = it.bLong;
    7553                                                byte ox;
    7554                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7555                                                for (int j = 0; j < is; j++) {
    7556                                                        oai8data[it.oIndex + j] = ox;
    7557                                                }
    7558                                        }
    7559                                }
    7560                        } else {
    7561                                if (it.isOutputDouble()) {
    7562                                        while (it.hasNext()) {
    7563                                                double iax = it.aDouble;
    7564                                                double ibx = it.bDouble;
    7565                                                byte ox;
    7566                                                ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7567                                                oai8data[it.oIndex] = ox;
    7568                                                for (int j = 1; j < is; j++) {
    7569                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7570                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7571                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax / ibx);
    7572                                                        oai8data[it.oIndex + j] = ox;
    7573                                                }
    7574                                        }
    7575                                } else {
    7576                                        while (it.hasNext()) {
    7577                                                long iax = it.aLong;
    7578                                                long ibx = it.bLong;
    7579                                                byte ox;
    7580                                                ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7581                                                oai8data[it.oIndex] = ox;
    7582                                                for (int j = 1; j < is; j++) {
    7583                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7584                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7585                                                        ox = (byte) (ibx == 0 ? 0 : iax / ibx);
    7586                                                        oai8data[it.oIndex + j] = ox;
    7587                                                }
    7588                                        }
    7589                                }
    7590                        }
    7591                        break;
    7592                case Dataset.ARRAYINT16:
    7593                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    7594                        if (is == 1) {
    7595                                if (it.isOutputDouble()) {
    7596                                        while (it.hasNext()) {
    7597                                                final double iax = it.aDouble;
    7598                                                final double ibx = it.bDouble;
    7599                                                short ox;
    7600                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7601                                                oai16data[it.oIndex] = ox;
    7602                                        }
    7603                                } else {
    7604                                        while (it.hasNext()) {
    7605                                                final long iax = it.aLong;
    7606                                                final long ibx = it.bLong;
    7607                                                short ox;
    7608                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7609                                                oai16data[it.oIndex] = ox;
    7610                                        }
    7611                                }
    7612                        } else if (as < bs) {
    7613                                if (it.isOutputDouble()) {
    7614                                        while (it.hasNext()) {
    7615                                                final double iax = it.aDouble;
    7616                                                double ibx = it.bDouble;
    7617                                                short ox;
    7618                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7619                                                oai16data[it.oIndex] = ox;
    7620                                                for (int j = 1; j < is; j++) {
    7621                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7622                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7623                                                        oai16data[it.oIndex + j] = ox;
    7624                                                }
    7625                                        }
    7626                                } else {
    7627                                        while (it.hasNext()) {
    7628                                                final long iax = it.aLong;
    7629                                                long ibx = it.bLong;
    7630                                                short ox;
    7631                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7632                                                oai16data[it.oIndex] = ox;
    7633                                                for (int j = 1; j < is; j++) {
    7634                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7635                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7636                                                        oai16data[it.oIndex + j] = ox;
    7637                                                }
    7638                                        }
    7639                                }
    7640                        } else if (as > bs) {
    7641                                if (it.isOutputDouble()) {
    7642                                        while (it.hasNext()) {
    7643                                                double iax = it.aDouble;
    7644                                                final double ibx = it.bDouble;
    7645                                                short ox;
    7646                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7647                                                oai16data[it.oIndex] = ox;
    7648                                                for (int j = 1; j < is; j++) {
    7649                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7650                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7651                                                        oai16data[it.oIndex + j] = ox;
    7652                                                }
    7653                                        }
    7654                                } else {
    7655                                        while (it.hasNext()) {
    7656                                                long iax = it.aLong;
    7657                                                final long ibx = it.bLong;
    7658                                                short ox;
    7659                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7660                                                oai16data[it.oIndex] = ox;
    7661                                                for (int j = 1; j < is; j++) {
    7662                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7663                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7664                                                        oai16data[it.oIndex + j] = ox;
    7665                                                }
    7666                                        }
    7667                                }
    7668                        } else if (as == 1) {
    7669                                if (it.isOutputDouble()) {
    7670                                        while (it.hasNext()) {
    7671                                                final double iax = it.aDouble;
    7672                                                final double ibx = it.bDouble;
    7673                                                short ox;
    7674                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7675                                                for (int j = 0; j < is; j++) {
    7676                                                        oai16data[it.oIndex + j] = ox;
    7677                                                }
    7678                                        }
    7679                                } else {
    7680                                        while (it.hasNext()) {
    7681                                                final long iax = it.aLong;
    7682                                                final long ibx = it.bLong;
    7683                                                short ox;
    7684                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7685                                                for (int j = 0; j < is; j++) {
    7686                                                        oai16data[it.oIndex + j] = ox;
    7687                                                }
    7688                                        }
    7689                                }
    7690                        } else {
    7691                                if (it.isOutputDouble()) {
    7692                                        while (it.hasNext()) {
    7693                                                double iax = it.aDouble;
    7694                                                double ibx = it.bDouble;
    7695                                                short ox;
    7696                                                ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7697                                                oai16data[it.oIndex] = ox;
    7698                                                for (int j = 1; j < is; j++) {
    7699                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7700                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7701                                                        ox = (short) toLong(ibx == 0 ? 0 : iax / ibx);
    7702                                                        oai16data[it.oIndex + j] = ox;
    7703                                                }
    7704                                        }
    7705                                } else {
    7706                                        while (it.hasNext()) {
    7707                                                long iax = it.aLong;
    7708                                                long ibx = it.bLong;
    7709                                                short ox;
    7710                                                ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7711                                                oai16data[it.oIndex] = ox;
    7712                                                for (int j = 1; j < is; j++) {
    7713                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7714                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7715                                                        ox = (short) (ibx == 0 ? 0 : iax / ibx);
    7716                                                        oai16data[it.oIndex + j] = ox;
    7717                                                }
    7718                                        }
    7719                                }
    7720                        }
    7721                        break;
    7722                case Dataset.ARRAYINT64:
    7723                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    7724                        if (is == 1) {
    7725                                if (it.isOutputDouble()) {
    7726                                        while (it.hasNext()) {
    7727                                                final double iax = it.aDouble;
    7728                                                final double ibx = it.bDouble;
    7729                                                long ox;
    7730                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7731                                                oai64data[it.oIndex] = ox;
    7732                                        }
    7733                                } else {
    7734                                        while (it.hasNext()) {
    7735                                                final long iax = it.aLong;
    7736                                                final long ibx = it.bLong;
    7737                                                long ox;
    7738                                                ox = (ibx == 0 ? 0 : iax / ibx);
    7739                                                oai64data[it.oIndex] = ox;
    7740                                        }
    7741                                }
    7742                        } else if (as < bs) {
    7743                                if (it.isOutputDouble()) {
    7744                                        while (it.hasNext()) {
    7745                                                final double iax = it.aDouble;
    7746                                                double ibx = it.bDouble;
    7747                                                long ox;
    7748                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7749                                                oai64data[it.oIndex] = ox;
    7750                                                for (int j = 1; j < is; j++) {
    7751                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7752                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7753                                                        oai64data[it.oIndex + j] = ox;
    7754                                                }
    7755                                        }
    7756                                } else {
    7757                                        while (it.hasNext()) {
    7758                                                final long iax = it.aLong;
    7759                                                long ibx = it.bLong;
    7760                                                long ox;
    7761                                                ox = (ibx == 0 ? 0 : iax / ibx);
    7762                                                oai64data[it.oIndex] = ox;
    7763                                                for (int j = 1; j < is; j++) {
    7764                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7765                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    7766                                                        oai64data[it.oIndex + j] = ox;
    7767                                                }
    7768                                        }
    7769                                }
    7770                        } else if (as > bs) {
    7771                                if (it.isOutputDouble()) {
    7772                                        while (it.hasNext()) {
    7773                                                double iax = it.aDouble;
    7774                                                final double ibx = it.bDouble;
    7775                                                long ox;
    7776                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7777                                                oai64data[it.oIndex] = ox;
    7778                                                for (int j = 1; j < is; j++) {
    7779                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7780                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7781                                                        oai64data[it.oIndex + j] = ox;
    7782                                                }
    7783                                        }
    7784                                } else {
    7785                                        while (it.hasNext()) {
    7786                                                long iax = it.aLong;
    7787                                                final long ibx = it.bLong;
    7788                                                long ox;
    7789                                                ox = (ibx == 0 ? 0 : iax / ibx);
    7790                                                oai64data[it.oIndex] = ox;
    7791                                                for (int j = 1; j < is; j++) {
    7792                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7793                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    7794                                                        oai64data[it.oIndex + j] = ox;
    7795                                                }
    7796                                        }
    7797                                }
    7798                        } else if (as == 1) {
    7799                                if (it.isOutputDouble()) {
    7800                                        while (it.hasNext()) {
    7801                                                final double iax = it.aDouble;
    7802                                                final double ibx = it.bDouble;
    7803                                                long ox;
    7804                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7805                                                for (int j = 0; j < is; j++) {
    7806                                                        oai64data[it.oIndex + j] = ox;
    7807                                                }
    7808                                        }
    7809                                } else {
    7810                                        while (it.hasNext()) {
    7811                                                final long iax = it.aLong;
    7812                                                final long ibx = it.bLong;
    7813                                                long ox;
    7814                                                ox = (ibx == 0 ? 0 : iax / ibx);
    7815                                                for (int j = 0; j < is; j++) {
    7816                                                        oai64data[it.oIndex + j] = ox;
    7817                                                }
    7818                                        }
    7819                                }
    7820                        } else {
    7821                                if (it.isOutputDouble()) {
    7822                                        while (it.hasNext()) {
    7823                                                double iax = it.aDouble;
    7824                                                double ibx = it.bDouble;
    7825                                                long ox;
    7826                                                ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7827                                                oai64data[it.oIndex] = ox;
    7828                                                for (int j = 1; j < is; j++) {
    7829                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7830                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7831                                                        ox = toLong(ibx == 0 ? 0 : iax / ibx);
    7832                                                        oai64data[it.oIndex + j] = ox;
    7833                                                }
    7834                                        }
    7835                                } else {
    7836                                        while (it.hasNext()) {
    7837                                                long iax = it.aLong;
    7838                                                long ibx = it.bLong;
    7839                                                long ox;
    7840                                                ox = (ibx == 0 ? 0 : iax / ibx);
    7841                                                oai64data[it.oIndex] = ox;
    7842                                                for (int j = 1; j < is; j++) {
    7843                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7844                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7845                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    7846                                                        oai64data[it.oIndex + j] = ox;
    7847                                                }
    7848                                        }
    7849                                }
    7850                        }
    7851                        break;
    7852                case Dataset.ARRAYINT32:
    7853                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    7854                        if (is == 1) {
    7855                                if (it.isOutputDouble()) {
    7856                                        while (it.hasNext()) {
    7857                                                final double iax = it.aDouble;
    7858                                                final double ibx = it.bDouble;
    7859                                                int ox;
    7860                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7861                                                oai32data[it.oIndex] = ox;
    7862                                        }
    7863                                } else {
    7864                                        while (it.hasNext()) {
    7865                                                final long iax = it.aLong;
    7866                                                final long ibx = it.bLong;
    7867                                                int ox;
    7868                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7869                                                oai32data[it.oIndex] = ox;
    7870                                        }
    7871                                }
    7872                        } else if (as < bs) {
    7873                                if (it.isOutputDouble()) {
    7874                                        while (it.hasNext()) {
    7875                                                final double iax = it.aDouble;
    7876                                                double ibx = it.bDouble;
    7877                                                int ox;
    7878                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7879                                                oai32data[it.oIndex] = ox;
    7880                                                for (int j = 1; j < is; j++) {
    7881                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7882                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7883                                                        oai32data[it.oIndex + j] = ox;
    7884                                                }
    7885                                        }
    7886                                } else {
    7887                                        while (it.hasNext()) {
    7888                                                final long iax = it.aLong;
    7889                                                long ibx = it.bLong;
    7890                                                int ox;
    7891                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7892                                                oai32data[it.oIndex] = ox;
    7893                                                for (int j = 1; j < is; j++) {
    7894                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7895                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7896                                                        oai32data[it.oIndex + j] = ox;
    7897                                                }
    7898                                        }
    7899                                }
    7900                        } else if (as > bs) {
    7901                                if (it.isOutputDouble()) {
    7902                                        while (it.hasNext()) {
    7903                                                double iax = it.aDouble;
    7904                                                final double ibx = it.bDouble;
    7905                                                int ox;
    7906                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7907                                                oai32data[it.oIndex] = ox;
    7908                                                for (int j = 1; j < is; j++) {
    7909                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7910                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7911                                                        oai32data[it.oIndex + j] = ox;
    7912                                                }
    7913                                        }
    7914                                } else {
    7915                                        while (it.hasNext()) {
    7916                                                long iax = it.aLong;
    7917                                                final long ibx = it.bLong;
    7918                                                int ox;
    7919                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7920                                                oai32data[it.oIndex] = ox;
    7921                                                for (int j = 1; j < is; j++) {
    7922                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7923                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7924                                                        oai32data[it.oIndex + j] = ox;
    7925                                                }
    7926                                        }
    7927                                }
    7928                        } else if (as == 1) {
    7929                                if (it.isOutputDouble()) {
    7930                                        while (it.hasNext()) {
    7931                                                final double iax = it.aDouble;
    7932                                                final double ibx = it.bDouble;
    7933                                                int ox;
    7934                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7935                                                for (int j = 0; j < is; j++) {
    7936                                                        oai32data[it.oIndex + j] = ox;
    7937                                                }
    7938                                        }
    7939                                } else {
    7940                                        while (it.hasNext()) {
    7941                                                final long iax = it.aLong;
    7942                                                final long ibx = it.bLong;
    7943                                                int ox;
    7944                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7945                                                for (int j = 0; j < is; j++) {
    7946                                                        oai32data[it.oIndex + j] = ox;
    7947                                                }
    7948                                        }
    7949                                }
    7950                        } else {
    7951                                if (it.isOutputDouble()) {
    7952                                        while (it.hasNext()) {
    7953                                                double iax = it.aDouble;
    7954                                                double ibx = it.bDouble;
    7955                                                int ox;
    7956                                                ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7957                                                oai32data[it.oIndex] = ox;
    7958                                                for (int j = 1; j < is; j++) {
    7959                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    7960                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    7961                                                        ox = (int) toLong(ibx == 0 ? 0 : iax / ibx);
    7962                                                        oai32data[it.oIndex + j] = ox;
    7963                                                }
    7964                                        }
    7965                                } else {
    7966                                        while (it.hasNext()) {
    7967                                                long iax = it.aLong;
    7968                                                long ibx = it.bLong;
    7969                                                int ox;
    7970                                                ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7971                                                oai32data[it.oIndex] = ox;
    7972                                                for (int j = 1; j < is; j++) {
    7973                                                        iax = da.getElementLongAbs(it.aIndex + j);
    7974                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    7975                                                        ox = (int) (ibx == 0 ? 0 : iax / ibx);
    7976                                                        oai32data[it.oIndex + j] = ox;
    7977                                                }
    7978                                        }
    7979                                }
    7980                        }
    7981                        break;
    7982                case Dataset.FLOAT32:
    7983                        final float[] of32data = ((FloatDataset) result).getData();
    7984                        if (it.isOutputDouble()) {
    7985                                while (it.hasNext()) {
    7986                                        final double iax = it.aDouble;
    7987                                        final double ibx = it.bDouble;
    7988                                        float ox;
    7989                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
    7990                                        of32data[it.oIndex] = ox;
    7991                                }
    7992                        } else {
    7993                                while (it.hasNext()) {
    7994                                        final long iax = it.aLong;
    7995                                        final long ibx = it.bLong;
    7996                                        float ox;
    7997                                        ox = (ibx == 0 ? 0 : iax / ibx);
    7998                                        of32data[it.oIndex] = ox;
    7999                                }
    8000                        }
    8001                        break;
    8002                case Dataset.FLOAT64:
    8003                        final double[] of64data = ((DoubleDataset) result).getData();
    8004                        if (it.isOutputDouble()) {
    8005                                while (it.hasNext()) {
    8006                                        final double iax = it.aDouble;
    8007                                        final double ibx = it.bDouble;
    8008                                        double ox;
    8009                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8010                                        of64data[it.oIndex] = ox;
    8011                                }
    8012                        } else {
    8013                                while (it.hasNext()) {
    8014                                        final long iax = it.aLong;
    8015                                        final long ibx = it.bLong;
    8016                                        double ox;
    8017                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8018                                        of64data[it.oIndex] = ox;
    8019                                }
    8020                        }
    8021                        break;
    8022                case Dataset.ARRAYFLOAT32:
    8023                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    8024                        if (is == 1) {
    8025                                if (it.isOutputDouble()) {
    8026                                        while (it.hasNext()) {
    8027                                                final double iax = it.aDouble;
    8028                                                final double ibx = it.bDouble;
    8029                                                float ox;
    8030                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8031                                                oaf32data[it.oIndex] = ox;
    8032                                        }
    8033                                } else {
    8034                                        while (it.hasNext()) {
    8035                                                final long iax = it.aLong;
    8036                                                final long ibx = it.bLong;
    8037                                                float ox;
    8038                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8039                                                oaf32data[it.oIndex] = ox;
    8040                                        }
    8041                                }
    8042                        } else if (as < bs) {
    8043                                if (it.isOutputDouble()) {
    8044                                        while (it.hasNext()) {
    8045                                                final double iax = it.aDouble;
    8046                                                double ibx = it.bDouble;
    8047                                                float ox;
    8048                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8049                                                oaf32data[it.oIndex] = ox;
    8050                                                for (int j = 1; j < is; j++) {
    8051                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8052                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8053                                                        oaf32data[it.oIndex + j] = ox;
    8054                                                }
    8055                                        }
    8056                                } else {
    8057                                        while (it.hasNext()) {
    8058                                                final long iax = it.aLong;
    8059                                                long ibx = it.bLong;
    8060                                                float ox;
    8061                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8062                                                oaf32data[it.oIndex] = ox;
    8063                                                for (int j = 1; j < is; j++) {
    8064                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8065                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8066                                                        oaf32data[it.oIndex + j] = ox;
    8067                                                }
    8068                                        }
    8069                                }
    8070                        } else if (as > bs) {
    8071                                if (it.isOutputDouble()) {
    8072                                        while (it.hasNext()) {
    8073                                                double iax = it.aDouble;
    8074                                                final double ibx = it.bDouble;
    8075                                                float ox;
    8076                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8077                                                oaf32data[it.oIndex] = ox;
    8078                                                for (int j = 1; j < is; j++) {
    8079                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8080                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8081                                                        oaf32data[it.oIndex + j] = ox;
    8082                                                }
    8083                                        }
    8084                                } else {
    8085                                        while (it.hasNext()) {
    8086                                                long iax = it.aLong;
    8087                                                final long ibx = it.bLong;
    8088                                                float ox;
    8089                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8090                                                oaf32data[it.oIndex] = ox;
    8091                                                for (int j = 1; j < is; j++) {
    8092                                                        iax = da.getElementLongAbs(it.aIndex + j);
    8093                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8094                                                        oaf32data[it.oIndex + j] = ox;
    8095                                                }
    8096                                        }
    8097                                }
    8098                        } else if (as == 1) {
    8099                                if (it.isOutputDouble()) {
    8100                                        while (it.hasNext()) {
    8101                                                final double iax = it.aDouble;
    8102                                                final double ibx = it.bDouble;
    8103                                                float ox;
    8104                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8105                                                for (int j = 0; j < is; j++) {
    8106                                                        oaf32data[it.oIndex + j] = ox;
    8107                                                }
    8108                                        }
    8109                                } else {
    8110                                        while (it.hasNext()) {
    8111                                                final long iax = it.aLong;
    8112                                                final long ibx = it.bLong;
    8113                                                float ox;
    8114                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8115                                                for (int j = 0; j < is; j++) {
    8116                                                        oaf32data[it.oIndex + j] = ox;
    8117                                                }
    8118                                        }
    8119                                }
    8120                        } else {
    8121                                if (it.isOutputDouble()) {
    8122                                        while (it.hasNext()) {
    8123                                                double iax = it.aDouble;
    8124                                                double ibx = it.bDouble;
    8125                                                float ox;
    8126                                                ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8127                                                oaf32data[it.oIndex] = ox;
    8128                                                for (int j = 1; j < is; j++) {
    8129                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8130                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8131                                                        ox = (float) (ibx == 0 ? 0 : iax / ibx);
    8132                                                        oaf32data[it.oIndex + j] = ox;
    8133                                                }
    8134                                        }
    8135                                } else {
    8136                                        while (it.hasNext()) {
    8137                                                long iax = it.aLong;
    8138                                                long ibx = it.bLong;
    8139                                                float ox;
    8140                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8141                                                oaf32data[it.oIndex] = ox;
    8142                                                for (int j = 1; j < is; j++) {
    8143                                                        iax = da.getElementLongAbs(it.aIndex + j);
    8144                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8145                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8146                                                        oaf32data[it.oIndex + j] = ox;
    8147                                                }
    8148                                        }
    8149                                }
    8150                        }
    8151                        break;
    8152                case Dataset.ARRAYFLOAT64:
    8153                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    8154                        if (is == 1) {
    8155                                if (it.isOutputDouble()) {
    8156                                        while (it.hasNext()) {
    8157                                                final double iax = it.aDouble;
    8158                                                final double ibx = it.bDouble;
    8159                                                double ox;
    8160                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8161                                                oaf64data[it.oIndex] = ox;
    8162                                        }
    8163                                } else {
    8164                                        while (it.hasNext()) {
    8165                                                final long iax = it.aLong;
    8166                                                final long ibx = it.bLong;
    8167                                                double ox;
    8168                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8169                                                oaf64data[it.oIndex] = ox;
    8170                                        }
    8171                                }
    8172                        } else if (as < bs) {
    8173                                if (it.isOutputDouble()) {
    8174                                        while (it.hasNext()) {
    8175                                                final double iax = it.aDouble;
    8176                                                double ibx = it.bDouble;
    8177                                                double ox;
    8178                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8179                                                oaf64data[it.oIndex] = ox;
    8180                                                for (int j = 1; j < is; j++) {
    8181                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8182                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8183                                                        oaf64data[it.oIndex + j] = ox;
    8184                                                }
    8185                                        }
    8186                                } else {
    8187                                        while (it.hasNext()) {
    8188                                                final long iax = it.aLong;
    8189                                                long ibx = it.bLong;
    8190                                                double ox;
    8191                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8192                                                oaf64data[it.oIndex] = ox;
    8193                                                for (int j = 1; j < is; j++) {
    8194                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8195                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8196                                                        oaf64data[it.oIndex + j] = ox;
    8197                                                }
    8198                                        }
    8199                                }
    8200                        } else if (as > bs) {
    8201                                if (it.isOutputDouble()) {
    8202                                        while (it.hasNext()) {
    8203                                                double iax = it.aDouble;
    8204                                                final double ibx = it.bDouble;
    8205                                                double ox;
    8206                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8207                                                oaf64data[it.oIndex] = ox;
    8208                                                for (int j = 1; j < is; j++) {
    8209                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8210                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8211                                                        oaf64data[it.oIndex + j] = ox;
    8212                                                }
    8213                                        }
    8214                                } else {
    8215                                        while (it.hasNext()) {
    8216                                                long iax = it.aLong;
    8217                                                final long ibx = it.bLong;
    8218                                                double ox;
    8219                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8220                                                oaf64data[it.oIndex] = ox;
    8221                                                for (int j = 1; j < is; j++) {
    8222                                                        iax = da.getElementLongAbs(it.aIndex + j);
    8223                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8224                                                        oaf64data[it.oIndex + j] = ox;
    8225                                                }
    8226                                        }
    8227                                }
    8228                        } else if (as == 1) {
    8229                                if (it.isOutputDouble()) {
    8230                                        while (it.hasNext()) {
    8231                                                final double iax = it.aDouble;
    8232                                                final double ibx = it.bDouble;
    8233                                                double ox;
    8234                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8235                                                for (int j = 0; j < is; j++) {
    8236                                                        oaf64data[it.oIndex + j] = ox;
    8237                                                }
    8238                                        }
    8239                                } else {
    8240                                        while (it.hasNext()) {
    8241                                                final long iax = it.aLong;
    8242                                                final long ibx = it.bLong;
    8243                                                double ox;
    8244                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8245                                                for (int j = 0; j < is; j++) {
    8246                                                        oaf64data[it.oIndex + j] = ox;
    8247                                                }
    8248                                        }
    8249                                }
    8250                        } else {
    8251                                if (it.isOutputDouble()) {
    8252                                        while (it.hasNext()) {
    8253                                                double iax = it.aDouble;
    8254                                                double ibx = it.bDouble;
    8255                                                double ox;
    8256                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8257                                                oaf64data[it.oIndex] = ox;
    8258                                                for (int j = 1; j < is; j++) {
    8259                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8260                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8261                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8262                                                        oaf64data[it.oIndex + j] = ox;
    8263                                                }
    8264                                        }
    8265                                } else {
    8266                                        while (it.hasNext()) {
    8267                                                long iax = it.aLong;
    8268                                                long ibx = it.bLong;
    8269                                                double ox;
    8270                                                ox = (ibx == 0 ? 0 : iax / ibx);
    8271                                                oaf64data[it.oIndex] = ox;
    8272                                                for (int j = 1; j < is; j++) {
    8273                                                        iax = da.getElementLongAbs(it.aIndex + j);
    8274                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8275                                                        ox = (ibx == 0 ? 0 : iax / ibx);
    8276                                                        oaf64data[it.oIndex + j] = ox;
    8277                                                }
    8278                                        }
    8279                                }
    8280                        }
    8281                        break;
    8282                case Dataset.COMPLEX64:
    8283                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    8284                        if (as == 1) {
    8285                                final double iay = 0;
    8286                                while (it.hasNext()) {
    8287                                        final double iax = it.aDouble;
    8288                                        final double ibx = it.bDouble;
    8289                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    8290                                        float ox;
    8291                                        float oy;
    8292                                        float q;
    8293                                        float den;
    8294                                        if (ibx == 0 && iby == 0) {
    8295                                                ox = 0;
    8296                                                oy = 0;
    8297                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    8298                                                q = (float) (ibx / iby);
    8299                                                den = (float) (ibx * q + iby);
    8300                                                ox = (float) ((iax * q + iay) / den);
    8301                                                oy = (float) ((iay * q - ibx) / den);
    8302                                        } else {
    8303                                                q = (float) (iby / ibx);
    8304                                                den = (float) (iby * q + ibx);
    8305                                                ox = (float) ((iay * q + iax) / den);
    8306                                                oy = (float) ((iay - iax * q) / den);
    8307                                        }
    8308                                        oc64data[it.oIndex] = ox;
    8309                                        oc64data[it.oIndex + 1] = oy;
    8310                                }
    8311                        } else if (bs == 1) {
    8312                                final double iby = 0;
    8313                                while (it.hasNext()) {
    8314                                        final double iax = it.aDouble;
    8315                                        final double ibx = it.bDouble;
    8316                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    8317                                        float ox;
    8318                                        float oy;
    8319                                        float q;
    8320                                        float den;
    8321                                        if (ibx == 0 && iby == 0) {
    8322                                                ox = 0;
    8323                                                oy = 0;
    8324                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    8325                                                q = (float) (ibx / iby);
    8326                                                den = (float) (ibx * q + iby);
    8327                                                ox = (float) ((iax * q + iay) / den);
    8328                                                oy = (float) ((iay * q - ibx) / den);
    8329                                        } else {
    8330                                                q = (float) (iby / ibx);
    8331                                                den = (float) (iby * q + ibx);
    8332                                                ox = (float) ((iay * q + iax) / den);
    8333                                                oy = (float) ((iay - iax * q) / den);
    8334                                        }
    8335                                        oc64data[it.oIndex] = ox;
    8336                                        oc64data[it.oIndex + 1] = oy;
    8337                                }
    8338                        } else {
    8339                                while (it.hasNext()) {
    8340                                        final double iax = it.aDouble;
    8341                                        final double ibx = it.bDouble;
    8342                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    8343                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    8344                                        float ox;
    8345                                        float oy;
    8346                                        float q;
    8347                                        float den;
    8348                                        if (ibx == 0 && iby == 0) {
    8349                                                ox = 0;
    8350                                                oy = 0;
    8351                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    8352                                                q = (float) (ibx / iby);
    8353                                                den = (float) (ibx * q + iby);
    8354                                                ox = (float) ((iax * q + iay) / den);
    8355                                                oy = (float) ((iay * q - ibx) / den);
    8356                                        } else {
    8357                                                q = (float) (iby / ibx);
    8358                                                den = (float) (iby * q + ibx);
    8359                                                ox = (float) ((iay * q + iax) / den);
    8360                                                oy = (float) ((iay - iax * q) / den);
    8361                                        }
    8362                                        oc64data[it.oIndex] = ox;
    8363                                        oc64data[it.oIndex + 1] = oy;
    8364                                }
    8365                        }
    8366                        break;
    8367                case Dataset.COMPLEX128:
    8368                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    8369                        if (as == 1) {
    8370                                final double iay = 0;
    8371                                while (it.hasNext()) {
    8372                                        final double iax = it.aDouble;
    8373                                        final double ibx = it.bDouble;
    8374                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    8375                                        double ox;
    8376                                        double oy;
    8377                                        double q;
    8378                                        double den;
    8379                                        if (ibx == 0 && iby == 0) {
    8380                                                ox = 0;
    8381                                                oy = 0;
    8382                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    8383                                                q = (ibx / iby);
    8384                                                den = (ibx * q + iby);
    8385                                                ox = ((iax * q + iay) / den);
    8386                                                oy = ((iay * q - ibx) / den);
    8387                                        } else {
    8388                                                q = (iby / ibx);
    8389                                                den = (iby * q + ibx);
    8390                                                ox = ((iay * q + iax) / den);
    8391                                                oy = ((iay - iax * q) / den);
    8392                                        }
    8393                                        oc128data[it.oIndex] = ox;
    8394                                        oc128data[it.oIndex + 1] = oy;
    8395                                }
    8396                        } else if (bs == 1) {
    8397                                final double iby = 0;
    8398                                while (it.hasNext()) {
    8399                                        final double iax = it.aDouble;
    8400                                        final double ibx = it.bDouble;
    8401                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    8402                                        double ox;
    8403                                        double oy;
    8404                                        double q;
    8405                                        double den;
    8406                                        if (ibx == 0 && iby == 0) {
    8407                                                ox = 0;
    8408                                                oy = 0;
    8409                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    8410                                                q = (ibx / iby);
    8411                                                den = (ibx * q + iby);
    8412                                                ox = ((iax * q + iay) / den);
    8413                                                oy = ((iay * q - ibx) / den);
    8414                                        } else {
    8415                                                q = (iby / ibx);
    8416                                                den = (iby * q + ibx);
    8417                                                ox = ((iay * q + iax) / den);
    8418                                                oy = ((iay - iax * q) / den);
    8419                                        }
    8420                                        oc128data[it.oIndex] = ox;
    8421                                        oc128data[it.oIndex + 1] = oy;
    8422                                }
    8423                        } else {
    8424                                while (it.hasNext()) {
    8425                                        final double iax = it.aDouble;
    8426                                        final double ibx = it.bDouble;
    8427                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    8428                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    8429                                        double ox;
    8430                                        double oy;
    8431                                        double q;
    8432                                        double den;
    8433                                        if (ibx == 0 && iby == 0) {
    8434                                                ox = 0;
    8435                                                oy = 0;
    8436                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    8437                                                q = (ibx / iby);
    8438                                                den = (ibx * q + iby);
    8439                                                ox = ((iax * q + iay) / den);
    8440                                                oy = ((iay * q - ibx) / den);
    8441                                        } else {
    8442                                                q = (iby / ibx);
    8443                                                den = (iby * q + ibx);
    8444                                                ox = ((iay * q + iax) / den);
    8445                                                oy = ((iay - iax * q) / den);
    8446                                        }
    8447                                        oc128data[it.oIndex] = ox;
    8448                                        oc128data[it.oIndex + 1] = oy;
    8449                                }
    8450                        }
    8451                        break;
    8452                default:
    8453                        throw new IllegalArgumentException("dividez supports integer, compound integer, real, compound real, complex datasets only");
    8454                }
    8455
    8456                addBinaryOperatorName(da, db, result, "/");
    8457                return result;
    8458        }
    8459
    8460        /**
    8461         * divideTowardsFloor operator
    8462         * @param a
    8463         * @param b
    8464         * @return {@code a / b}, division of a by b but rounded towards negative infinity
    8465         */
    8466        public static Dataset divideTowardsFloor(final Object a, final Object b) {
    8467                return divideTowardsFloor(a, b, null);
    8468        }
    8469
    8470        /**
    8471         * divideTowardsFloor operator
    8472         * @param a
    8473         * @param b
    8474         * @param o output can be null - in which case, a new dataset is created
    8475         * @return {@code a / b}, division of a by b but rounded towards negative infinity
    8476         */
    8477        public static Dataset divideTowardsFloor(final Object a, final Object b, final Dataset o) {
    8478                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    8479                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    8480                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    8481                final Dataset result = it.getOutput();
    8482                final int is = result.getElementsPerItem();
    8483                final int as = da.getElementsPerItem();
    8484                final int bs = db.getElementsPerItem();
    8485                final int dt = result.getDType();
    8486
    8487                switch(dt) {
    8488                case Dataset.INT8:
    8489                        final byte[] oi8data = ((ByteDataset) result).getData();
    8490                        if (it.isOutputDouble()) {
    8491                                while (it.hasNext()) {
    8492                                        final double iax = it.aDouble;
    8493                                        final double ibx = it.bDouble;
    8494                                        byte ox;
    8495                                        if (ibx == 0) {
    8496                                                ox = 0;
    8497                                        } else {
    8498                                                ox = (byte) toLong(iax / ibx);
    8499                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8500                                                        ox--;
    8501                                                }
    8502                                        }
    8503                                        oi8data[it.oIndex] = ox;
    8504                                }
    8505                        } else {
    8506                                while (it.hasNext()) {
    8507                                        final long iax = it.aLong;
    8508                                        final long ibx = it.bLong;
    8509                                        byte ox;
    8510                                        if (ibx == 0) {
    8511                                                ox = 0;
    8512                                        } else {
    8513                                                ox = (byte) (iax / ibx);
    8514                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8515                                                        ox--;
    8516                                                }
    8517                                        }
    8518                                        oi8data[it.oIndex] = ox;
    8519                                }
    8520                        }
    8521                        break;
    8522                case Dataset.INT16:
    8523                        final short[] oi16data = ((ShortDataset) result).getData();
    8524                        if (it.isOutputDouble()) {
    8525                                while (it.hasNext()) {
    8526                                        final double iax = it.aDouble;
    8527                                        final double ibx = it.bDouble;
    8528                                        short ox;
    8529                                        if (ibx == 0) {
    8530                                                ox = 0;
    8531                                        } else {
    8532                                                ox = (short) toLong(iax / ibx);
    8533                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8534                                                        ox--;
    8535                                                }
    8536                                        }
    8537                                        oi16data[it.oIndex] = ox;
    8538                                }
    8539                        } else {
    8540                                while (it.hasNext()) {
    8541                                        final long iax = it.aLong;
    8542                                        final long ibx = it.bLong;
    8543                                        short ox;
    8544                                        if (ibx == 0) {
    8545                                                ox = 0;
    8546                                        } else {
    8547                                                ox = (short) (iax / ibx);
    8548                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8549                                                        ox--;
    8550                                                }
    8551                                        }
    8552                                        oi16data[it.oIndex] = ox;
    8553                                }
    8554                        }
    8555                        break;
    8556                case Dataset.INT64:
    8557                        final long[] oi64data = ((LongDataset) result).getData();
    8558                        if (it.isOutputDouble()) {
    8559                                while (it.hasNext()) {
    8560                                        final double iax = it.aDouble;
    8561                                        final double ibx = it.bDouble;
    8562                                        long ox;
    8563                                        if (ibx == 0) {
    8564                                                ox = 0;
    8565                                        } else {
    8566                                                ox = toLong(iax / ibx);
    8567                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8568                                                        ox--;
    8569                                                }
    8570                                        }
    8571                                        oi64data[it.oIndex] = ox;
    8572                                }
    8573                        } else {
    8574                                while (it.hasNext()) {
    8575                                        final long iax = it.aLong;
    8576                                        final long ibx = it.bLong;
    8577                                        long ox;
    8578                                        if (ibx == 0) {
    8579                                                ox = 0;
    8580                                        } else {
    8581                                                ox = (iax / ibx);
    8582                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8583                                                        ox--;
    8584                                                }
    8585                                        }
    8586                                        oi64data[it.oIndex] = ox;
    8587                                }
    8588                        }
    8589                        break;
    8590                case Dataset.INT32:
    8591                        final int[] oi32data = ((IntegerDataset) result).getData();
    8592                        if (it.isOutputDouble()) {
    8593                                while (it.hasNext()) {
    8594                                        final double iax = it.aDouble;
    8595                                        final double ibx = it.bDouble;
    8596                                        int ox;
    8597                                        if (ibx == 0) {
    8598                                                ox = 0;
    8599                                        } else {
    8600                                                ox = (int) toLong(iax / ibx);
    8601                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8602                                                        ox--;
    8603                                                }
    8604                                        }
    8605                                        oi32data[it.oIndex] = ox;
    8606                                }
    8607                        } else {
    8608                                while (it.hasNext()) {
    8609                                        final long iax = it.aLong;
    8610                                        final long ibx = it.bLong;
    8611                                        int ox;
    8612                                        if (ibx == 0) {
    8613                                                ox = 0;
    8614                                        } else {
    8615                                                ox = (int) (iax / ibx);
    8616                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8617                                                        ox--;
    8618                                                }
    8619                                        }
    8620                                        oi32data[it.oIndex] = ox;
    8621                                }
    8622                        }
    8623                        break;
    8624                case Dataset.ARRAYINT8:
    8625                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    8626                        if (is == 1) {
    8627                                if (it.isOutputDouble()) {
    8628                                        while (it.hasNext()) {
    8629                                                final double iax = it.aDouble;
    8630                                                final double ibx = it.bDouble;
    8631                                                byte ox;
    8632                                                if (ibx == 0) {
    8633                                                        ox = 0;
    8634                                                } else {
    8635                                                        ox = (byte) toLong(iax / ibx);
    8636                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8637                                                                ox--;
    8638                                                        }
    8639                                                }
    8640                                                oai8data[it.oIndex] = ox;
    8641                                        }
    8642                                } else {
    8643                                        while (it.hasNext()) {
    8644                                                final long iax = it.aLong;
    8645                                                final long ibx = it.bLong;
    8646                                                byte ox;
    8647                                                if (ibx == 0) {
    8648                                                        ox = 0;
    8649                                                } else {
    8650                                                        ox = (byte) (iax / ibx);
    8651                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8652                                                                ox--;
    8653                                                        }
    8654                                                }
    8655                                                oai8data[it.oIndex] = ox;
    8656                                        }
    8657                                }
    8658                        } else if (as < bs) {
    8659                                if (it.isOutputDouble()) {
    8660                                        while (it.hasNext()) {
    8661                                                final double iax = it.aDouble;
    8662                                                double ibx = it.bDouble;
    8663                                                byte ox;
    8664                                                if (ibx == 0) {
    8665                                                        ox = 0;
    8666                                                } else {
    8667                                                        ox = (byte) toLong(iax / ibx);
    8668                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8669                                                                ox--;
    8670                                                        }
    8671                                                }
    8672                                                oai8data[it.oIndex] = ox;
    8673                                                for (int j = 1; j < is; j++) {
    8674                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8675                                                        if (ibx == 0) {
    8676                                                                ox = 0;
    8677                                                        } else {
    8678                                                                ox = (byte) toLong(iax / ibx);
    8679                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8680                                                                        ox--;
    8681                                                                }
    8682                                                        }
    8683                                                        oai8data[it.oIndex + j] = ox;
    8684                                                }
    8685                                        }
    8686                                } else {
    8687                                        while (it.hasNext()) {
    8688                                                final long iax = it.aLong;
    8689                                                long ibx = it.bLong;
    8690                                                byte ox;
    8691                                                if (ibx == 0) {
    8692                                                        ox = 0;
    8693                                                } else {
    8694                                                        ox = (byte) (iax / ibx);
    8695                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8696                                                                ox--;
    8697                                                        }
    8698                                                }
    8699                                                oai8data[it.oIndex] = ox;
    8700                                                for (int j = 1; j < is; j++) {
    8701                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8702                                                        if (ibx == 0) {
    8703                                                                ox = 0;
    8704                                                        } else {
    8705                                                                ox = (byte) (iax / ibx);
    8706                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8707                                                                        ox--;
    8708                                                                }
    8709                                                        }
    8710                                                        oai8data[it.oIndex + j] = ox;
    8711                                                }
    8712                                        }
    8713                                }
    8714                        } else if (as > bs) {
    8715                                if (it.isOutputDouble()) {
    8716                                        while (it.hasNext()) {
    8717                                                double iax = it.aDouble;
    8718                                                final double ibx = it.bDouble;
    8719                                                byte ox;
    8720                                                if (ibx == 0) {
    8721                                                        ox = 0;
    8722                                                } else {
    8723                                                        ox = (byte) toLong(iax / ibx);
    8724                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8725                                                                ox--;
    8726                                                        }
    8727                                                }
    8728                                                oai8data[it.oIndex] = ox;
    8729                                                for (int j = 1; j < is; j++) {
    8730                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8731                                                        if (ibx == 0) {
    8732                                                                ox = 0;
    8733                                                        } else {
    8734                                                                ox = (byte) toLong(iax / ibx);
    8735                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8736                                                                        ox--;
    8737                                                                }
    8738                                                        }
    8739                                                        oai8data[it.oIndex + j] = ox;
    8740                                                }
    8741                                        }
    8742                                } else {
    8743                                        while (it.hasNext()) {
    8744                                                long iax = it.aLong;
    8745                                                final long ibx = it.bLong;
    8746                                                byte ox;
    8747                                                if (ibx == 0) {
    8748                                                        ox = 0;
    8749                                                } else {
    8750                                                        ox = (byte) (iax / ibx);
    8751                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8752                                                                ox--;
    8753                                                        }
    8754                                                }
    8755                                                oai8data[it.oIndex] = ox;
    8756                                                for (int j = 1; j < is; j++) {
    8757                                                        iax = da.getElementLongAbs(it.aIndex + j);
    8758                                                        if (ibx == 0) {
    8759                                                                ox = 0;
    8760                                                        } else {
    8761                                                                ox = (byte) (iax / ibx);
    8762                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8763                                                                        ox--;
    8764                                                                }
    8765                                                        }
    8766                                                        oai8data[it.oIndex + j] = ox;
    8767                                                }
    8768                                        }
    8769                                }
    8770                        } else if (as == 1) {
    8771                                if (it.isOutputDouble()) {
    8772                                        while (it.hasNext()) {
    8773                                                final double iax = it.aDouble;
    8774                                                final double ibx = it.bDouble;
    8775                                                byte ox;
    8776                                                if (ibx == 0) {
    8777                                                        ox = 0;
    8778                                                } else {
    8779                                                        ox = (byte) toLong(iax / ibx);
    8780                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8781                                                                ox--;
    8782                                                        }
    8783                                                }
    8784                                                for (int j = 0; j < is; j++) {
    8785                                                        oai8data[it.oIndex + j] = ox;
    8786                                                }
    8787                                        }
    8788                                } else {
    8789                                        while (it.hasNext()) {
    8790                                                final long iax = it.aLong;
    8791                                                final long ibx = it.bLong;
    8792                                                byte ox;
    8793                                                if (ibx == 0) {
    8794                                                        ox = 0;
    8795                                                } else {
    8796                                                        ox = (byte) (iax / ibx);
    8797                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8798                                                                ox--;
    8799                                                        }
    8800                                                }
    8801                                                for (int j = 0; j < is; j++) {
    8802                                                        oai8data[it.oIndex + j] = ox;
    8803                                                }
    8804                                        }
    8805                                }
    8806                        } else {
    8807                                if (it.isOutputDouble()) {
    8808                                        while (it.hasNext()) {
    8809                                                double iax = it.aDouble;
    8810                                                double ibx = it.bDouble;
    8811                                                byte ox;
    8812                                                if (ibx == 0) {
    8813                                                        ox = 0;
    8814                                                } else {
    8815                                                        ox = (byte) toLong(iax / ibx);
    8816                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8817                                                                ox--;
    8818                                                        }
    8819                                                }
    8820                                                oai8data[it.oIndex] = ox;
    8821                                                for (int j = 1; j < is; j++) {
    8822                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8823                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8824                                                        if (ibx == 0) {
    8825                                                                ox = 0;
    8826                                                        } else {
    8827                                                                ox = (byte) toLong(iax / ibx);
    8828                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8829                                                                        ox--;
    8830                                                                }
    8831                                                        }
    8832                                                        oai8data[it.oIndex + j] = ox;
    8833                                                }
    8834                                        }
    8835                                } else {
    8836                                        while (it.hasNext()) {
    8837                                                long iax = it.aLong;
    8838                                                long ibx = it.bLong;
    8839                                                byte ox;
    8840                                                if (ibx == 0) {
    8841                                                        ox = 0;
    8842                                                } else {
    8843                                                        ox = (byte) (iax / ibx);
    8844                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8845                                                                ox--;
    8846                                                        }
    8847                                                }
    8848                                                oai8data[it.oIndex] = ox;
    8849                                                for (int j = 1; j < is; j++) {
    8850                                                        iax = da.getElementLongAbs(it.aIndex + j);
    8851                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8852                                                        if (ibx == 0) {
    8853                                                                ox = 0;
    8854                                                        } else {
    8855                                                                ox = (byte) (iax / ibx);
    8856                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8857                                                                        ox--;
    8858                                                                }
    8859                                                        }
    8860                                                        oai8data[it.oIndex + j] = ox;
    8861                                                }
    8862                                        }
    8863                                }
    8864                        }
    8865                        break;
    8866                case Dataset.ARRAYINT16:
    8867                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    8868                        if (is == 1) {
    8869                                if (it.isOutputDouble()) {
    8870                                        while (it.hasNext()) {
    8871                                                final double iax = it.aDouble;
    8872                                                final double ibx = it.bDouble;
    8873                                                short ox;
    8874                                                if (ibx == 0) {
    8875                                                        ox = 0;
    8876                                                } else {
    8877                                                        ox = (short) toLong(iax / ibx);
    8878                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8879                                                                ox--;
    8880                                                        }
    8881                                                }
    8882                                                oai16data[it.oIndex] = ox;
    8883                                        }
    8884                                } else {
    8885                                        while (it.hasNext()) {
    8886                                                final long iax = it.aLong;
    8887                                                final long ibx = it.bLong;
    8888                                                short ox;
    8889                                                if (ibx == 0) {
    8890                                                        ox = 0;
    8891                                                } else {
    8892                                                        ox = (short) (iax / ibx);
    8893                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8894                                                                ox--;
    8895                                                        }
    8896                                                }
    8897                                                oai16data[it.oIndex] = ox;
    8898                                        }
    8899                                }
    8900                        } else if (as < bs) {
    8901                                if (it.isOutputDouble()) {
    8902                                        while (it.hasNext()) {
    8903                                                final double iax = it.aDouble;
    8904                                                double ibx = it.bDouble;
    8905                                                short ox;
    8906                                                if (ibx == 0) {
    8907                                                        ox = 0;
    8908                                                } else {
    8909                                                        ox = (short) toLong(iax / ibx);
    8910                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8911                                                                ox--;
    8912                                                        }
    8913                                                }
    8914                                                oai16data[it.oIndex] = ox;
    8915                                                for (int j = 1; j < is; j++) {
    8916                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    8917                                                        if (ibx == 0) {
    8918                                                                ox = 0;
    8919                                                        } else {
    8920                                                                ox = (short) toLong(iax / ibx);
    8921                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8922                                                                        ox--;
    8923                                                                }
    8924                                                        }
    8925                                                        oai16data[it.oIndex + j] = ox;
    8926                                                }
    8927                                        }
    8928                                } else {
    8929                                        while (it.hasNext()) {
    8930                                                final long iax = it.aLong;
    8931                                                long ibx = it.bLong;
    8932                                                short ox;
    8933                                                if (ibx == 0) {
    8934                                                        ox = 0;
    8935                                                } else {
    8936                                                        ox = (short) (iax / ibx);
    8937                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8938                                                                ox--;
    8939                                                        }
    8940                                                }
    8941                                                oai16data[it.oIndex] = ox;
    8942                                                for (int j = 1; j < is; j++) {
    8943                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    8944                                                        if (ibx == 0) {
    8945                                                                ox = 0;
    8946                                                        } else {
    8947                                                                ox = (short) (iax / ibx);
    8948                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8949                                                                        ox--;
    8950                                                                }
    8951                                                        }
    8952                                                        oai16data[it.oIndex + j] = ox;
    8953                                                }
    8954                                        }
    8955                                }
    8956                        } else if (as > bs) {
    8957                                if (it.isOutputDouble()) {
    8958                                        while (it.hasNext()) {
    8959                                                double iax = it.aDouble;
    8960                                                final double ibx = it.bDouble;
    8961                                                short ox;
    8962                                                if (ibx == 0) {
    8963                                                        ox = 0;
    8964                                                } else {
    8965                                                        ox = (short) toLong(iax / ibx);
    8966                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8967                                                                ox--;
    8968                                                        }
    8969                                                }
    8970                                                oai16data[it.oIndex] = ox;
    8971                                                for (int j = 1; j < is; j++) {
    8972                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    8973                                                        if (ibx == 0) {
    8974                                                                ox = 0;
    8975                                                        } else {
    8976                                                                ox = (short) toLong(iax / ibx);
    8977                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8978                                                                        ox--;
    8979                                                                }
    8980                                                        }
    8981                                                        oai16data[it.oIndex + j] = ox;
    8982                                                }
    8983                                        }
    8984                                } else {
    8985                                        while (it.hasNext()) {
    8986                                                long iax = it.aLong;
    8987                                                final long ibx = it.bLong;
    8988                                                short ox;
    8989                                                if (ibx == 0) {
    8990                                                        ox = 0;
    8991                                                } else {
    8992                                                        ox = (short) (iax / ibx);
    8993                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    8994                                                                ox--;
    8995                                                        }
    8996                                                }
    8997                                                oai16data[it.oIndex] = ox;
    8998                                                for (int j = 1; j < is; j++) {
    8999                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9000                                                        if (ibx == 0) {
    9001                                                                ox = 0;
    9002                                                        } else {
    9003                                                                ox = (short) (iax / ibx);
    9004                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9005                                                                        ox--;
    9006                                                                }
    9007                                                        }
    9008                                                        oai16data[it.oIndex + j] = ox;
    9009                                                }
    9010                                        }
    9011                                }
    9012                        } else if (as == 1) {
    9013                                if (it.isOutputDouble()) {
    9014                                        while (it.hasNext()) {
    9015                                                final double iax = it.aDouble;
    9016                                                final double ibx = it.bDouble;
    9017                                                short ox;
    9018                                                if (ibx == 0) {
    9019                                                        ox = 0;
    9020                                                } else {
    9021                                                        ox = (short) toLong(iax / ibx);
    9022                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9023                                                                ox--;
    9024                                                        }
    9025                                                }
    9026                                                for (int j = 0; j < is; j++) {
    9027                                                        oai16data[it.oIndex + j] = ox;
    9028                                                }
    9029                                        }
    9030                                } else {
    9031                                        while (it.hasNext()) {
    9032                                                final long iax = it.aLong;
    9033                                                final long ibx = it.bLong;
    9034                                                short ox;
    9035                                                if (ibx == 0) {
    9036                                                        ox = 0;
    9037                                                } else {
    9038                                                        ox = (short) (iax / ibx);
    9039                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9040                                                                ox--;
    9041                                                        }
    9042                                                }
    9043                                                for (int j = 0; j < is; j++) {
    9044                                                        oai16data[it.oIndex + j] = ox;
    9045                                                }
    9046                                        }
    9047                                }
    9048                        } else {
    9049                                if (it.isOutputDouble()) {
    9050                                        while (it.hasNext()) {
    9051                                                double iax = it.aDouble;
    9052                                                double ibx = it.bDouble;
    9053                                                short ox;
    9054                                                if (ibx == 0) {
    9055                                                        ox = 0;
    9056                                                } else {
    9057                                                        ox = (short) toLong(iax / ibx);
    9058                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9059                                                                ox--;
    9060                                                        }
    9061                                                }
    9062                                                oai16data[it.oIndex] = ox;
    9063                                                for (int j = 1; j < is; j++) {
    9064                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9065                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9066                                                        if (ibx == 0) {
    9067                                                                ox = 0;
    9068                                                        } else {
    9069                                                                ox = (short) toLong(iax / ibx);
    9070                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9071                                                                        ox--;
    9072                                                                }
    9073                                                        }
    9074                                                        oai16data[it.oIndex + j] = ox;
    9075                                                }
    9076                                        }
    9077                                } else {
    9078                                        while (it.hasNext()) {
    9079                                                long iax = it.aLong;
    9080                                                long ibx = it.bLong;
    9081                                                short ox;
    9082                                                if (ibx == 0) {
    9083                                                        ox = 0;
    9084                                                } else {
    9085                                                        ox = (short) (iax / ibx);
    9086                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9087                                                                ox--;
    9088                                                        }
    9089                                                }
    9090                                                oai16data[it.oIndex] = ox;
    9091                                                for (int j = 1; j < is; j++) {
    9092                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9093                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9094                                                        if (ibx == 0) {
    9095                                                                ox = 0;
    9096                                                        } else {
    9097                                                                ox = (short) (iax / ibx);
    9098                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9099                                                                        ox--;
    9100                                                                }
    9101                                                        }
    9102                                                        oai16data[it.oIndex + j] = ox;
    9103                                                }
    9104                                        }
    9105                                }
    9106                        }
    9107                        break;
    9108                case Dataset.ARRAYINT64:
    9109                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    9110                        if (is == 1) {
    9111                                if (it.isOutputDouble()) {
    9112                                        while (it.hasNext()) {
    9113                                                final double iax = it.aDouble;
    9114                                                final double ibx = it.bDouble;
    9115                                                long ox;
    9116                                                if (ibx == 0) {
    9117                                                        ox = 0;
    9118                                                } else {
    9119                                                        ox = toLong(iax / ibx);
    9120                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9121                                                                ox--;
    9122                                                        }
    9123                                                }
    9124                                                oai64data[it.oIndex] = ox;
    9125                                        }
    9126                                } else {
    9127                                        while (it.hasNext()) {
    9128                                                final long iax = it.aLong;
    9129                                                final long ibx = it.bLong;
    9130                                                long ox;
    9131                                                if (ibx == 0) {
    9132                                                        ox = 0;
    9133                                                } else {
    9134                                                        ox = (iax / ibx);
    9135                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9136                                                                ox--;
    9137                                                        }
    9138                                                }
    9139                                                oai64data[it.oIndex] = ox;
    9140                                        }
    9141                                }
    9142                        } else if (as < bs) {
    9143                                if (it.isOutputDouble()) {
    9144                                        while (it.hasNext()) {
    9145                                                final double iax = it.aDouble;
    9146                                                double ibx = it.bDouble;
    9147                                                long ox;
    9148                                                if (ibx == 0) {
    9149                                                        ox = 0;
    9150                                                } else {
    9151                                                        ox = toLong(iax / ibx);
    9152                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9153                                                                ox--;
    9154                                                        }
    9155                                                }
    9156                                                oai64data[it.oIndex] = ox;
    9157                                                for (int j = 1; j < is; j++) {
    9158                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9159                                                        if (ibx == 0) {
    9160                                                                ox = 0;
    9161                                                        } else {
    9162                                                                ox = toLong(iax / ibx);
    9163                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9164                                                                        ox--;
    9165                                                                }
    9166                                                        }
    9167                                                        oai64data[it.oIndex + j] = ox;
    9168                                                }
    9169                                        }
    9170                                } else {
    9171                                        while (it.hasNext()) {
    9172                                                final long iax = it.aLong;
    9173                                                long ibx = it.bLong;
    9174                                                long ox;
    9175                                                if (ibx == 0) {
    9176                                                        ox = 0;
    9177                                                } else {
    9178                                                        ox = (iax / ibx);
    9179                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9180                                                                ox--;
    9181                                                        }
    9182                                                }
    9183                                                oai64data[it.oIndex] = ox;
    9184                                                for (int j = 1; j < is; j++) {
    9185                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9186                                                        if (ibx == 0) {
    9187                                                                ox = 0;
    9188                                                        } else {
    9189                                                                ox = (iax / ibx);
    9190                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9191                                                                        ox--;
    9192                                                                }
    9193                                                        }
    9194                                                        oai64data[it.oIndex + j] = ox;
    9195                                                }
    9196                                        }
    9197                                }
    9198                        } else if (as > bs) {
    9199                                if (it.isOutputDouble()) {
    9200                                        while (it.hasNext()) {
    9201                                                double iax = it.aDouble;
    9202                                                final double ibx = it.bDouble;
    9203                                                long ox;
    9204                                                if (ibx == 0) {
    9205                                                        ox = 0;
    9206                                                } else {
    9207                                                        ox = toLong(iax / ibx);
    9208                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9209                                                                ox--;
    9210                                                        }
    9211                                                }
    9212                                                oai64data[it.oIndex] = ox;
    9213                                                for (int j = 1; j < is; j++) {
    9214                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9215                                                        if (ibx == 0) {
    9216                                                                ox = 0;
    9217                                                        } else {
    9218                                                                ox = toLong(iax / ibx);
    9219                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9220                                                                        ox--;
    9221                                                                }
    9222                                                        }
    9223                                                        oai64data[it.oIndex + j] = ox;
    9224                                                }
    9225                                        }
    9226                                } else {
    9227                                        while (it.hasNext()) {
    9228                                                long iax = it.aLong;
    9229                                                final long ibx = it.bLong;
    9230                                                long ox;
    9231                                                if (ibx == 0) {
    9232                                                        ox = 0;
    9233                                                } else {
    9234                                                        ox = (iax / ibx);
    9235                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9236                                                                ox--;
    9237                                                        }
    9238                                                }
    9239                                                oai64data[it.oIndex] = ox;
    9240                                                for (int j = 1; j < is; j++) {
    9241                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9242                                                        if (ibx == 0) {
    9243                                                                ox = 0;
    9244                                                        } else {
    9245                                                                ox = (iax / ibx);
    9246                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9247                                                                        ox--;
    9248                                                                }
    9249                                                        }
    9250                                                        oai64data[it.oIndex + j] = ox;
    9251                                                }
    9252                                        }
    9253                                }
    9254                        } else if (as == 1) {
    9255                                if (it.isOutputDouble()) {
    9256                                        while (it.hasNext()) {
    9257                                                final double iax = it.aDouble;
    9258                                                final double ibx = it.bDouble;
    9259                                                long ox;
    9260                                                if (ibx == 0) {
    9261                                                        ox = 0;
    9262                                                } else {
    9263                                                        ox = toLong(iax / ibx);
    9264                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9265                                                                ox--;
    9266                                                        }
    9267                                                }
    9268                                                for (int j = 0; j < is; j++) {
    9269                                                        oai64data[it.oIndex + j] = ox;
    9270                                                }
    9271                                        }
    9272                                } else {
    9273                                        while (it.hasNext()) {
    9274                                                final long iax = it.aLong;
    9275                                                final long ibx = it.bLong;
    9276                                                long ox;
    9277                                                if (ibx == 0) {
    9278                                                        ox = 0;
    9279                                                } else {
    9280                                                        ox = (iax / ibx);
    9281                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9282                                                                ox--;
    9283                                                        }
    9284                                                }
    9285                                                for (int j = 0; j < is; j++) {
    9286                                                        oai64data[it.oIndex + j] = ox;
    9287                                                }
    9288                                        }
    9289                                }
    9290                        } else {
    9291                                if (it.isOutputDouble()) {
    9292                                        while (it.hasNext()) {
    9293                                                double iax = it.aDouble;
    9294                                                double ibx = it.bDouble;
    9295                                                long ox;
    9296                                                if (ibx == 0) {
    9297                                                        ox = 0;
    9298                                                } else {
    9299                                                        ox = toLong(iax / ibx);
    9300                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9301                                                                ox--;
    9302                                                        }
    9303                                                }
    9304                                                oai64data[it.oIndex] = ox;
    9305                                                for (int j = 1; j < is; j++) {
    9306                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9307                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9308                                                        if (ibx == 0) {
    9309                                                                ox = 0;
    9310                                                        } else {
    9311                                                                ox = toLong(iax / ibx);
    9312                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9313                                                                        ox--;
    9314                                                                }
    9315                                                        }
    9316                                                        oai64data[it.oIndex + j] = ox;
    9317                                                }
    9318                                        }
    9319                                } else {
    9320                                        while (it.hasNext()) {
    9321                                                long iax = it.aLong;
    9322                                                long ibx = it.bLong;
    9323                                                long ox;
    9324                                                if (ibx == 0) {
    9325                                                        ox = 0;
    9326                                                } else {
    9327                                                        ox = (iax / ibx);
    9328                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9329                                                                ox--;
    9330                                                        }
    9331                                                }
    9332                                                oai64data[it.oIndex] = ox;
    9333                                                for (int j = 1; j < is; j++) {
    9334                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9335                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9336                                                        if (ibx == 0) {
    9337                                                                ox = 0;
    9338                                                        } else {
    9339                                                                ox = (iax / ibx);
    9340                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9341                                                                        ox--;
    9342                                                                }
    9343                                                        }
    9344                                                        oai64data[it.oIndex + j] = ox;
    9345                                                }
    9346                                        }
    9347                                }
    9348                        }
    9349                        break;
    9350                case Dataset.ARRAYINT32:
    9351                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    9352                        if (is == 1) {
    9353                                if (it.isOutputDouble()) {
    9354                                        while (it.hasNext()) {
    9355                                                final double iax = it.aDouble;
    9356                                                final double ibx = it.bDouble;
    9357                                                int ox;
    9358                                                if (ibx == 0) {
    9359                                                        ox = 0;
    9360                                                } else {
    9361                                                        ox = (int) toLong(iax / ibx);
    9362                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9363                                                                ox--;
    9364                                                        }
    9365                                                }
    9366                                                oai32data[it.oIndex] = ox;
    9367                                        }
    9368                                } else {
    9369                                        while (it.hasNext()) {
    9370                                                final long iax = it.aLong;
    9371                                                final long ibx = it.bLong;
    9372                                                int ox;
    9373                                                if (ibx == 0) {
    9374                                                        ox = 0;
    9375                                                } else {
    9376                                                        ox = (int) (iax / ibx);
    9377                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9378                                                                ox--;
    9379                                                        }
    9380                                                }
    9381                                                oai32data[it.oIndex] = ox;
    9382                                        }
    9383                                }
    9384                        } else if (as < bs) {
    9385                                if (it.isOutputDouble()) {
    9386                                        while (it.hasNext()) {
    9387                                                final double iax = it.aDouble;
    9388                                                double ibx = it.bDouble;
    9389                                                int ox;
    9390                                                if (ibx == 0) {
    9391                                                        ox = 0;
    9392                                                } else {
    9393                                                        ox = (int) toLong(iax / ibx);
    9394                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9395                                                                ox--;
    9396                                                        }
    9397                                                }
    9398                                                oai32data[it.oIndex] = ox;
    9399                                                for (int j = 1; j < is; j++) {
    9400                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9401                                                        if (ibx == 0) {
    9402                                                                ox = 0;
    9403                                                        } else {
    9404                                                                ox = (int) toLong(iax / ibx);
    9405                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9406                                                                        ox--;
    9407                                                                }
    9408                                                        }
    9409                                                        oai32data[it.oIndex + j] = ox;
    9410                                                }
    9411                                        }
    9412                                } else {
    9413                                        while (it.hasNext()) {
    9414                                                final long iax = it.aLong;
    9415                                                long ibx = it.bLong;
    9416                                                int ox;
    9417                                                if (ibx == 0) {
    9418                                                        ox = 0;
    9419                                                } else {
    9420                                                        ox = (int) (iax / ibx);
    9421                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9422                                                                ox--;
    9423                                                        }
    9424                                                }
    9425                                                oai32data[it.oIndex] = ox;
    9426                                                for (int j = 1; j < is; j++) {
    9427                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9428                                                        if (ibx == 0) {
    9429                                                                ox = 0;
    9430                                                        } else {
    9431                                                                ox = (int) (iax / ibx);
    9432                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9433                                                                        ox--;
    9434                                                                }
    9435                                                        }
    9436                                                        oai32data[it.oIndex + j] = ox;
    9437                                                }
    9438                                        }
    9439                                }
    9440                        } else if (as > bs) {
    9441                                if (it.isOutputDouble()) {
    9442                                        while (it.hasNext()) {
    9443                                                double iax = it.aDouble;
    9444                                                final double ibx = it.bDouble;
    9445                                                int ox;
    9446                                                if (ibx == 0) {
    9447                                                        ox = 0;
    9448                                                } else {
    9449                                                        ox = (int) toLong(iax / ibx);
    9450                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9451                                                                ox--;
    9452                                                        }
    9453                                                }
    9454                                                oai32data[it.oIndex] = ox;
    9455                                                for (int j = 1; j < is; j++) {
    9456                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9457                                                        if (ibx == 0) {
    9458                                                                ox = 0;
    9459                                                        } else {
    9460                                                                ox = (int) toLong(iax / ibx);
    9461                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9462                                                                        ox--;
    9463                                                                }
    9464                                                        }
    9465                                                        oai32data[it.oIndex + j] = ox;
    9466                                                }
    9467                                        }
    9468                                } else {
    9469                                        while (it.hasNext()) {
    9470                                                long iax = it.aLong;
    9471                                                final long ibx = it.bLong;
    9472                                                int ox;
    9473                                                if (ibx == 0) {
    9474                                                        ox = 0;
    9475                                                } else {
    9476                                                        ox = (int) (iax / ibx);
    9477                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9478                                                                ox--;
    9479                                                        }
    9480                                                }
    9481                                                oai32data[it.oIndex] = ox;
    9482                                                for (int j = 1; j < is; j++) {
    9483                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9484                                                        if (ibx == 0) {
    9485                                                                ox = 0;
    9486                                                        } else {
    9487                                                                ox = (int) (iax / ibx);
    9488                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9489                                                                        ox--;
    9490                                                                }
    9491                                                        }
    9492                                                        oai32data[it.oIndex + j] = ox;
    9493                                                }
    9494                                        }
    9495                                }
    9496                        } else if (as == 1) {
    9497                                if (it.isOutputDouble()) {
    9498                                        while (it.hasNext()) {
    9499                                                final double iax = it.aDouble;
    9500                                                final double ibx = it.bDouble;
    9501                                                int ox;
    9502                                                if (ibx == 0) {
    9503                                                        ox = 0;
    9504                                                } else {
    9505                                                        ox = (int) toLong(iax / ibx);
    9506                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9507                                                                ox--;
    9508                                                        }
    9509                                                }
    9510                                                for (int j = 0; j < is; j++) {
    9511                                                        oai32data[it.oIndex + j] = ox;
    9512                                                }
    9513                                        }
    9514                                } else {
    9515                                        while (it.hasNext()) {
    9516                                                final long iax = it.aLong;
    9517                                                final long ibx = it.bLong;
    9518                                                int ox;
    9519                                                if (ibx == 0) {
    9520                                                        ox = 0;
    9521                                                } else {
    9522                                                        ox = (int) (iax / ibx);
    9523                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9524                                                                ox--;
    9525                                                        }
    9526                                                }
    9527                                                for (int j = 0; j < is; j++) {
    9528                                                        oai32data[it.oIndex + j] = ox;
    9529                                                }
    9530                                        }
    9531                                }
    9532                        } else {
    9533                                if (it.isOutputDouble()) {
    9534                                        while (it.hasNext()) {
    9535                                                double iax = it.aDouble;
    9536                                                double ibx = it.bDouble;
    9537                                                int ox;
    9538                                                if (ibx == 0) {
    9539                                                        ox = 0;
    9540                                                } else {
    9541                                                        ox = (int) toLong(iax / ibx);
    9542                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9543                                                                ox--;
    9544                                                        }
    9545                                                }
    9546                                                oai32data[it.oIndex] = ox;
    9547                                                for (int j = 1; j < is; j++) {
    9548                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9549                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9550                                                        if (ibx == 0) {
    9551                                                                ox = 0;
    9552                                                        } else {
    9553                                                                ox = (int) toLong(iax / ibx);
    9554                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9555                                                                        ox--;
    9556                                                                }
    9557                                                        }
    9558                                                        oai32data[it.oIndex + j] = ox;
    9559                                                }
    9560                                        }
    9561                                } else {
    9562                                        while (it.hasNext()) {
    9563                                                long iax = it.aLong;
    9564                                                long ibx = it.bLong;
    9565                                                int ox;
    9566                                                if (ibx == 0) {
    9567                                                        ox = 0;
    9568                                                } else {
    9569                                                        ox = (int) (iax / ibx);
    9570                                                        if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9571                                                                ox--;
    9572                                                        }
    9573                                                }
    9574                                                oai32data[it.oIndex] = ox;
    9575                                                for (int j = 1; j < is; j++) {
    9576                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9577                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9578                                                        if (ibx == 0) {
    9579                                                                ox = 0;
    9580                                                        } else {
    9581                                                                ox = (int) (iax / ibx);
    9582                                                                if (iax != ox * ibx && ((iax < 0) ^ (ibx < 0))) {
    9583                                                                        ox--;
    9584                                                                }
    9585                                                        }
    9586                                                        oai32data[it.oIndex + j] = ox;
    9587                                                }
    9588                                        }
    9589                                }
    9590                        }
    9591                        break;
    9592                case Dataset.FLOAT32:
    9593                        final float[] of32data = ((FloatDataset) result).getData();
    9594                        if (it.isOutputDouble()) {
    9595                                while (it.hasNext()) {
    9596                                        final double iax = it.aDouble;
    9597                                        final double ibx = it.bDouble;
    9598                                        float ox;
    9599                                        ox = (float) (iax / ibx);
    9600                                        of32data[it.oIndex] = ox;
    9601                                }
    9602                        } else {
    9603                                while (it.hasNext()) {
    9604                                        final long iax = it.aLong;
    9605                                        final long ibx = it.bLong;
    9606                                        float ox;
    9607                                        ox = (iax / ibx);
    9608                                        of32data[it.oIndex] = ox;
    9609                                }
    9610                        }
    9611                        break;
    9612                case Dataset.FLOAT64:
    9613                        final double[] of64data = ((DoubleDataset) result).getData();
    9614                        if (it.isOutputDouble()) {
    9615                                while (it.hasNext()) {
    9616                                        final double iax = it.aDouble;
    9617                                        final double ibx = it.bDouble;
    9618                                        double ox;
    9619                                        ox = (iax / ibx);
    9620                                        of64data[it.oIndex] = ox;
    9621                                }
    9622                        } else {
    9623                                while (it.hasNext()) {
    9624                                        final long iax = it.aLong;
    9625                                        final long ibx = it.bLong;
    9626                                        double ox;
    9627                                        ox = (iax / ibx);
    9628                                        of64data[it.oIndex] = ox;
    9629                                }
    9630                        }
    9631                        break;
    9632                case Dataset.ARRAYFLOAT32:
    9633                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    9634                        if (is == 1) {
    9635                                if (it.isOutputDouble()) {
    9636                                        while (it.hasNext()) {
    9637                                                final double iax = it.aDouble;
    9638                                                final double ibx = it.bDouble;
    9639                                                float ox;
    9640                                                ox = (float) (iax / ibx);
    9641                                                oaf32data[it.oIndex] = ox;
    9642                                        }
    9643                                } else {
    9644                                        while (it.hasNext()) {
    9645                                                final long iax = it.aLong;
    9646                                                final long ibx = it.bLong;
    9647                                                float ox;
    9648                                                ox = (iax / ibx);
    9649                                                oaf32data[it.oIndex] = ox;
    9650                                        }
    9651                                }
    9652                        } else if (as < bs) {
    9653                                if (it.isOutputDouble()) {
    9654                                        while (it.hasNext()) {
    9655                                                final double iax = it.aDouble;
    9656                                                double ibx = it.bDouble;
    9657                                                float ox;
    9658                                                ox = (float) (iax / ibx);
    9659                                                oaf32data[it.oIndex] = ox;
    9660                                                for (int j = 1; j < is; j++) {
    9661                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9662                                                        ox = (float) (iax / ibx);
    9663                                                        oaf32data[it.oIndex + j] = ox;
    9664                                                }
    9665                                        }
    9666                                } else {
    9667                                        while (it.hasNext()) {
    9668                                                final long iax = it.aLong;
    9669                                                long ibx = it.bLong;
    9670                                                float ox;
    9671                                                ox = (iax / ibx);
    9672                                                oaf32data[it.oIndex] = ox;
    9673                                                for (int j = 1; j < is; j++) {
    9674                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9675                                                        ox = (iax / ibx);
    9676                                                        oaf32data[it.oIndex + j] = ox;
    9677                                                }
    9678                                        }
    9679                                }
    9680                        } else if (as > bs) {
    9681                                if (it.isOutputDouble()) {
    9682                                        while (it.hasNext()) {
    9683                                                double iax = it.aDouble;
    9684                                                final double ibx = it.bDouble;
    9685                                                float ox;
    9686                                                ox = (float) (iax / ibx);
    9687                                                oaf32data[it.oIndex] = ox;
    9688                                                for (int j = 1; j < is; j++) {
    9689                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9690                                                        ox = (float) (iax / ibx);
    9691                                                        oaf32data[it.oIndex + j] = ox;
    9692                                                }
    9693                                        }
    9694                                } else {
    9695                                        while (it.hasNext()) {
    9696                                                long iax = it.aLong;
    9697                                                final long ibx = it.bLong;
    9698                                                float ox;
    9699                                                ox = (iax / ibx);
    9700                                                oaf32data[it.oIndex] = ox;
    9701                                                for (int j = 1; j < is; j++) {
    9702                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9703                                                        ox = (iax / ibx);
    9704                                                        oaf32data[it.oIndex + j] = ox;
    9705                                                }
    9706                                        }
    9707                                }
    9708                        } else if (as == 1) {
    9709                                if (it.isOutputDouble()) {
    9710                                        while (it.hasNext()) {
    9711                                                final double iax = it.aDouble;
    9712                                                final double ibx = it.bDouble;
    9713                                                float ox;
    9714                                                ox = (float) (iax / ibx);
    9715                                                for (int j = 0; j < is; j++) {
    9716                                                        oaf32data[it.oIndex + j] = ox;
    9717                                                }
    9718                                        }
    9719                                } else {
    9720                                        while (it.hasNext()) {
    9721                                                final long iax = it.aLong;
    9722                                                final long ibx = it.bLong;
    9723                                                float ox;
    9724                                                ox = (iax / ibx);
    9725                                                for (int j = 0; j < is; j++) {
    9726                                                        oaf32data[it.oIndex + j] = ox;
    9727                                                }
    9728                                        }
    9729                                }
    9730                        } else {
    9731                                if (it.isOutputDouble()) {
    9732                                        while (it.hasNext()) {
    9733                                                double iax = it.aDouble;
    9734                                                double ibx = it.bDouble;
    9735                                                float ox;
    9736                                                ox = (float) (iax / ibx);
    9737                                                oaf32data[it.oIndex] = ox;
    9738                                                for (int j = 1; j < is; j++) {
    9739                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9740                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9741                                                        ox = (float) (iax / ibx);
    9742                                                        oaf32data[it.oIndex + j] = ox;
    9743                                                }
    9744                                        }
    9745                                } else {
    9746                                        while (it.hasNext()) {
    9747                                                long iax = it.aLong;
    9748                                                long ibx = it.bLong;
    9749                                                float ox;
    9750                                                ox = (iax / ibx);
    9751                                                oaf32data[it.oIndex] = ox;
    9752                                                for (int j = 1; j < is; j++) {
    9753                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9754                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9755                                                        ox = (iax / ibx);
    9756                                                        oaf32data[it.oIndex + j] = ox;
    9757                                                }
    9758                                        }
    9759                                }
    9760                        }
    9761                        break;
    9762                case Dataset.ARRAYFLOAT64:
    9763                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    9764                        if (is == 1) {
    9765                                if (it.isOutputDouble()) {
    9766                                        while (it.hasNext()) {
    9767                                                final double iax = it.aDouble;
    9768                                                final double ibx = it.bDouble;
    9769                                                double ox;
    9770                                                ox = (iax / ibx);
    9771                                                oaf64data[it.oIndex] = ox;
    9772                                        }
    9773                                } else {
    9774                                        while (it.hasNext()) {
    9775                                                final long iax = it.aLong;
    9776                                                final long ibx = it.bLong;
    9777                                                double ox;
    9778                                                ox = (iax / ibx);
    9779                                                oaf64data[it.oIndex] = ox;
    9780                                        }
    9781                                }
    9782                        } else if (as < bs) {
    9783                                if (it.isOutputDouble()) {
    9784                                        while (it.hasNext()) {
    9785                                                final double iax = it.aDouble;
    9786                                                double ibx = it.bDouble;
    9787                                                double ox;
    9788                                                ox = (iax / ibx);
    9789                                                oaf64data[it.oIndex] = ox;
    9790                                                for (int j = 1; j < is; j++) {
    9791                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9792                                                        ox = (iax / ibx);
    9793                                                        oaf64data[it.oIndex + j] = ox;
    9794                                                }
    9795                                        }
    9796                                } else {
    9797                                        while (it.hasNext()) {
    9798                                                final long iax = it.aLong;
    9799                                                long ibx = it.bLong;
    9800                                                double ox;
    9801                                                ox = (iax / ibx);
    9802                                                oaf64data[it.oIndex] = ox;
    9803                                                for (int j = 1; j < is; j++) {
    9804                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9805                                                        ox = (iax / ibx);
    9806                                                        oaf64data[it.oIndex + j] = ox;
    9807                                                }
    9808                                        }
    9809                                }
    9810                        } else if (as > bs) {
    9811                                if (it.isOutputDouble()) {
    9812                                        while (it.hasNext()) {
    9813                                                double iax = it.aDouble;
    9814                                                final double ibx = it.bDouble;
    9815                                                double ox;
    9816                                                ox = (iax / ibx);
    9817                                                oaf64data[it.oIndex] = ox;
    9818                                                for (int j = 1; j < is; j++) {
    9819                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9820                                                        ox = (iax / ibx);
    9821                                                        oaf64data[it.oIndex + j] = ox;
    9822                                                }
    9823                                        }
    9824                                } else {
    9825                                        while (it.hasNext()) {
    9826                                                long iax = it.aLong;
    9827                                                final long ibx = it.bLong;
    9828                                                double ox;
    9829                                                ox = (iax / ibx);
    9830                                                oaf64data[it.oIndex] = ox;
    9831                                                for (int j = 1; j < is; j++) {
    9832                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9833                                                        ox = (iax / ibx);
    9834                                                        oaf64data[it.oIndex + j] = ox;
    9835                                                }
    9836                                        }
    9837                                }
    9838                        } else if (as == 1) {
    9839                                if (it.isOutputDouble()) {
    9840                                        while (it.hasNext()) {
    9841                                                final double iax = it.aDouble;
    9842                                                final double ibx = it.bDouble;
    9843                                                double ox;
    9844                                                ox = (iax / ibx);
    9845                                                for (int j = 0; j < is; j++) {
    9846                                                        oaf64data[it.oIndex + j] = ox;
    9847                                                }
    9848                                        }
    9849                                } else {
    9850                                        while (it.hasNext()) {
    9851                                                final long iax = it.aLong;
    9852                                                final long ibx = it.bLong;
    9853                                                double ox;
    9854                                                ox = (iax / ibx);
    9855                                                for (int j = 0; j < is; j++) {
    9856                                                        oaf64data[it.oIndex + j] = ox;
    9857                                                }
    9858                                        }
    9859                                }
    9860                        } else {
    9861                                if (it.isOutputDouble()) {
    9862                                        while (it.hasNext()) {
    9863                                                double iax = it.aDouble;
    9864                                                double ibx = it.bDouble;
    9865                                                double ox;
    9866                                                ox = (iax / ibx);
    9867                                                oaf64data[it.oIndex] = ox;
    9868                                                for (int j = 1; j < is; j++) {
    9869                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    9870                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    9871                                                        ox = (iax / ibx);
    9872                                                        oaf64data[it.oIndex + j] = ox;
    9873                                                }
    9874                                        }
    9875                                } else {
    9876                                        while (it.hasNext()) {
    9877                                                long iax = it.aLong;
    9878                                                long ibx = it.bLong;
    9879                                                double ox;
    9880                                                ox = (iax / ibx);
    9881                                                oaf64data[it.oIndex] = ox;
    9882                                                for (int j = 1; j < is; j++) {
    9883                                                        iax = da.getElementLongAbs(it.aIndex + j);
    9884                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    9885                                                        ox = (iax / ibx);
    9886                                                        oaf64data[it.oIndex + j] = ox;
    9887                                                }
    9888                                        }
    9889                                }
    9890                        }
    9891                        break;
    9892                case Dataset.COMPLEX64:
    9893                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    9894                        if (as == 1) {
    9895                                final double iay = 0;
    9896                                while (it.hasNext()) {
    9897                                        final double iax = it.aDouble;
    9898                                        final double ibx = it.bDouble;
    9899                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    9900                                        float ox;
    9901                                        float oy;
    9902                                        float q;
    9903                                        float den;
    9904                                        if (iby == 0) {
    9905                                                ox = (float) (iax / ibx);
    9906                                                oy = (float) (iay / ibx);
    9907                                        } else if (ibx == 0) {
    9908                                                ox = (float) (iay / iby);
    9909                                                oy = (float) (-iax / iby);
    9910                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    9911                                                q = (float) (ibx / iby);
    9912                                                den = (float) (ibx * q + iby);
    9913                                                ox = (float) ((iax * q + iay) / den);
    9914                                                oy = (float) ((iay * q - ibx) / den);
    9915                                        } else {
    9916                                                q = (float) (iby / ibx);
    9917                                                den = (float) (iby * q + ibx);
    9918                                                ox = (float) ((iay * q + iax) / den);
    9919                                                oy = (float) ((iay - iax * q) / den);
    9920                                        }
    9921                                        oc64data[it.oIndex] = ox;
    9922                                        oc64data[it.oIndex + 1] = oy;
    9923                                }
    9924                        } else if (bs == 1) {
    9925                                final double iby = 0;
    9926                                while (it.hasNext()) {
    9927                                        final double iax = it.aDouble;
    9928                                        final double ibx = it.bDouble;
    9929                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    9930                                        float ox;
    9931                                        float oy;
    9932                                        float q;
    9933                                        float den;
    9934                                        if (iby == 0) {
    9935                                                ox = (float) (iax / ibx);
    9936                                                oy = (float) (iay / ibx);
    9937                                        } else if (ibx == 0) {
    9938                                                ox = (float) (iay / iby);
    9939                                                oy = (float) (-iax / iby);
    9940                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    9941                                                q = (float) (ibx / iby);
    9942                                                den = (float) (ibx * q + iby);
    9943                                                ox = (float) ((iax * q + iay) / den);
    9944                                                oy = (float) ((iay * q - ibx) / den);
    9945                                        } else {
    9946                                                q = (float) (iby / ibx);
    9947                                                den = (float) (iby * q + ibx);
    9948                                                ox = (float) ((iay * q + iax) / den);
    9949                                                oy = (float) ((iay - iax * q) / den);
    9950                                        }
    9951                                        oc64data[it.oIndex] = ox;
    9952                                        oc64data[it.oIndex + 1] = oy;
    9953                                }
    9954                        } else {
    9955                                while (it.hasNext()) {
    9956                                        final double iax = it.aDouble;
    9957                                        final double ibx = it.bDouble;
    9958                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    9959                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    9960                                        float ox;
    9961                                        float oy;
    9962                                        float q;
    9963                                        float den;
    9964                                        if (iby == 0) {
    9965                                                ox = (float) (iax / ibx);
    9966                                                oy = (float) (iay / ibx);
    9967                                        } else if (ibx == 0) {
    9968                                                ox = (float) (iay / iby);
    9969                                                oy = (float) (-iax / iby);
    9970                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    9971                                                q = (float) (ibx / iby);
    9972                                                den = (float) (ibx * q + iby);
    9973                                                ox = (float) ((iax * q + iay) / den);
    9974                                                oy = (float) ((iay * q - ibx) / den);
    9975                                        } else {
    9976                                                q = (float) (iby / ibx);
    9977                                                den = (float) (iby * q + ibx);
    9978                                                ox = (float) ((iay * q + iax) / den);
    9979                                                oy = (float) ((iay - iax * q) / den);
    9980                                        }
    9981                                        oc64data[it.oIndex] = ox;
    9982                                        oc64data[it.oIndex + 1] = oy;
    9983                                }
    9984                        }
    9985                        break;
    9986                case Dataset.COMPLEX128:
    9987                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    9988                        if (as == 1) {
    9989                                final double iay = 0;
    9990                                while (it.hasNext()) {
    9991                                        final double iax = it.aDouble;
    9992                                        final double ibx = it.bDouble;
    9993                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    9994                                        double ox;
    9995                                        double oy;
    9996                                        double q;
    9997                                        double den;
    9998                                        if (iby == 0) {
    9999                                                ox = (iax / ibx);
    10000                                                oy = (iay / ibx);
    10001                                        } else if (ibx == 0) {
    10002                                                ox = (iay / iby);
    10003                                                oy = (-iax / iby);
    10004                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    10005                                                q = (ibx / iby);
    10006                                                den = (ibx * q + iby);
    10007                                                ox = ((iax * q + iay) / den);
    10008                                                oy = ((iay * q - ibx) / den);
    10009                                        } else {
    10010                                                q = (iby / ibx);
    10011                                                den = (iby * q + ibx);
    10012                                                ox = ((iay * q + iax) / den);
    10013                                                oy = ((iay - iax * q) / den);
    10014                                        }
    10015                                        oc128data[it.oIndex] = ox;
    10016                                        oc128data[it.oIndex + 1] = oy;
    10017                                }
    10018                        } else if (bs == 1) {
    10019                                final double iby = 0;
    10020                                while (it.hasNext()) {
    10021                                        final double iax = it.aDouble;
    10022                                        final double ibx = it.bDouble;
    10023                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    10024                                        double ox;
    10025                                        double oy;
    10026                                        double q;
    10027                                        double den;
    10028                                        if (iby == 0) {
    10029                                                ox = (iax / ibx);
    10030                                                oy = (iay / ibx);
    10031                                        } else if (ibx == 0) {
    10032                                                ox = (iay / iby);
    10033                                                oy = (-iax / iby);
    10034                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    10035                                                q = (ibx / iby);
    10036                                                den = (ibx * q + iby);
    10037                                                ox = ((iax * q + iay) / den);
    10038                                                oy = ((iay * q - ibx) / den);
    10039                                        } else {
    10040                                                q = (iby / ibx);
    10041                                                den = (iby * q + ibx);
    10042                                                ox = ((iay * q + iax) / den);
    10043                                                oy = ((iay - iax * q) / den);
    10044                                        }
    10045                                        oc128data[it.oIndex] = ox;
    10046                                        oc128data[it.oIndex + 1] = oy;
    10047                                }
    10048                        } else {
    10049                                while (it.hasNext()) {
    10050                                        final double iax = it.aDouble;
    10051                                        final double ibx = it.bDouble;
    10052                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    10053                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    10054                                        double ox;
    10055                                        double oy;
    10056                                        double q;
    10057                                        double den;
    10058                                        if (iby == 0) {
    10059                                                ox = (iax / ibx);
    10060                                                oy = (iay / ibx);
    10061                                        } else if (ibx == 0) {
    10062                                                ox = (iay / iby);
    10063                                                oy = (-iax / iby);
    10064                                        } else if (Math.abs(ibx) < Math.abs(iby)) {
    10065                                                q = (ibx / iby);
    10066                                                den = (ibx * q + iby);
    10067                                                ox = ((iax * q + iay) / den);
    10068                                                oy = ((iay * q - ibx) / den);
    10069                                        } else {
    10070                                                q = (iby / ibx);
    10071                                                den = (iby * q + ibx);
    10072                                                ox = ((iay * q + iax) / den);
    10073                                                oy = ((iay - iax * q) / den);
    10074                                        }
    10075                                        oc128data[it.oIndex] = ox;
    10076                                        oc128data[it.oIndex + 1] = oy;
    10077                                }
    10078                        }
    10079                        break;
    10080                default:
    10081                        throw new IllegalArgumentException("divideTowardsFloor supports integer, compound integer, real, compound real, complex datasets only");
    10082                }
    10083
    10084                addBinaryOperatorName(da, db, result, "/");
    10085                return result;
    10086        }
    10087
    10088        /**
    10089         * power operator
    10090         * @param a
    10091         * @param b
    10092         * @return {@code a ** b}, raise a to power of b
    10093         */
    10094        public static Dataset power(final Object a, final Object b) {
    10095                return power(a, b, null);
    10096        }
    10097
    10098        /**
    10099         * power operator
    10100         * @param a
    10101         * @param b
    10102         * @param o output can be null - in which case, a new dataset is created
    10103         * @return {@code a ** b}, raise a to power of b
    10104         */
    10105        public static Dataset power(final Object a, final Object b, final Dataset o) {
    10106                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    10107                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    10108                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    10109                final Dataset result = it.getOutput();
    10110                final int is = result.getElementsPerItem();
    10111                final int as = da.getElementsPerItem();
    10112                final int bs = db.getElementsPerItem();
    10113                final int dt = result.getDType();
    10114
    10115                switch(dt) {
    10116                case Dataset.INT8:
    10117                        final byte[] oi8data = ((ByteDataset) result).getData();
    10118                        if (it.isOutputDouble()) {
    10119                                while (it.hasNext()) {
    10120                                        final double iax = it.aDouble;
    10121                                        final double ibx = it.bDouble;
    10122                                        byte ox;
    10123                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10124                                        oi8data[it.oIndex] = ox;
    10125                                }
    10126                        } else {
    10127                                while (it.hasNext()) {
    10128                                        final long iax = it.aLong;
    10129                                        final long ibx = it.bLong;
    10130                                        byte ox;
    10131                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10132                                        oi8data[it.oIndex] = ox;
    10133                                }
    10134                        }
    10135                        break;
    10136                case Dataset.INT16:
    10137                        final short[] oi16data = ((ShortDataset) result).getData();
    10138                        if (it.isOutputDouble()) {
    10139                                while (it.hasNext()) {
    10140                                        final double iax = it.aDouble;
    10141                                        final double ibx = it.bDouble;
    10142                                        short ox;
    10143                                        ox = (short) toLong(Math.pow(iax, ibx));
    10144                                        oi16data[it.oIndex] = ox;
    10145                                }
    10146                        } else {
    10147                                while (it.hasNext()) {
    10148                                        final long iax = it.aLong;
    10149                                        final long ibx = it.bLong;
    10150                                        short ox;
    10151                                        ox = (short) toLong(Math.pow(iax, ibx));
    10152                                        oi16data[it.oIndex] = ox;
    10153                                }
    10154                        }
    10155                        break;
    10156                case Dataset.INT64:
    10157                        final long[] oi64data = ((LongDataset) result).getData();
    10158                        if (it.isOutputDouble()) {
    10159                                while (it.hasNext()) {
    10160                                        final double iax = it.aDouble;
    10161                                        final double ibx = it.bDouble;
    10162                                        long ox;
    10163                                        ox = toLong(Math.pow(iax, ibx));
    10164                                        oi64data[it.oIndex] = ox;
    10165                                }
    10166                        } else {
    10167                                while (it.hasNext()) {
    10168                                        final long iax = it.aLong;
    10169                                        final long ibx = it.bLong;
    10170                                        long ox;
    10171                                        ox = toLong(Math.pow(iax, ibx));
    10172                                        oi64data[it.oIndex] = ox;
    10173                                }
    10174                        }
    10175                        break;
    10176                case Dataset.INT32:
    10177                        final int[] oi32data = ((IntegerDataset) result).getData();
    10178                        if (it.isOutputDouble()) {
    10179                                while (it.hasNext()) {
    10180                                        final double iax = it.aDouble;
    10181                                        final double ibx = it.bDouble;
    10182                                        int ox;
    10183                                        ox = (int) toLong(Math.pow(iax, ibx));
    10184                                        oi32data[it.oIndex] = ox;
    10185                                }
    10186                        } else {
    10187                                while (it.hasNext()) {
    10188                                        final long iax = it.aLong;
    10189                                        final long ibx = it.bLong;
    10190                                        int ox;
    10191                                        ox = (int) toLong(Math.pow(iax, ibx));
    10192                                        oi32data[it.oIndex] = ox;
    10193                                }
    10194                        }
    10195                        break;
    10196                case Dataset.ARRAYINT8:
    10197                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    10198                        if (is == 1) {
    10199                                if (it.isOutputDouble()) {
    10200                                        while (it.hasNext()) {
    10201                                                final double iax = it.aDouble;
    10202                                                final double ibx = it.bDouble;
    10203                                                byte ox;
    10204                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10205                                                oai8data[it.oIndex] = ox;
    10206                                        }
    10207                                } else {
    10208                                        while (it.hasNext()) {
    10209                                                final long iax = it.aLong;
    10210                                                final long ibx = it.bLong;
    10211                                                byte ox;
    10212                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10213                                                oai8data[it.oIndex] = ox;
    10214                                        }
    10215                                }
    10216                        } else if (as < bs) {
    10217                                if (it.isOutputDouble()) {
    10218                                        while (it.hasNext()) {
    10219                                                final double iax = it.aDouble;
    10220                                                double ibx = it.bDouble;
    10221                                                byte ox;
    10222                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10223                                                oai8data[it.oIndex] = ox;
    10224                                                for (int j = 1; j < is; j++) {
    10225                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10226                                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10227                                                        oai8data[it.oIndex + j] = ox;
    10228                                                }
    10229                                        }
    10230                                } else {
    10231                                        while (it.hasNext()) {
    10232                                                final long iax = it.aLong;
    10233                                                long ibx = it.bLong;
    10234                                                byte ox;
    10235                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10236                                                oai8data[it.oIndex] = ox;
    10237                                                for (int j = 1; j < is; j++) {
    10238                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10239                                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10240                                                        oai8data[it.oIndex + j] = ox;
    10241                                                }
    10242                                        }
    10243                                }
    10244                        } else if (as > bs) {
    10245                                if (it.isOutputDouble()) {
    10246                                        while (it.hasNext()) {
    10247                                                double iax = it.aDouble;
    10248                                                final double ibx = it.bDouble;
    10249                                                byte ox;
    10250                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10251                                                oai8data[it.oIndex] = ox;
    10252                                                for (int j = 1; j < is; j++) {
    10253                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10254                                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10255                                                        oai8data[it.oIndex + j] = ox;
    10256                                                }
    10257                                        }
    10258                                } else {
    10259                                        while (it.hasNext()) {
    10260                                                long iax = it.aLong;
    10261                                                final long ibx = it.bLong;
    10262                                                byte ox;
    10263                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10264                                                oai8data[it.oIndex] = ox;
    10265                                                for (int j = 1; j < is; j++) {
    10266                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10267                                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10268                                                        oai8data[it.oIndex + j] = ox;
    10269                                                }
    10270                                        }
    10271                                }
    10272                        } else if (as == 1) {
    10273                                if (it.isOutputDouble()) {
    10274                                        while (it.hasNext()) {
    10275                                                final double iax = it.aDouble;
    10276                                                final double ibx = it.bDouble;
    10277                                                byte ox;
    10278                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10279                                                for (int j = 0; j < is; j++) {
    10280                                                        oai8data[it.oIndex + j] = ox;
    10281                                                }
    10282                                        }
    10283                                } else {
    10284                                        while (it.hasNext()) {
    10285                                                final long iax = it.aLong;
    10286                                                final long ibx = it.bLong;
    10287                                                byte ox;
    10288                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10289                                                for (int j = 0; j < is; j++) {
    10290                                                        oai8data[it.oIndex + j] = ox;
    10291                                                }
    10292                                        }
    10293                                }
    10294                        } else {
    10295                                if (it.isOutputDouble()) {
    10296                                        while (it.hasNext()) {
    10297                                                double iax = it.aDouble;
    10298                                                double ibx = it.bDouble;
    10299                                                byte ox;
    10300                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10301                                                oai8data[it.oIndex] = ox;
    10302                                                for (int j = 1; j < is; j++) {
    10303                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10304                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10305                                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10306                                                        oai8data[it.oIndex + j] = ox;
    10307                                                }
    10308                                        }
    10309                                } else {
    10310                                        while (it.hasNext()) {
    10311                                                long iax = it.aLong;
    10312                                                long ibx = it.bLong;
    10313                                                byte ox;
    10314                                                ox = (byte) toLong(Math.pow(iax, ibx));
    10315                                                oai8data[it.oIndex] = ox;
    10316                                                for (int j = 1; j < is; j++) {
    10317                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10318                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10319                                                        ox = (byte) toLong(Math.pow(iax, ibx));
    10320                                                        oai8data[it.oIndex + j] = ox;
    10321                                                }
    10322                                        }
    10323                                }
    10324                        }
    10325                        break;
    10326                case Dataset.ARRAYINT16:
    10327                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    10328                        if (is == 1) {
    10329                                if (it.isOutputDouble()) {
    10330                                        while (it.hasNext()) {
    10331                                                final double iax = it.aDouble;
    10332                                                final double ibx = it.bDouble;
    10333                                                short ox;
    10334                                                ox = (short) toLong(Math.pow(iax, ibx));
    10335                                                oai16data[it.oIndex] = ox;
    10336                                        }
    10337                                } else {
    10338                                        while (it.hasNext()) {
    10339                                                final long iax = it.aLong;
    10340                                                final long ibx = it.bLong;
    10341                                                short ox;
    10342                                                ox = (short) toLong(Math.pow(iax, ibx));
    10343                                                oai16data[it.oIndex] = ox;
    10344                                        }
    10345                                }
    10346                        } else if (as < bs) {
    10347                                if (it.isOutputDouble()) {
    10348                                        while (it.hasNext()) {
    10349                                                final double iax = it.aDouble;
    10350                                                double ibx = it.bDouble;
    10351                                                short ox;
    10352                                                ox = (short) toLong(Math.pow(iax, ibx));
    10353                                                oai16data[it.oIndex] = ox;
    10354                                                for (int j = 1; j < is; j++) {
    10355                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10356                                                        ox = (short) toLong(Math.pow(iax, ibx));
    10357                                                        oai16data[it.oIndex + j] = ox;
    10358                                                }
    10359                                        }
    10360                                } else {
    10361                                        while (it.hasNext()) {
    10362                                                final long iax = it.aLong;
    10363                                                long ibx = it.bLong;
    10364                                                short ox;
    10365                                                ox = (short) toLong(Math.pow(iax, ibx));
    10366                                                oai16data[it.oIndex] = ox;
    10367                                                for (int j = 1; j < is; j++) {
    10368                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10369                                                        ox = (short) toLong(Math.pow(iax, ibx));
    10370                                                        oai16data[it.oIndex + j] = ox;
    10371                                                }
    10372                                        }
    10373                                }
    10374                        } else if (as > bs) {
    10375                                if (it.isOutputDouble()) {
    10376                                        while (it.hasNext()) {
    10377                                                double iax = it.aDouble;
    10378                                                final double ibx = it.bDouble;
    10379                                                short ox;
    10380                                                ox = (short) toLong(Math.pow(iax, ibx));
    10381                                                oai16data[it.oIndex] = ox;
    10382                                                for (int j = 1; j < is; j++) {
    10383                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10384                                                        ox = (short) toLong(Math.pow(iax, ibx));
    10385                                                        oai16data[it.oIndex + j] = ox;
    10386                                                }
    10387                                        }
    10388                                } else {
    10389                                        while (it.hasNext()) {
    10390                                                long iax = it.aLong;
    10391                                                final long ibx = it.bLong;
    10392                                                short ox;
    10393                                                ox = (short) toLong(Math.pow(iax, ibx));
    10394                                                oai16data[it.oIndex] = ox;
    10395                                                for (int j = 1; j < is; j++) {
    10396                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10397                                                        ox = (short) toLong(Math.pow(iax, ibx));
    10398                                                        oai16data[it.oIndex + j] = ox;
    10399                                                }
    10400                                        }
    10401                                }
    10402                        } else if (as == 1) {
    10403                                if (it.isOutputDouble()) {
    10404                                        while (it.hasNext()) {
    10405                                                final double iax = it.aDouble;
    10406                                                final double ibx = it.bDouble;
    10407                                                short ox;
    10408                                                ox = (short) toLong(Math.pow(iax, ibx));
    10409                                                for (int j = 0; j < is; j++) {
    10410                                                        oai16data[it.oIndex + j] = ox;
    10411                                                }
    10412                                        }
    10413                                } else {
    10414                                        while (it.hasNext()) {
    10415                                                final long iax = it.aLong;
    10416                                                final long ibx = it.bLong;
    10417                                                short ox;
    10418                                                ox = (short) toLong(Math.pow(iax, ibx));
    10419                                                for (int j = 0; j < is; j++) {
    10420                                                        oai16data[it.oIndex + j] = ox;
    10421                                                }
    10422                                        }
    10423                                }
    10424                        } else {
    10425                                if (it.isOutputDouble()) {
    10426                                        while (it.hasNext()) {
    10427                                                double iax = it.aDouble;
    10428                                                double ibx = it.bDouble;
    10429                                                short ox;
    10430                                                ox = (short) toLong(Math.pow(iax, ibx));
    10431                                                oai16data[it.oIndex] = ox;
    10432                                                for (int j = 1; j < is; j++) {
    10433                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10434                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10435                                                        ox = (short) toLong(Math.pow(iax, ibx));
    10436                                                        oai16data[it.oIndex + j] = ox;
    10437                                                }
    10438                                        }
    10439                                } else {
    10440                                        while (it.hasNext()) {
    10441                                                long iax = it.aLong;
    10442                                                long ibx = it.bLong;
    10443                                                short ox;
    10444                                                ox = (short) toLong(Math.pow(iax, ibx));
    10445                                                oai16data[it.oIndex] = ox;
    10446                                                for (int j = 1; j < is; j++) {
    10447                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10448                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10449                                                        ox = (short) toLong(Math.pow(iax, ibx));
    10450                                                        oai16data[it.oIndex + j] = ox;
    10451                                                }
    10452                                        }
    10453                                }
    10454                        }
    10455                        break;
    10456                case Dataset.ARRAYINT64:
    10457                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    10458                        if (is == 1) {
    10459                                if (it.isOutputDouble()) {
    10460                                        while (it.hasNext()) {
    10461                                                final double iax = it.aDouble;
    10462                                                final double ibx = it.bDouble;
    10463                                                long ox;
    10464                                                ox = toLong(Math.pow(iax, ibx));
    10465                                                oai64data[it.oIndex] = ox;
    10466                                        }
    10467                                } else {
    10468                                        while (it.hasNext()) {
    10469                                                final long iax = it.aLong;
    10470                                                final long ibx = it.bLong;
    10471                                                long ox;
    10472                                                ox = toLong(Math.pow(iax, ibx));
    10473                                                oai64data[it.oIndex] = ox;
    10474                                        }
    10475                                }
    10476                        } else if (as < bs) {
    10477                                if (it.isOutputDouble()) {
    10478                                        while (it.hasNext()) {
    10479                                                final double iax = it.aDouble;
    10480                                                double ibx = it.bDouble;
    10481                                                long ox;
    10482                                                ox = toLong(Math.pow(iax, ibx));
    10483                                                oai64data[it.oIndex] = ox;
    10484                                                for (int j = 1; j < is; j++) {
    10485                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10486                                                        ox = toLong(Math.pow(iax, ibx));
    10487                                                        oai64data[it.oIndex + j] = ox;
    10488                                                }
    10489                                        }
    10490                                } else {
    10491                                        while (it.hasNext()) {
    10492                                                final long iax = it.aLong;
    10493                                                long ibx = it.bLong;
    10494                                                long ox;
    10495                                                ox = toLong(Math.pow(iax, ibx));
    10496                                                oai64data[it.oIndex] = ox;
    10497                                                for (int j = 1; j < is; j++) {
    10498                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10499                                                        ox = toLong(Math.pow(iax, ibx));
    10500                                                        oai64data[it.oIndex + j] = ox;
    10501                                                }
    10502                                        }
    10503                                }
    10504                        } else if (as > bs) {
    10505                                if (it.isOutputDouble()) {
    10506                                        while (it.hasNext()) {
    10507                                                double iax = it.aDouble;
    10508                                                final double ibx = it.bDouble;
    10509                                                long ox;
    10510                                                ox = toLong(Math.pow(iax, ibx));
    10511                                                oai64data[it.oIndex] = ox;
    10512                                                for (int j = 1; j < is; j++) {
    10513                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10514                                                        ox = toLong(Math.pow(iax, ibx));
    10515                                                        oai64data[it.oIndex + j] = ox;
    10516                                                }
    10517                                        }
    10518                                } else {
    10519                                        while (it.hasNext()) {
    10520                                                long iax = it.aLong;
    10521                                                final long ibx = it.bLong;
    10522                                                long ox;
    10523                                                ox = toLong(Math.pow(iax, ibx));
    10524                                                oai64data[it.oIndex] = ox;
    10525                                                for (int j = 1; j < is; j++) {
    10526                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10527                                                        ox = toLong(Math.pow(iax, ibx));
    10528                                                        oai64data[it.oIndex + j] = ox;
    10529                                                }
    10530                                        }
    10531                                }
    10532                        } else if (as == 1) {
    10533                                if (it.isOutputDouble()) {
    10534                                        while (it.hasNext()) {
    10535                                                final double iax = it.aDouble;
    10536                                                final double ibx = it.bDouble;
    10537                                                long ox;
    10538                                                ox = toLong(Math.pow(iax, ibx));
    10539                                                for (int j = 0; j < is; j++) {
    10540                                                        oai64data[it.oIndex + j] = ox;
    10541                                                }
    10542                                        }
    10543                                } else {
    10544                                        while (it.hasNext()) {
    10545                                                final long iax = it.aLong;
    10546                                                final long ibx = it.bLong;
    10547                                                long ox;
    10548                                                ox = toLong(Math.pow(iax, ibx));
    10549                                                for (int j = 0; j < is; j++) {
    10550                                                        oai64data[it.oIndex + j] = ox;
    10551                                                }
    10552                                        }
    10553                                }
    10554                        } else {
    10555                                if (it.isOutputDouble()) {
    10556                                        while (it.hasNext()) {
    10557                                                double iax = it.aDouble;
    10558                                                double ibx = it.bDouble;
    10559                                                long ox;
    10560                                                ox = toLong(Math.pow(iax, ibx));
    10561                                                oai64data[it.oIndex] = ox;
    10562                                                for (int j = 1; j < is; j++) {
    10563                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10564                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10565                                                        ox = toLong(Math.pow(iax, ibx));
    10566                                                        oai64data[it.oIndex + j] = ox;
    10567                                                }
    10568                                        }
    10569                                } else {
    10570                                        while (it.hasNext()) {
    10571                                                long iax = it.aLong;
    10572                                                long ibx = it.bLong;
    10573                                                long ox;
    10574                                                ox = toLong(Math.pow(iax, ibx));
    10575                                                oai64data[it.oIndex] = ox;
    10576                                                for (int j = 1; j < is; j++) {
    10577                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10578                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10579                                                        ox = toLong(Math.pow(iax, ibx));
    10580                                                        oai64data[it.oIndex + j] = ox;
    10581                                                }
    10582                                        }
    10583                                }
    10584                        }
    10585                        break;
    10586                case Dataset.ARRAYINT32:
    10587                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    10588                        if (is == 1) {
    10589                                if (it.isOutputDouble()) {
    10590                                        while (it.hasNext()) {
    10591                                                final double iax = it.aDouble;
    10592                                                final double ibx = it.bDouble;
    10593                                                int ox;
    10594                                                ox = (int) toLong(Math.pow(iax, ibx));
    10595                                                oai32data[it.oIndex] = ox;
    10596                                        }
    10597                                } else {
    10598                                        while (it.hasNext()) {
    10599                                                final long iax = it.aLong;
    10600                                                final long ibx = it.bLong;
    10601                                                int ox;
    10602                                                ox = (int) toLong(Math.pow(iax, ibx));
    10603                                                oai32data[it.oIndex] = ox;
    10604                                        }
    10605                                }
    10606                        } else if (as < bs) {
    10607                                if (it.isOutputDouble()) {
    10608                                        while (it.hasNext()) {
    10609                                                final double iax = it.aDouble;
    10610                                                double ibx = it.bDouble;
    10611                                                int ox;
    10612                                                ox = (int) toLong(Math.pow(iax, ibx));
    10613                                                oai32data[it.oIndex] = ox;
    10614                                                for (int j = 1; j < is; j++) {
    10615                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10616                                                        ox = (int) toLong(Math.pow(iax, ibx));
    10617                                                        oai32data[it.oIndex + j] = ox;
    10618                                                }
    10619                                        }
    10620                                } else {
    10621                                        while (it.hasNext()) {
    10622                                                final long iax = it.aLong;
    10623                                                long ibx = it.bLong;
    10624                                                int ox;
    10625                                                ox = (int) toLong(Math.pow(iax, ibx));
    10626                                                oai32data[it.oIndex] = ox;
    10627                                                for (int j = 1; j < is; j++) {
    10628                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10629                                                        ox = (int) toLong(Math.pow(iax, ibx));
    10630                                                        oai32data[it.oIndex + j] = ox;
    10631                                                }
    10632                                        }
    10633                                }
    10634                        } else if (as > bs) {
    10635                                if (it.isOutputDouble()) {
    10636                                        while (it.hasNext()) {
    10637                                                double iax = it.aDouble;
    10638                                                final double ibx = it.bDouble;
    10639                                                int ox;
    10640                                                ox = (int) toLong(Math.pow(iax, ibx));
    10641                                                oai32data[it.oIndex] = ox;
    10642                                                for (int j = 1; j < is; j++) {
    10643                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10644                                                        ox = (int) toLong(Math.pow(iax, ibx));
    10645                                                        oai32data[it.oIndex + j] = ox;
    10646                                                }
    10647                                        }
    10648                                } else {
    10649                                        while (it.hasNext()) {
    10650                                                long iax = it.aLong;
    10651                                                final long ibx = it.bLong;
    10652                                                int ox;
    10653                                                ox = (int) toLong(Math.pow(iax, ibx));
    10654                                                oai32data[it.oIndex] = ox;
    10655                                                for (int j = 1; j < is; j++) {
    10656                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10657                                                        ox = (int) toLong(Math.pow(iax, ibx));
    10658                                                        oai32data[it.oIndex + j] = ox;
    10659                                                }
    10660                                        }
    10661                                }
    10662                        } else if (as == 1) {
    10663                                if (it.isOutputDouble()) {
    10664                                        while (it.hasNext()) {
    10665                                                final double iax = it.aDouble;
    10666                                                final double ibx = it.bDouble;
    10667                                                int ox;
    10668                                                ox = (int) toLong(Math.pow(iax, ibx));
    10669                                                for (int j = 0; j < is; j++) {
    10670                                                        oai32data[it.oIndex + j] = ox;
    10671                                                }
    10672                                        }
    10673                                } else {
    10674                                        while (it.hasNext()) {
    10675                                                final long iax = it.aLong;
    10676                                                final long ibx = it.bLong;
    10677                                                int ox;
    10678                                                ox = (int) toLong(Math.pow(iax, ibx));
    10679                                                for (int j = 0; j < is; j++) {
    10680                                                        oai32data[it.oIndex + j] = ox;
    10681                                                }
    10682                                        }
    10683                                }
    10684                        } else {
    10685                                if (it.isOutputDouble()) {
    10686                                        while (it.hasNext()) {
    10687                                                double iax = it.aDouble;
    10688                                                double ibx = it.bDouble;
    10689                                                int ox;
    10690                                                ox = (int) toLong(Math.pow(iax, ibx));
    10691                                                oai32data[it.oIndex] = ox;
    10692                                                for (int j = 1; j < is; j++) {
    10693                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10694                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10695                                                        ox = (int) toLong(Math.pow(iax, ibx));
    10696                                                        oai32data[it.oIndex + j] = ox;
    10697                                                }
    10698                                        }
    10699                                } else {
    10700                                        while (it.hasNext()) {
    10701                                                long iax = it.aLong;
    10702                                                long ibx = it.bLong;
    10703                                                int ox;
    10704                                                ox = (int) toLong(Math.pow(iax, ibx));
    10705                                                oai32data[it.oIndex] = ox;
    10706                                                for (int j = 1; j < is; j++) {
    10707                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10708                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10709                                                        ox = (int) toLong(Math.pow(iax, ibx));
    10710                                                        oai32data[it.oIndex + j] = ox;
    10711                                                }
    10712                                        }
    10713                                }
    10714                        }
    10715                        break;
    10716                case Dataset.FLOAT32:
    10717                        final float[] of32data = ((FloatDataset) result).getData();
    10718                        if (it.isOutputDouble()) {
    10719                                while (it.hasNext()) {
    10720                                        final double iax = it.aDouble;
    10721                                        final double ibx = it.bDouble;
    10722                                        float ox;
    10723                                        ox = (float) (Math.pow(iax, ibx));
    10724                                        of32data[it.oIndex] = ox;
    10725                                }
    10726                        } else {
    10727                                while (it.hasNext()) {
    10728                                        final long iax = it.aLong;
    10729                                        final long ibx = it.bLong;
    10730                                        float ox;
    10731                                        ox = (float) (Math.pow(iax, ibx));
    10732                                        of32data[it.oIndex] = ox;
    10733                                }
    10734                        }
    10735                        break;
    10736                case Dataset.FLOAT64:
    10737                        final double[] of64data = ((DoubleDataset) result).getData();
    10738                        if (it.isOutputDouble()) {
    10739                                while (it.hasNext()) {
    10740                                        final double iax = it.aDouble;
    10741                                        final double ibx = it.bDouble;
    10742                                        double ox;
    10743                                        ox = (Math.pow(iax, ibx));
    10744                                        of64data[it.oIndex] = ox;
    10745                                }
    10746                        } else {
    10747                                while (it.hasNext()) {
    10748                                        final long iax = it.aLong;
    10749                                        final long ibx = it.bLong;
    10750                                        double ox;
    10751                                        ox = (Math.pow(iax, ibx));
    10752                                        of64data[it.oIndex] = ox;
    10753                                }
    10754                        }
    10755                        break;
    10756                case Dataset.ARRAYFLOAT32:
    10757                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    10758                        if (is == 1) {
    10759                                if (it.isOutputDouble()) {
    10760                                        while (it.hasNext()) {
    10761                                                final double iax = it.aDouble;
    10762                                                final double ibx = it.bDouble;
    10763                                                float ox;
    10764                                                ox = (float) (Math.pow(iax, ibx));
    10765                                                oaf32data[it.oIndex] = ox;
    10766                                        }
    10767                                } else {
    10768                                        while (it.hasNext()) {
    10769                                                final long iax = it.aLong;
    10770                                                final long ibx = it.bLong;
    10771                                                float ox;
    10772                                                ox = (float) (Math.pow(iax, ibx));
    10773                                                oaf32data[it.oIndex] = ox;
    10774                                        }
    10775                                }
    10776                        } else if (as < bs) {
    10777                                if (it.isOutputDouble()) {
    10778                                        while (it.hasNext()) {
    10779                                                final double iax = it.aDouble;
    10780                                                double ibx = it.bDouble;
    10781                                                float ox;
    10782                                                ox = (float) (Math.pow(iax, ibx));
    10783                                                oaf32data[it.oIndex] = ox;
    10784                                                for (int j = 1; j < is; j++) {
    10785                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10786                                                        ox = (float) (Math.pow(iax, ibx));
    10787                                                        oaf32data[it.oIndex + j] = ox;
    10788                                                }
    10789                                        }
    10790                                } else {
    10791                                        while (it.hasNext()) {
    10792                                                final long iax = it.aLong;
    10793                                                long ibx = it.bLong;
    10794                                                float ox;
    10795                                                ox = (float) (Math.pow(iax, ibx));
    10796                                                oaf32data[it.oIndex] = ox;
    10797                                                for (int j = 1; j < is; j++) {
    10798                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10799                                                        ox = (float) (Math.pow(iax, ibx));
    10800                                                        oaf32data[it.oIndex + j] = ox;
    10801                                                }
    10802                                        }
    10803                                }
    10804                        } else if (as > bs) {
    10805                                if (it.isOutputDouble()) {
    10806                                        while (it.hasNext()) {
    10807                                                double iax = it.aDouble;
    10808                                                final double ibx = it.bDouble;
    10809                                                float ox;
    10810                                                ox = (float) (Math.pow(iax, ibx));
    10811                                                oaf32data[it.oIndex] = ox;
    10812                                                for (int j = 1; j < is; j++) {
    10813                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10814                                                        ox = (float) (Math.pow(iax, ibx));
    10815                                                        oaf32data[it.oIndex + j] = ox;
    10816                                                }
    10817                                        }
    10818                                } else {
    10819                                        while (it.hasNext()) {
    10820                                                long iax = it.aLong;
    10821                                                final long ibx = it.bLong;
    10822                                                float ox;
    10823                                                ox = (float) (Math.pow(iax, ibx));
    10824                                                oaf32data[it.oIndex] = ox;
    10825                                                for (int j = 1; j < is; j++) {
    10826                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10827                                                        ox = (float) (Math.pow(iax, ibx));
    10828                                                        oaf32data[it.oIndex + j] = ox;
    10829                                                }
    10830                                        }
    10831                                }
    10832                        } else if (as == 1) {
    10833                                if (it.isOutputDouble()) {
    10834                                        while (it.hasNext()) {
    10835                                                final double iax = it.aDouble;
    10836                                                final double ibx = it.bDouble;
    10837                                                float ox;
    10838                                                ox = (float) (Math.pow(iax, ibx));
    10839                                                for (int j = 0; j < is; j++) {
    10840                                                        oaf32data[it.oIndex + j] = ox;
    10841                                                }
    10842                                        }
    10843                                } else {
    10844                                        while (it.hasNext()) {
    10845                                                final long iax = it.aLong;
    10846                                                final long ibx = it.bLong;
    10847                                                float ox;
    10848                                                ox = (float) (Math.pow(iax, ibx));
    10849                                                for (int j = 0; j < is; j++) {
    10850                                                        oaf32data[it.oIndex + j] = ox;
    10851                                                }
    10852                                        }
    10853                                }
    10854                        } else {
    10855                                if (it.isOutputDouble()) {
    10856                                        while (it.hasNext()) {
    10857                                                double iax = it.aDouble;
    10858                                                double ibx = it.bDouble;
    10859                                                float ox;
    10860                                                ox = (float) (Math.pow(iax, ibx));
    10861                                                oaf32data[it.oIndex] = ox;
    10862                                                for (int j = 1; j < is; j++) {
    10863                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10864                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10865                                                        ox = (float) (Math.pow(iax, ibx));
    10866                                                        oaf32data[it.oIndex + j] = ox;
    10867                                                }
    10868                                        }
    10869                                } else {
    10870                                        while (it.hasNext()) {
    10871                                                long iax = it.aLong;
    10872                                                long ibx = it.bLong;
    10873                                                float ox;
    10874                                                ox = (float) (Math.pow(iax, ibx));
    10875                                                oaf32data[it.oIndex] = ox;
    10876                                                for (int j = 1; j < is; j++) {
    10877                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10878                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10879                                                        ox = (float) (Math.pow(iax, ibx));
    10880                                                        oaf32data[it.oIndex + j] = ox;
    10881                                                }
    10882                                        }
    10883                                }
    10884                        }
    10885                        break;
    10886                case Dataset.ARRAYFLOAT64:
    10887                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    10888                        if (is == 1) {
    10889                                if (it.isOutputDouble()) {
    10890                                        while (it.hasNext()) {
    10891                                                final double iax = it.aDouble;
    10892                                                final double ibx = it.bDouble;
    10893                                                double ox;
    10894                                                ox = (Math.pow(iax, ibx));
    10895                                                oaf64data[it.oIndex] = ox;
    10896                                        }
    10897                                } else {
    10898                                        while (it.hasNext()) {
    10899                                                final long iax = it.aLong;
    10900                                                final long ibx = it.bLong;
    10901                                                double ox;
    10902                                                ox = (Math.pow(iax, ibx));
    10903                                                oaf64data[it.oIndex] = ox;
    10904                                        }
    10905                                }
    10906                        } else if (as < bs) {
    10907                                if (it.isOutputDouble()) {
    10908                                        while (it.hasNext()) {
    10909                                                final double iax = it.aDouble;
    10910                                                double ibx = it.bDouble;
    10911                                                double ox;
    10912                                                ox = (Math.pow(iax, ibx));
    10913                                                oaf64data[it.oIndex] = ox;
    10914                                                for (int j = 1; j < is; j++) {
    10915                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10916                                                        ox = (Math.pow(iax, ibx));
    10917                                                        oaf64data[it.oIndex + j] = ox;
    10918                                                }
    10919                                        }
    10920                                } else {
    10921                                        while (it.hasNext()) {
    10922                                                final long iax = it.aLong;
    10923                                                long ibx = it.bLong;
    10924                                                double ox;
    10925                                                ox = (Math.pow(iax, ibx));
    10926                                                oaf64data[it.oIndex] = ox;
    10927                                                for (int j = 1; j < is; j++) {
    10928                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    10929                                                        ox = (Math.pow(iax, ibx));
    10930                                                        oaf64data[it.oIndex + j] = ox;
    10931                                                }
    10932                                        }
    10933                                }
    10934                        } else if (as > bs) {
    10935                                if (it.isOutputDouble()) {
    10936                                        while (it.hasNext()) {
    10937                                                double iax = it.aDouble;
    10938                                                final double ibx = it.bDouble;
    10939                                                double ox;
    10940                                                ox = (Math.pow(iax, ibx));
    10941                                                oaf64data[it.oIndex] = ox;
    10942                                                for (int j = 1; j < is; j++) {
    10943                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10944                                                        ox = (Math.pow(iax, ibx));
    10945                                                        oaf64data[it.oIndex + j] = ox;
    10946                                                }
    10947                                        }
    10948                                } else {
    10949                                        while (it.hasNext()) {
    10950                                                long iax = it.aLong;
    10951                                                final long ibx = it.bLong;
    10952                                                double ox;
    10953                                                ox = (Math.pow(iax, ibx));
    10954                                                oaf64data[it.oIndex] = ox;
    10955                                                for (int j = 1; j < is; j++) {
    10956                                                        iax = da.getElementLongAbs(it.aIndex + j);
    10957                                                        ox = (Math.pow(iax, ibx));
    10958                                                        oaf64data[it.oIndex + j] = ox;
    10959                                                }
    10960                                        }
    10961                                }
    10962                        } else if (as == 1) {
    10963                                if (it.isOutputDouble()) {
    10964                                        while (it.hasNext()) {
    10965                                                final double iax = it.aDouble;
    10966                                                final double ibx = it.bDouble;
    10967                                                double ox;
    10968                                                ox = (Math.pow(iax, ibx));
    10969                                                for (int j = 0; j < is; j++) {
    10970                                                        oaf64data[it.oIndex + j] = ox;
    10971                                                }
    10972                                        }
    10973                                } else {
    10974                                        while (it.hasNext()) {
    10975                                                final long iax = it.aLong;
    10976                                                final long ibx = it.bLong;
    10977                                                double ox;
    10978                                                ox = (Math.pow(iax, ibx));
    10979                                                for (int j = 0; j < is; j++) {
    10980                                                        oaf64data[it.oIndex + j] = ox;
    10981                                                }
    10982                                        }
    10983                                }
    10984                        } else {
    10985                                if (it.isOutputDouble()) {
    10986                                        while (it.hasNext()) {
    10987                                                double iax = it.aDouble;
    10988                                                double ibx = it.bDouble;
    10989                                                double ox;
    10990                                                ox = (Math.pow(iax, ibx));
    10991                                                oaf64data[it.oIndex] = ox;
    10992                                                for (int j = 1; j < is; j++) {
    10993                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    10994                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    10995                                                        ox = (Math.pow(iax, ibx));
    10996                                                        oaf64data[it.oIndex + j] = ox;
    10997                                                }
    10998                                        }
    10999                                } else {
    11000                                        while (it.hasNext()) {
    11001                                                long iax = it.aLong;
    11002                                                long ibx = it.bLong;
    11003                                                double ox;
    11004                                                ox = (Math.pow(iax, ibx));
    11005                                                oaf64data[it.oIndex] = ox;
    11006                                                for (int j = 1; j < is; j++) {
    11007                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11008                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11009                                                        ox = (Math.pow(iax, ibx));
    11010                                                        oaf64data[it.oIndex + j] = ox;
    11011                                                }
    11012                                        }
    11013                                }
    11014                        }
    11015                        break;
    11016                case Dataset.COMPLEX64:
    11017                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    11018                        if (as == 1) {
    11019                                final double iay = 0;
    11020                                while (it.hasNext()) {
    11021                                        final double iax = it.aDouble;
    11022                                        final double ibx = it.bDouble;
    11023                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    11024                                        Complex tz;
    11025                                        float ox;
    11026                                        float oy;
    11027                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
    11028                                        ox = (float) (tz.getReal());
    11029                                        oy = (float) (tz.getImaginary());
    11030                                        oc64data[it.oIndex] = ox;
    11031                                        oc64data[it.oIndex + 1] = oy;
    11032                                }
    11033                        } else if (bs == 1) {
    11034                                final double iby = 0;
    11035                                while (it.hasNext()) {
    11036                                        final double iax = it.aDouble;
    11037                                        final double ibx = it.bDouble;
    11038                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    11039                                        Complex tz;
    11040                                        float ox;
    11041                                        float oy;
    11042                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
    11043                                        ox = (float) (tz.getReal());
    11044                                        oy = (float) (tz.getImaginary());
    11045                                        oc64data[it.oIndex] = ox;
    11046                                        oc64data[it.oIndex + 1] = oy;
    11047                                }
    11048                        } else {
    11049                                while (it.hasNext()) {
    11050                                        final double iax = it.aDouble;
    11051                                        final double ibx = it.bDouble;
    11052                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    11053                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    11054                                        Complex tz;
    11055                                        float ox;
    11056                                        float oy;
    11057                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
    11058                                        ox = (float) (tz.getReal());
    11059                                        oy = (float) (tz.getImaginary());
    11060                                        oc64data[it.oIndex] = ox;
    11061                                        oc64data[it.oIndex + 1] = oy;
    11062                                }
    11063                        }
    11064                        break;
    11065                case Dataset.COMPLEX128:
    11066                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    11067                        if (as == 1) {
    11068                                final double iay = 0;
    11069                                while (it.hasNext()) {
    11070                                        final double iax = it.aDouble;
    11071                                        final double ibx = it.bDouble;
    11072                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    11073                                        Complex tz;
    11074                                        double ox;
    11075                                        double oy;
    11076                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
    11077                                        ox = (tz.getReal());
    11078                                        oy = (tz.getImaginary());
    11079                                        oc128data[it.oIndex] = ox;
    11080                                        oc128data[it.oIndex + 1] = oy;
    11081                                }
    11082                        } else if (bs == 1) {
    11083                                final double iby = 0;
    11084                                while (it.hasNext()) {
    11085                                        final double iax = it.aDouble;
    11086                                        final double ibx = it.bDouble;
    11087                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    11088                                        Complex tz;
    11089                                        double ox;
    11090                                        double oy;
    11091                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
    11092                                        ox = (tz.getReal());
    11093                                        oy = (tz.getImaginary());
    11094                                        oc128data[it.oIndex] = ox;
    11095                                        oc128data[it.oIndex + 1] = oy;
    11096                                }
    11097                        } else {
    11098                                while (it.hasNext()) {
    11099                                        final double iax = it.aDouble;
    11100                                        final double ibx = it.bDouble;
    11101                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    11102                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    11103                                        Complex tz;
    11104                                        double ox;
    11105                                        double oy;
    11106                                        tz = new Complex(iax, iay).pow(new Complex(ibx, iby));
    11107                                        ox = (tz.getReal());
    11108                                        oy = (tz.getImaginary());
    11109                                        oc128data[it.oIndex] = ox;
    11110                                        oc128data[it.oIndex + 1] = oy;
    11111                                }
    11112                        }
    11113                        break;
    11114                default:
    11115                        throw new IllegalArgumentException("power supports integer, compound integer, real, compound real, complex datasets only");
    11116                }
    11117
    11118                addBinaryOperatorName(da, db, result, "**");
    11119                return result;
    11120        }
    11121
    11122        /**
    11123         * remainder operator
    11124         * @param a
    11125         * @param b
    11126         * @return {@code a % b}, remainder of division of a by b
    11127         */
    11128        public static Dataset remainder(final Object a, final Object b) {
    11129                return remainder(a, b, null);
    11130        }
    11131
    11132        /**
    11133         * remainder operator
    11134         * @param a
    11135         * @param b
    11136         * @param o output can be null - in which case, a new dataset is created
    11137         * @return {@code a % b}, remainder of division of a by b
    11138         */
    11139        public static Dataset remainder(final Object a, final Object b, final Dataset o) {
    11140                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    11141                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    11142                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    11143                final Dataset result = it.getOutput();
    11144                final int is = result.getElementsPerItem();
    11145                final int as = da.getElementsPerItem();
    11146                final int bs = db.getElementsPerItem();
    11147                final int dt = result.getDType();
    11148
    11149                switch(dt) {
    11150                case Dataset.INT8:
    11151                        final byte[] oi8data = ((ByteDataset) result).getData();
    11152                        if (it.isOutputDouble()) {
    11153                                while (it.hasNext()) {
    11154                                        final double iax = it.aDouble;
    11155                                        final double ibx = it.bDouble;
    11156                                        byte ox;
    11157                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11158                                        oi8data[it.oIndex] = ox;
    11159                                }
    11160                        } else {
    11161                                while (it.hasNext()) {
    11162                                        final long iax = it.aLong;
    11163                                        final long ibx = it.bLong;
    11164                                        byte ox;
    11165                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11166                                        oi8data[it.oIndex] = ox;
    11167                                }
    11168                        }
    11169                        break;
    11170                case Dataset.INT16:
    11171                        final short[] oi16data = ((ShortDataset) result).getData();
    11172                        if (it.isOutputDouble()) {
    11173                                while (it.hasNext()) {
    11174                                        final double iax = it.aDouble;
    11175                                        final double ibx = it.bDouble;
    11176                                        short ox;
    11177                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11178                                        oi16data[it.oIndex] = ox;
    11179                                }
    11180                        } else {
    11181                                while (it.hasNext()) {
    11182                                        final long iax = it.aLong;
    11183                                        final long ibx = it.bLong;
    11184                                        short ox;
    11185                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11186                                        oi16data[it.oIndex] = ox;
    11187                                }
    11188                        }
    11189                        break;
    11190                case Dataset.INT64:
    11191                        final long[] oi64data = ((LongDataset) result).getData();
    11192                        if (it.isOutputDouble()) {
    11193                                while (it.hasNext()) {
    11194                                        final double iax = it.aDouble;
    11195                                        final double ibx = it.bDouble;
    11196                                        long ox;
    11197                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11198                                        oi64data[it.oIndex] = ox;
    11199                                }
    11200                        } else {
    11201                                while (it.hasNext()) {
    11202                                        final long iax = it.aLong;
    11203                                        final long ibx = it.bLong;
    11204                                        long ox;
    11205                                        ox = (ibx == 0 ? 0 : iax % ibx);
    11206                                        oi64data[it.oIndex] = ox;
    11207                                }
    11208                        }
    11209                        break;
    11210                case Dataset.INT32:
    11211                        final int[] oi32data = ((IntegerDataset) result).getData();
    11212                        if (it.isOutputDouble()) {
    11213                                while (it.hasNext()) {
    11214                                        final double iax = it.aDouble;
    11215                                        final double ibx = it.bDouble;
    11216                                        int ox;
    11217                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11218                                        oi32data[it.oIndex] = ox;
    11219                                }
    11220                        } else {
    11221                                while (it.hasNext()) {
    11222                                        final long iax = it.aLong;
    11223                                        final long ibx = it.bLong;
    11224                                        int ox;
    11225                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11226                                        oi32data[it.oIndex] = ox;
    11227                                }
    11228                        }
    11229                        break;
    11230                case Dataset.ARRAYINT8:
    11231                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    11232                        if (is == 1) {
    11233                                if (it.isOutputDouble()) {
    11234                                        while (it.hasNext()) {
    11235                                                final double iax = it.aDouble;
    11236                                                final double ibx = it.bDouble;
    11237                                                byte ox;
    11238                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11239                                                oai8data[it.oIndex] = ox;
    11240                                        }
    11241                                } else {
    11242                                        while (it.hasNext()) {
    11243                                                final long iax = it.aLong;
    11244                                                final long ibx = it.bLong;
    11245                                                byte ox;
    11246                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11247                                                oai8data[it.oIndex] = ox;
    11248                                        }
    11249                                }
    11250                        } else if (as < bs) {
    11251                                if (it.isOutputDouble()) {
    11252                                        while (it.hasNext()) {
    11253                                                final double iax = it.aDouble;
    11254                                                double ibx = it.bDouble;
    11255                                                byte ox;
    11256                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11257                                                oai8data[it.oIndex] = ox;
    11258                                                for (int j = 1; j < is; j++) {
    11259                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11260                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11261                                                        oai8data[it.oIndex + j] = ox;
    11262                                                }
    11263                                        }
    11264                                } else {
    11265                                        while (it.hasNext()) {
    11266                                                final long iax = it.aLong;
    11267                                                long ibx = it.bLong;
    11268                                                byte ox;
    11269                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11270                                                oai8data[it.oIndex] = ox;
    11271                                                for (int j = 1; j < is; j++) {
    11272                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11273                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11274                                                        oai8data[it.oIndex + j] = ox;
    11275                                                }
    11276                                        }
    11277                                }
    11278                        } else if (as > bs) {
    11279                                if (it.isOutputDouble()) {
    11280                                        while (it.hasNext()) {
    11281                                                double iax = it.aDouble;
    11282                                                final double ibx = it.bDouble;
    11283                                                byte ox;
    11284                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11285                                                oai8data[it.oIndex] = ox;
    11286                                                for (int j = 1; j < is; j++) {
    11287                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11288                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11289                                                        oai8data[it.oIndex + j] = ox;
    11290                                                }
    11291                                        }
    11292                                } else {
    11293                                        while (it.hasNext()) {
    11294                                                long iax = it.aLong;
    11295                                                final long ibx = it.bLong;
    11296                                                byte ox;
    11297                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11298                                                oai8data[it.oIndex] = ox;
    11299                                                for (int j = 1; j < is; j++) {
    11300                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11301                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11302                                                        oai8data[it.oIndex + j] = ox;
    11303                                                }
    11304                                        }
    11305                                }
    11306                        } else if (as == 1) {
    11307                                if (it.isOutputDouble()) {
    11308                                        while (it.hasNext()) {
    11309                                                final double iax = it.aDouble;
    11310                                                final double ibx = it.bDouble;
    11311                                                byte ox;
    11312                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11313                                                for (int j = 0; j < is; j++) {
    11314                                                        oai8data[it.oIndex + j] = ox;
    11315                                                }
    11316                                        }
    11317                                } else {
    11318                                        while (it.hasNext()) {
    11319                                                final long iax = it.aLong;
    11320                                                final long ibx = it.bLong;
    11321                                                byte ox;
    11322                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11323                                                for (int j = 0; j < is; j++) {
    11324                                                        oai8data[it.oIndex + j] = ox;
    11325                                                }
    11326                                        }
    11327                                }
    11328                        } else {
    11329                                if (it.isOutputDouble()) {
    11330                                        while (it.hasNext()) {
    11331                                                double iax = it.aDouble;
    11332                                                double ibx = it.bDouble;
    11333                                                byte ox;
    11334                                                ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11335                                                oai8data[it.oIndex] = ox;
    11336                                                for (int j = 1; j < is; j++) {
    11337                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11338                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11339                                                        ox = (byte) toLong(ibx == 0 ? 0 : iax % ibx);
    11340                                                        oai8data[it.oIndex + j] = ox;
    11341                                                }
    11342                                        }
    11343                                } else {
    11344                                        while (it.hasNext()) {
    11345                                                long iax = it.aLong;
    11346                                                long ibx = it.bLong;
    11347                                                byte ox;
    11348                                                ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11349                                                oai8data[it.oIndex] = ox;
    11350                                                for (int j = 1; j < is; j++) {
    11351                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11352                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11353                                                        ox = (byte) (ibx == 0 ? 0 : iax % ibx);
    11354                                                        oai8data[it.oIndex + j] = ox;
    11355                                                }
    11356                                        }
    11357                                }
    11358                        }
    11359                        break;
    11360                case Dataset.ARRAYINT16:
    11361                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    11362                        if (is == 1) {
    11363                                if (it.isOutputDouble()) {
    11364                                        while (it.hasNext()) {
    11365                                                final double iax = it.aDouble;
    11366                                                final double ibx = it.bDouble;
    11367                                                short ox;
    11368                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11369                                                oai16data[it.oIndex] = ox;
    11370                                        }
    11371                                } else {
    11372                                        while (it.hasNext()) {
    11373                                                final long iax = it.aLong;
    11374                                                final long ibx = it.bLong;
    11375                                                short ox;
    11376                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11377                                                oai16data[it.oIndex] = ox;
    11378                                        }
    11379                                }
    11380                        } else if (as < bs) {
    11381                                if (it.isOutputDouble()) {
    11382                                        while (it.hasNext()) {
    11383                                                final double iax = it.aDouble;
    11384                                                double ibx = it.bDouble;
    11385                                                short ox;
    11386                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11387                                                oai16data[it.oIndex] = ox;
    11388                                                for (int j = 1; j < is; j++) {
    11389                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11390                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11391                                                        oai16data[it.oIndex + j] = ox;
    11392                                                }
    11393                                        }
    11394                                } else {
    11395                                        while (it.hasNext()) {
    11396                                                final long iax = it.aLong;
    11397                                                long ibx = it.bLong;
    11398                                                short ox;
    11399                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11400                                                oai16data[it.oIndex] = ox;
    11401                                                for (int j = 1; j < is; j++) {
    11402                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11403                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11404                                                        oai16data[it.oIndex + j] = ox;
    11405                                                }
    11406                                        }
    11407                                }
    11408                        } else if (as > bs) {
    11409                                if (it.isOutputDouble()) {
    11410                                        while (it.hasNext()) {
    11411                                                double iax = it.aDouble;
    11412                                                final double ibx = it.bDouble;
    11413                                                short ox;
    11414                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11415                                                oai16data[it.oIndex] = ox;
    11416                                                for (int j = 1; j < is; j++) {
    11417                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11418                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11419                                                        oai16data[it.oIndex + j] = ox;
    11420                                                }
    11421                                        }
    11422                                } else {
    11423                                        while (it.hasNext()) {
    11424                                                long iax = it.aLong;
    11425                                                final long ibx = it.bLong;
    11426                                                short ox;
    11427                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11428                                                oai16data[it.oIndex] = ox;
    11429                                                for (int j = 1; j < is; j++) {
    11430                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11431                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11432                                                        oai16data[it.oIndex + j] = ox;
    11433                                                }
    11434                                        }
    11435                                }
    11436                        } else if (as == 1) {
    11437                                if (it.isOutputDouble()) {
    11438                                        while (it.hasNext()) {
    11439                                                final double iax = it.aDouble;
    11440                                                final double ibx = it.bDouble;
    11441                                                short ox;
    11442                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11443                                                for (int j = 0; j < is; j++) {
    11444                                                        oai16data[it.oIndex + j] = ox;
    11445                                                }
    11446                                        }
    11447                                } else {
    11448                                        while (it.hasNext()) {
    11449                                                final long iax = it.aLong;
    11450                                                final long ibx = it.bLong;
    11451                                                short ox;
    11452                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11453                                                for (int j = 0; j < is; j++) {
    11454                                                        oai16data[it.oIndex + j] = ox;
    11455                                                }
    11456                                        }
    11457                                }
    11458                        } else {
    11459                                if (it.isOutputDouble()) {
    11460                                        while (it.hasNext()) {
    11461                                                double iax = it.aDouble;
    11462                                                double ibx = it.bDouble;
    11463                                                short ox;
    11464                                                ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11465                                                oai16data[it.oIndex] = ox;
    11466                                                for (int j = 1; j < is; j++) {
    11467                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11468                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11469                                                        ox = (short) toLong(ibx == 0 ? 0 : iax % ibx);
    11470                                                        oai16data[it.oIndex + j] = ox;
    11471                                                }
    11472                                        }
    11473                                } else {
    11474                                        while (it.hasNext()) {
    11475                                                long iax = it.aLong;
    11476                                                long ibx = it.bLong;
    11477                                                short ox;
    11478                                                ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11479                                                oai16data[it.oIndex] = ox;
    11480                                                for (int j = 1; j < is; j++) {
    11481                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11482                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11483                                                        ox = (short) (ibx == 0 ? 0 : iax % ibx);
    11484                                                        oai16data[it.oIndex + j] = ox;
    11485                                                }
    11486                                        }
    11487                                }
    11488                        }
    11489                        break;
    11490                case Dataset.ARRAYINT64:
    11491                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    11492                        if (is == 1) {
    11493                                if (it.isOutputDouble()) {
    11494                                        while (it.hasNext()) {
    11495                                                final double iax = it.aDouble;
    11496                                                final double ibx = it.bDouble;
    11497                                                long ox;
    11498                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11499                                                oai64data[it.oIndex] = ox;
    11500                                        }
    11501                                } else {
    11502                                        while (it.hasNext()) {
    11503                                                final long iax = it.aLong;
    11504                                                final long ibx = it.bLong;
    11505                                                long ox;
    11506                                                ox = (ibx == 0 ? 0 : iax % ibx);
    11507                                                oai64data[it.oIndex] = ox;
    11508                                        }
    11509                                }
    11510                        } else if (as < bs) {
    11511                                if (it.isOutputDouble()) {
    11512                                        while (it.hasNext()) {
    11513                                                final double iax = it.aDouble;
    11514                                                double ibx = it.bDouble;
    11515                                                long ox;
    11516                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11517                                                oai64data[it.oIndex] = ox;
    11518                                                for (int j = 1; j < is; j++) {
    11519                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11520                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11521                                                        oai64data[it.oIndex + j] = ox;
    11522                                                }
    11523                                        }
    11524                                } else {
    11525                                        while (it.hasNext()) {
    11526                                                final long iax = it.aLong;
    11527                                                long ibx = it.bLong;
    11528                                                long ox;
    11529                                                ox = (ibx == 0 ? 0 : iax % ibx);
    11530                                                oai64data[it.oIndex] = ox;
    11531                                                for (int j = 1; j < is; j++) {
    11532                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11533                                                        ox = (ibx == 0 ? 0 : iax % ibx);
    11534                                                        oai64data[it.oIndex + j] = ox;
    11535                                                }
    11536                                        }
    11537                                }
    11538                        } else if (as > bs) {
    11539                                if (it.isOutputDouble()) {
    11540                                        while (it.hasNext()) {
    11541                                                double iax = it.aDouble;
    11542                                                final double ibx = it.bDouble;
    11543                                                long ox;
    11544                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11545                                                oai64data[it.oIndex] = ox;
    11546                                                for (int j = 1; j < is; j++) {
    11547                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11548                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11549                                                        oai64data[it.oIndex + j] = ox;
    11550                                                }
    11551                                        }
    11552                                } else {
    11553                                        while (it.hasNext()) {
    11554                                                long iax = it.aLong;
    11555                                                final long ibx = it.bLong;
    11556                                                long ox;
    11557                                                ox = (ibx == 0 ? 0 : iax % ibx);
    11558                                                oai64data[it.oIndex] = ox;
    11559                                                for (int j = 1; j < is; j++) {
    11560                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11561                                                        ox = (ibx == 0 ? 0 : iax % ibx);
    11562                                                        oai64data[it.oIndex + j] = ox;
    11563                                                }
    11564                                        }
    11565                                }
    11566                        } else if (as == 1) {
    11567                                if (it.isOutputDouble()) {
    11568                                        while (it.hasNext()) {
    11569                                                final double iax = it.aDouble;
    11570                                                final double ibx = it.bDouble;
    11571                                                long ox;
    11572                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11573                                                for (int j = 0; j < is; j++) {
    11574                                                        oai64data[it.oIndex + j] = ox;
    11575                                                }
    11576                                        }
    11577                                } else {
    11578                                        while (it.hasNext()) {
    11579                                                final long iax = it.aLong;
    11580                                                final long ibx = it.bLong;
    11581                                                long ox;
    11582                                                ox = (ibx == 0 ? 0 : iax % ibx);
    11583                                                for (int j = 0; j < is; j++) {
    11584                                                        oai64data[it.oIndex + j] = ox;
    11585                                                }
    11586                                        }
    11587                                }
    11588                        } else {
    11589                                if (it.isOutputDouble()) {
    11590                                        while (it.hasNext()) {
    11591                                                double iax = it.aDouble;
    11592                                                double ibx = it.bDouble;
    11593                                                long ox;
    11594                                                ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11595                                                oai64data[it.oIndex] = ox;
    11596                                                for (int j = 1; j < is; j++) {
    11597                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11598                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11599                                                        ox = toLong(ibx == 0 ? 0 : iax % ibx);
    11600                                                        oai64data[it.oIndex + j] = ox;
    11601                                                }
    11602                                        }
    11603                                } else {
    11604                                        while (it.hasNext()) {
    11605                                                long iax = it.aLong;
    11606                                                long ibx = it.bLong;
    11607                                                long ox;
    11608                                                ox = (ibx == 0 ? 0 : iax % ibx);
    11609                                                oai64data[it.oIndex] = ox;
    11610                                                for (int j = 1; j < is; j++) {
    11611                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11612                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11613                                                        ox = (ibx == 0 ? 0 : iax % ibx);
    11614                                                        oai64data[it.oIndex + j] = ox;
    11615                                                }
    11616                                        }
    11617                                }
    11618                        }
    11619                        break;
    11620                case Dataset.ARRAYINT32:
    11621                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    11622                        if (is == 1) {
    11623                                if (it.isOutputDouble()) {
    11624                                        while (it.hasNext()) {
    11625                                                final double iax = it.aDouble;
    11626                                                final double ibx = it.bDouble;
    11627                                                int ox;
    11628                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11629                                                oai32data[it.oIndex] = ox;
    11630                                        }
    11631                                } else {
    11632                                        while (it.hasNext()) {
    11633                                                final long iax = it.aLong;
    11634                                                final long ibx = it.bLong;
    11635                                                int ox;
    11636                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11637                                                oai32data[it.oIndex] = ox;
    11638                                        }
    11639                                }
    11640                        } else if (as < bs) {
    11641                                if (it.isOutputDouble()) {
    11642                                        while (it.hasNext()) {
    11643                                                final double iax = it.aDouble;
    11644                                                double ibx = it.bDouble;
    11645                                                int ox;
    11646                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11647                                                oai32data[it.oIndex] = ox;
    11648                                                for (int j = 1; j < is; j++) {
    11649                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11650                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11651                                                        oai32data[it.oIndex + j] = ox;
    11652                                                }
    11653                                        }
    11654                                } else {
    11655                                        while (it.hasNext()) {
    11656                                                final long iax = it.aLong;
    11657                                                long ibx = it.bLong;
    11658                                                int ox;
    11659                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11660                                                oai32data[it.oIndex] = ox;
    11661                                                for (int j = 1; j < is; j++) {
    11662                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11663                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11664                                                        oai32data[it.oIndex + j] = ox;
    11665                                                }
    11666                                        }
    11667                                }
    11668                        } else if (as > bs) {
    11669                                if (it.isOutputDouble()) {
    11670                                        while (it.hasNext()) {
    11671                                                double iax = it.aDouble;
    11672                                                final double ibx = it.bDouble;
    11673                                                int ox;
    11674                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11675                                                oai32data[it.oIndex] = ox;
    11676                                                for (int j = 1; j < is; j++) {
    11677                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11678                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11679                                                        oai32data[it.oIndex + j] = ox;
    11680                                                }
    11681                                        }
    11682                                } else {
    11683                                        while (it.hasNext()) {
    11684                                                long iax = it.aLong;
    11685                                                final long ibx = it.bLong;
    11686                                                int ox;
    11687                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11688                                                oai32data[it.oIndex] = ox;
    11689                                                for (int j = 1; j < is; j++) {
    11690                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11691                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11692                                                        oai32data[it.oIndex + j] = ox;
    11693                                                }
    11694                                        }
    11695                                }
    11696                        } else if (as == 1) {
    11697                                if (it.isOutputDouble()) {
    11698                                        while (it.hasNext()) {
    11699                                                final double iax = it.aDouble;
    11700                                                final double ibx = it.bDouble;
    11701                                                int ox;
    11702                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11703                                                for (int j = 0; j < is; j++) {
    11704                                                        oai32data[it.oIndex + j] = ox;
    11705                                                }
    11706                                        }
    11707                                } else {
    11708                                        while (it.hasNext()) {
    11709                                                final long iax = it.aLong;
    11710                                                final long ibx = it.bLong;
    11711                                                int ox;
    11712                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11713                                                for (int j = 0; j < is; j++) {
    11714                                                        oai32data[it.oIndex + j] = ox;
    11715                                                }
    11716                                        }
    11717                                }
    11718                        } else {
    11719                                if (it.isOutputDouble()) {
    11720                                        while (it.hasNext()) {
    11721                                                double iax = it.aDouble;
    11722                                                double ibx = it.bDouble;
    11723                                                int ox;
    11724                                                ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11725                                                oai32data[it.oIndex] = ox;
    11726                                                for (int j = 1; j < is; j++) {
    11727                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11728                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11729                                                        ox = (int) toLong(ibx == 0 ? 0 : iax % ibx);
    11730                                                        oai32data[it.oIndex + j] = ox;
    11731                                                }
    11732                                        }
    11733                                } else {
    11734                                        while (it.hasNext()) {
    11735                                                long iax = it.aLong;
    11736                                                long ibx = it.bLong;
    11737                                                int ox;
    11738                                                ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11739                                                oai32data[it.oIndex] = ox;
    11740                                                for (int j = 1; j < is; j++) {
    11741                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11742                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11743                                                        ox = (int) (ibx == 0 ? 0 : iax % ibx);
    11744                                                        oai32data[it.oIndex + j] = ox;
    11745                                                }
    11746                                        }
    11747                                }
    11748                        }
    11749                        break;
    11750                case Dataset.FLOAT32:
    11751                        final float[] of32data = ((FloatDataset) result).getData();
    11752                        if (it.isOutputDouble()) {
    11753                                while (it.hasNext()) {
    11754                                        final double iax = it.aDouble;
    11755                                        final double ibx = it.bDouble;
    11756                                        float ox;
    11757                                        ox = (float) (iax % ibx);
    11758                                        of32data[it.oIndex] = ox;
    11759                                }
    11760                        } else {
    11761                                while (it.hasNext()) {
    11762                                        final long iax = it.aLong;
    11763                                        final long ibx = it.bLong;
    11764                                        float ox;
    11765                                        ox = (iax % ibx);
    11766                                        of32data[it.oIndex] = ox;
    11767                                }
    11768                        }
    11769                        break;
    11770                case Dataset.FLOAT64:
    11771                        final double[] of64data = ((DoubleDataset) result).getData();
    11772                        if (it.isOutputDouble()) {
    11773                                while (it.hasNext()) {
    11774                                        final double iax = it.aDouble;
    11775                                        final double ibx = it.bDouble;
    11776                                        double ox;
    11777                                        ox = (iax % ibx);
    11778                                        of64data[it.oIndex] = ox;
    11779                                }
    11780                        } else {
    11781                                while (it.hasNext()) {
    11782                                        final long iax = it.aLong;
    11783                                        final long ibx = it.bLong;
    11784                                        double ox;
    11785                                        ox = (iax % ibx);
    11786                                        of64data[it.oIndex] = ox;
    11787                                }
    11788                        }
    11789                        break;
    11790                case Dataset.ARRAYFLOAT32:
    11791                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    11792                        if (is == 1) {
    11793                                if (it.isOutputDouble()) {
    11794                                        while (it.hasNext()) {
    11795                                                final double iax = it.aDouble;
    11796                                                final double ibx = it.bDouble;
    11797                                                float ox;
    11798                                                ox = (float) (iax % ibx);
    11799                                                oaf32data[it.oIndex] = ox;
    11800                                        }
    11801                                } else {
    11802                                        while (it.hasNext()) {
    11803                                                final long iax = it.aLong;
    11804                                                final long ibx = it.bLong;
    11805                                                float ox;
    11806                                                ox = (iax % ibx);
    11807                                                oaf32data[it.oIndex] = ox;
    11808                                        }
    11809                                }
    11810                        } else if (as < bs) {
    11811                                if (it.isOutputDouble()) {
    11812                                        while (it.hasNext()) {
    11813                                                final double iax = it.aDouble;
    11814                                                double ibx = it.bDouble;
    11815                                                float ox;
    11816                                                ox = (float) (iax % ibx);
    11817                                                oaf32data[it.oIndex] = ox;
    11818                                                for (int j = 1; j < is; j++) {
    11819                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11820                                                        ox = (float) (iax % ibx);
    11821                                                        oaf32data[it.oIndex + j] = ox;
    11822                                                }
    11823                                        }
    11824                                } else {
    11825                                        while (it.hasNext()) {
    11826                                                final long iax = it.aLong;
    11827                                                long ibx = it.bLong;
    11828                                                float ox;
    11829                                                ox = (iax % ibx);
    11830                                                oaf32data[it.oIndex] = ox;
    11831                                                for (int j = 1; j < is; j++) {
    11832                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11833                                                        ox = (iax % ibx);
    11834                                                        oaf32data[it.oIndex + j] = ox;
    11835                                                }
    11836                                        }
    11837                                }
    11838                        } else if (as > bs) {
    11839                                if (it.isOutputDouble()) {
    11840                                        while (it.hasNext()) {
    11841                                                double iax = it.aDouble;
    11842                                                final double ibx = it.bDouble;
    11843                                                float ox;
    11844                                                ox = (float) (iax % ibx);
    11845                                                oaf32data[it.oIndex] = ox;
    11846                                                for (int j = 1; j < is; j++) {
    11847                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11848                                                        ox = (float) (iax % ibx);
    11849                                                        oaf32data[it.oIndex + j] = ox;
    11850                                                }
    11851                                        }
    11852                                } else {
    11853                                        while (it.hasNext()) {
    11854                                                long iax = it.aLong;
    11855                                                final long ibx = it.bLong;
    11856                                                float ox;
    11857                                                ox = (iax % ibx);
    11858                                                oaf32data[it.oIndex] = ox;
    11859                                                for (int j = 1; j < is; j++) {
    11860                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11861                                                        ox = (iax % ibx);
    11862                                                        oaf32data[it.oIndex + j] = ox;
    11863                                                }
    11864                                        }
    11865                                }
    11866                        } else if (as == 1) {
    11867                                if (it.isOutputDouble()) {
    11868                                        while (it.hasNext()) {
    11869                                                final double iax = it.aDouble;
    11870                                                final double ibx = it.bDouble;
    11871                                                float ox;
    11872                                                ox = (float) (iax % ibx);
    11873                                                for (int j = 0; j < is; j++) {
    11874                                                        oaf32data[it.oIndex + j] = ox;
    11875                                                }
    11876                                        }
    11877                                } else {
    11878                                        while (it.hasNext()) {
    11879                                                final long iax = it.aLong;
    11880                                                final long ibx = it.bLong;
    11881                                                float ox;
    11882                                                ox = (iax % ibx);
    11883                                                for (int j = 0; j < is; j++) {
    11884                                                        oaf32data[it.oIndex + j] = ox;
    11885                                                }
    11886                                        }
    11887                                }
    11888                        } else {
    11889                                if (it.isOutputDouble()) {
    11890                                        while (it.hasNext()) {
    11891                                                double iax = it.aDouble;
    11892                                                double ibx = it.bDouble;
    11893                                                float ox;
    11894                                                ox = (float) (iax % ibx);
    11895                                                oaf32data[it.oIndex] = ox;
    11896                                                for (int j = 1; j < is; j++) {
    11897                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11898                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11899                                                        ox = (float) (iax % ibx);
    11900                                                        oaf32data[it.oIndex + j] = ox;
    11901                                                }
    11902                                        }
    11903                                } else {
    11904                                        while (it.hasNext()) {
    11905                                                long iax = it.aLong;
    11906                                                long ibx = it.bLong;
    11907                                                float ox;
    11908                                                ox = (iax % ibx);
    11909                                                oaf32data[it.oIndex] = ox;
    11910                                                for (int j = 1; j < is; j++) {
    11911                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11912                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11913                                                        ox = (iax % ibx);
    11914                                                        oaf32data[it.oIndex + j] = ox;
    11915                                                }
    11916                                        }
    11917                                }
    11918                        }
    11919                        break;
    11920                case Dataset.ARRAYFLOAT64:
    11921                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    11922                        if (is == 1) {
    11923                                if (it.isOutputDouble()) {
    11924                                        while (it.hasNext()) {
    11925                                                final double iax = it.aDouble;
    11926                                                final double ibx = it.bDouble;
    11927                                                double ox;
    11928                                                ox = (iax % ibx);
    11929                                                oaf64data[it.oIndex] = ox;
    11930                                        }
    11931                                } else {
    11932                                        while (it.hasNext()) {
    11933                                                final long iax = it.aLong;
    11934                                                final long ibx = it.bLong;
    11935                                                double ox;
    11936                                                ox = (iax % ibx);
    11937                                                oaf64data[it.oIndex] = ox;
    11938                                        }
    11939                                }
    11940                        } else if (as < bs) {
    11941                                if (it.isOutputDouble()) {
    11942                                        while (it.hasNext()) {
    11943                                                final double iax = it.aDouble;
    11944                                                double ibx = it.bDouble;
    11945                                                double ox;
    11946                                                ox = (iax % ibx);
    11947                                                oaf64data[it.oIndex] = ox;
    11948                                                for (int j = 1; j < is; j++) {
    11949                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    11950                                                        ox = (iax % ibx);
    11951                                                        oaf64data[it.oIndex + j] = ox;
    11952                                                }
    11953                                        }
    11954                                } else {
    11955                                        while (it.hasNext()) {
    11956                                                final long iax = it.aLong;
    11957                                                long ibx = it.bLong;
    11958                                                double ox;
    11959                                                ox = (iax % ibx);
    11960                                                oaf64data[it.oIndex] = ox;
    11961                                                for (int j = 1; j < is; j++) {
    11962                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    11963                                                        ox = (iax % ibx);
    11964                                                        oaf64data[it.oIndex + j] = ox;
    11965                                                }
    11966                                        }
    11967                                }
    11968                        } else if (as > bs) {
    11969                                if (it.isOutputDouble()) {
    11970                                        while (it.hasNext()) {
    11971                                                double iax = it.aDouble;
    11972                                                final double ibx = it.bDouble;
    11973                                                double ox;
    11974                                                ox = (iax % ibx);
    11975                                                oaf64data[it.oIndex] = ox;
    11976                                                for (int j = 1; j < is; j++) {
    11977                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    11978                                                        ox = (iax % ibx);
    11979                                                        oaf64data[it.oIndex + j] = ox;
    11980                                                }
    11981                                        }
    11982                                } else {
    11983                                        while (it.hasNext()) {
    11984                                                long iax = it.aLong;
    11985                                                final long ibx = it.bLong;
    11986                                                double ox;
    11987                                                ox = (iax % ibx);
    11988                                                oaf64data[it.oIndex] = ox;
    11989                                                for (int j = 1; j < is; j++) {
    11990                                                        iax = da.getElementLongAbs(it.aIndex + j);
    11991                                                        ox = (iax % ibx);
    11992                                                        oaf64data[it.oIndex + j] = ox;
    11993                                                }
    11994                                        }
    11995                                }
    11996                        } else if (as == 1) {
    11997                                if (it.isOutputDouble()) {
    11998                                        while (it.hasNext()) {
    11999                                                final double iax = it.aDouble;
    12000                                                final double ibx = it.bDouble;
    12001                                                double ox;
    12002                                                ox = (iax % ibx);
    12003                                                for (int j = 0; j < is; j++) {
    12004                                                        oaf64data[it.oIndex + j] = ox;
    12005                                                }
    12006                                        }
    12007                                } else {
    12008                                        while (it.hasNext()) {
    12009                                                final long iax = it.aLong;
    12010                                                final long ibx = it.bLong;
    12011                                                double ox;
    12012                                                ox = (iax % ibx);
    12013                                                for (int j = 0; j < is; j++) {
    12014                                                        oaf64data[it.oIndex + j] = ox;
    12015                                                }
    12016                                        }
    12017                                }
    12018                        } else {
    12019                                if (it.isOutputDouble()) {
    12020                                        while (it.hasNext()) {
    12021                                                double iax = it.aDouble;
    12022                                                double ibx = it.bDouble;
    12023                                                double ox;
    12024                                                ox = (iax % ibx);
    12025                                                oaf64data[it.oIndex] = ox;
    12026                                                for (int j = 1; j < is; j++) {
    12027                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12028                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12029                                                        ox = (iax % ibx);
    12030                                                        oaf64data[it.oIndex + j] = ox;
    12031                                                }
    12032                                        }
    12033                                } else {
    12034                                        while (it.hasNext()) {
    12035                                                long iax = it.aLong;
    12036                                                long ibx = it.bLong;
    12037                                                double ox;
    12038                                                ox = (iax % ibx);
    12039                                                oaf64data[it.oIndex] = ox;
    12040                                                for (int j = 1; j < is; j++) {
    12041                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12042                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12043                                                        ox = (iax % ibx);
    12044                                                        oaf64data[it.oIndex + j] = ox;
    12045                                                }
    12046                                        }
    12047                                }
    12048                        }
    12049                        break;
    12050                default:
    12051                        throw new IllegalArgumentException("remainder supports integer, compound integer, real, compound real datasets only");
    12052                }
    12053
    12054                addBinaryOperatorName(da, db, result, "%");
    12055                return result;
    12056        }
    12057
    12058        /**
    12059         * maximum operator
    12060         * @param a
    12061         * @param b
    12062         * @return return maximum of a and b
    12063         */
    12064        public static Dataset maximum(final Object a, final Object b) {
    12065                return maximum(a, b, null);
    12066        }
    12067
    12068        /**
    12069         * maximum operator
    12070         * @param a
    12071         * @param b
    12072         * @param o output can be null - in which case, a new dataset is created
    12073         * @return return maximum of a and b
    12074         */
    12075        public static Dataset maximum(final Object a, final Object b, final Dataset o) {
    12076                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    12077                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    12078                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    12079                final Dataset result = it.getOutput();
    12080                final int is = result.getElementsPerItem();
    12081                final int as = da.getElementsPerItem();
    12082                final int bs = db.getElementsPerItem();
    12083                final int dt = result.getDType();
    12084
    12085                switch(dt) {
    12086                case Dataset.INT8:
    12087                        final byte[] oi8data = ((ByteDataset) result).getData();
    12088                        if (it.isOutputDouble()) {
    12089                                while (it.hasNext()) {
    12090                                        final double iax = it.aDouble;
    12091                                        final double ibx = it.bDouble;
    12092                                        byte ox;
    12093                                        ox = (byte) toLong(Math.max(iax, ibx));
    12094                                        oi8data[it.oIndex] = ox;
    12095                                }
    12096                        } else {
    12097                                while (it.hasNext()) {
    12098                                        final long iax = it.aLong;
    12099                                        final long ibx = it.bLong;
    12100                                        byte ox;
    12101                                        ox = (byte) toLong(Math.max(iax, ibx));
    12102                                        oi8data[it.oIndex] = ox;
    12103                                }
    12104                        }
    12105                        break;
    12106                case Dataset.INT16:
    12107                        final short[] oi16data = ((ShortDataset) result).getData();
    12108                        if (it.isOutputDouble()) {
    12109                                while (it.hasNext()) {
    12110                                        final double iax = it.aDouble;
    12111                                        final double ibx = it.bDouble;
    12112                                        short ox;
    12113                                        ox = (short) toLong(Math.max(iax, ibx));
    12114                                        oi16data[it.oIndex] = ox;
    12115                                }
    12116                        } else {
    12117                                while (it.hasNext()) {
    12118                                        final long iax = it.aLong;
    12119                                        final long ibx = it.bLong;
    12120                                        short ox;
    12121                                        ox = (short) toLong(Math.max(iax, ibx));
    12122                                        oi16data[it.oIndex] = ox;
    12123                                }
    12124                        }
    12125                        break;
    12126                case Dataset.INT64:
    12127                        final long[] oi64data = ((LongDataset) result).getData();
    12128                        if (it.isOutputDouble()) {
    12129                                while (it.hasNext()) {
    12130                                        final double iax = it.aDouble;
    12131                                        final double ibx = it.bDouble;
    12132                                        long ox;
    12133                                        ox = toLong(Math.max(iax, ibx));
    12134                                        oi64data[it.oIndex] = ox;
    12135                                }
    12136                        } else {
    12137                                while (it.hasNext()) {
    12138                                        final long iax = it.aLong;
    12139                                        final long ibx = it.bLong;
    12140                                        long ox;
    12141                                        ox = toLong(Math.max(iax, ibx));
    12142                                        oi64data[it.oIndex] = ox;
    12143                                }
    12144                        }
    12145                        break;
    12146                case Dataset.INT32:
    12147                        final int[] oi32data = ((IntegerDataset) result).getData();
    12148                        if (it.isOutputDouble()) {
    12149                                while (it.hasNext()) {
    12150                                        final double iax = it.aDouble;
    12151                                        final double ibx = it.bDouble;
    12152                                        int ox;
    12153                                        ox = (int) toLong(Math.max(iax, ibx));
    12154                                        oi32data[it.oIndex] = ox;
    12155                                }
    12156                        } else {
    12157                                while (it.hasNext()) {
    12158                                        final long iax = it.aLong;
    12159                                        final long ibx = it.bLong;
    12160                                        int ox;
    12161                                        ox = (int) toLong(Math.max(iax, ibx));
    12162                                        oi32data[it.oIndex] = ox;
    12163                                }
    12164                        }
    12165                        break;
    12166                case Dataset.ARRAYINT8:
    12167                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    12168                        if (is == 1) {
    12169                                if (it.isOutputDouble()) {
    12170                                        while (it.hasNext()) {
    12171                                                final double iax = it.aDouble;
    12172                                                final double ibx = it.bDouble;
    12173                                                byte ox;
    12174                                                ox = (byte) toLong(Math.max(iax, ibx));
    12175                                                oai8data[it.oIndex] = ox;
    12176                                        }
    12177                                } else {
    12178                                        while (it.hasNext()) {
    12179                                                final long iax = it.aLong;
    12180                                                final long ibx = it.bLong;
    12181                                                byte ox;
    12182                                                ox = (byte) toLong(Math.max(iax, ibx));
    12183                                                oai8data[it.oIndex] = ox;
    12184                                        }
    12185                                }
    12186                        } else if (as < bs) {
    12187                                if (it.isOutputDouble()) {
    12188                                        while (it.hasNext()) {
    12189                                                final double iax = it.aDouble;
    12190                                                double ibx = it.bDouble;
    12191                                                byte ox;
    12192                                                ox = (byte) toLong(Math.max(iax, ibx));
    12193                                                oai8data[it.oIndex] = ox;
    12194                                                for (int j = 1; j < is; j++) {
    12195                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12196                                                        ox = (byte) toLong(Math.max(iax, ibx));
    12197                                                        oai8data[it.oIndex + j] = ox;
    12198                                                }
    12199                                        }
    12200                                } else {
    12201                                        while (it.hasNext()) {
    12202                                                final long iax = it.aLong;
    12203                                                long ibx = it.bLong;
    12204                                                byte ox;
    12205                                                ox = (byte) toLong(Math.max(iax, ibx));
    12206                                                oai8data[it.oIndex] = ox;
    12207                                                for (int j = 1; j < is; j++) {
    12208                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12209                                                        ox = (byte) toLong(Math.max(iax, ibx));
    12210                                                        oai8data[it.oIndex + j] = ox;
    12211                                                }
    12212                                        }
    12213                                }
    12214                        } else if (as > bs) {
    12215                                if (it.isOutputDouble()) {
    12216                                        while (it.hasNext()) {
    12217                                                double iax = it.aDouble;
    12218                                                final double ibx = it.bDouble;
    12219                                                byte ox;
    12220                                                ox = (byte) toLong(Math.max(iax, ibx));
    12221                                                oai8data[it.oIndex] = ox;
    12222                                                for (int j = 1; j < is; j++) {
    12223                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12224                                                        ox = (byte) toLong(Math.max(iax, ibx));
    12225                                                        oai8data[it.oIndex + j] = ox;
    12226                                                }
    12227                                        }
    12228                                } else {
    12229                                        while (it.hasNext()) {
    12230                                                long iax = it.aLong;
    12231                                                final long ibx = it.bLong;
    12232                                                byte ox;
    12233                                                ox = (byte) toLong(Math.max(iax, ibx));
    12234                                                oai8data[it.oIndex] = ox;
    12235                                                for (int j = 1; j < is; j++) {
    12236                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12237                                                        ox = (byte) toLong(Math.max(iax, ibx));
    12238                                                        oai8data[it.oIndex + j] = ox;
    12239                                                }
    12240                                        }
    12241                                }
    12242                        } else if (as == 1) {
    12243                                if (it.isOutputDouble()) {
    12244                                        while (it.hasNext()) {
    12245                                                final double iax = it.aDouble;
    12246                                                final double ibx = it.bDouble;
    12247                                                byte ox;
    12248                                                ox = (byte) toLong(Math.max(iax, ibx));
    12249                                                for (int j = 0; j < is; j++) {
    12250                                                        oai8data[it.oIndex + j] = ox;
    12251                                                }
    12252                                        }
    12253                                } else {
    12254                                        while (it.hasNext()) {
    12255                                                final long iax = it.aLong;
    12256                                                final long ibx = it.bLong;
    12257                                                byte ox;
    12258                                                ox = (byte) toLong(Math.max(iax, ibx));
    12259                                                for (int j = 0; j < is; j++) {
    12260                                                        oai8data[it.oIndex + j] = ox;
    12261                                                }
    12262                                        }
    12263                                }
    12264                        } else {
    12265                                if (it.isOutputDouble()) {
    12266                                        while (it.hasNext()) {
    12267                                                double iax = it.aDouble;
    12268                                                double ibx = it.bDouble;
    12269                                                byte ox;
    12270                                                ox = (byte) toLong(Math.max(iax, ibx));
    12271                                                oai8data[it.oIndex] = ox;
    12272                                                for (int j = 1; j < is; j++) {
    12273                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12274                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12275                                                        ox = (byte) toLong(Math.max(iax, ibx));
    12276                                                        oai8data[it.oIndex + j] = ox;
    12277                                                }
    12278                                        }
    12279                                } else {
    12280                                        while (it.hasNext()) {
    12281                                                long iax = it.aLong;
    12282                                                long ibx = it.bLong;
    12283                                                byte ox;
    12284                                                ox = (byte) toLong(Math.max(iax, ibx));
    12285                                                oai8data[it.oIndex] = ox;
    12286                                                for (int j = 1; j < is; j++) {
    12287                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12288                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12289                                                        ox = (byte) toLong(Math.max(iax, ibx));
    12290                                                        oai8data[it.oIndex + j] = ox;
    12291                                                }
    12292                                        }
    12293                                }
    12294                        }
    12295                        break;
    12296                case Dataset.ARRAYINT16:
    12297                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    12298                        if (is == 1) {
    12299                                if (it.isOutputDouble()) {
    12300                                        while (it.hasNext()) {
    12301                                                final double iax = it.aDouble;
    12302                                                final double ibx = it.bDouble;
    12303                                                short ox;
    12304                                                ox = (short) toLong(Math.max(iax, ibx));
    12305                                                oai16data[it.oIndex] = ox;
    12306                                        }
    12307                                } else {
    12308                                        while (it.hasNext()) {
    12309                                                final long iax = it.aLong;
    12310                                                final long ibx = it.bLong;
    12311                                                short ox;
    12312                                                ox = (short) toLong(Math.max(iax, ibx));
    12313                                                oai16data[it.oIndex] = ox;
    12314                                        }
    12315                                }
    12316                        } else if (as < bs) {
    12317                                if (it.isOutputDouble()) {
    12318                                        while (it.hasNext()) {
    12319                                                final double iax = it.aDouble;
    12320                                                double ibx = it.bDouble;
    12321                                                short ox;
    12322                                                ox = (short) toLong(Math.max(iax, ibx));
    12323                                                oai16data[it.oIndex] = ox;
    12324                                                for (int j = 1; j < is; j++) {
    12325                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12326                                                        ox = (short) toLong(Math.max(iax, ibx));
    12327                                                        oai16data[it.oIndex + j] = ox;
    12328                                                }
    12329                                        }
    12330                                } else {
    12331                                        while (it.hasNext()) {
    12332                                                final long iax = it.aLong;
    12333                                                long ibx = it.bLong;
    12334                                                short ox;
    12335                                                ox = (short) toLong(Math.max(iax, ibx));
    12336                                                oai16data[it.oIndex] = ox;
    12337                                                for (int j = 1; j < is; j++) {
    12338                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12339                                                        ox = (short) toLong(Math.max(iax, ibx));
    12340                                                        oai16data[it.oIndex + j] = ox;
    12341                                                }
    12342                                        }
    12343                                }
    12344                        } else if (as > bs) {
    12345                                if (it.isOutputDouble()) {
    12346                                        while (it.hasNext()) {
    12347                                                double iax = it.aDouble;
    12348                                                final double ibx = it.bDouble;
    12349                                                short ox;
    12350                                                ox = (short) toLong(Math.max(iax, ibx));
    12351                                                oai16data[it.oIndex] = ox;
    12352                                                for (int j = 1; j < is; j++) {
    12353                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12354                                                        ox = (short) toLong(Math.max(iax, ibx));
    12355                                                        oai16data[it.oIndex + j] = ox;
    12356                                                }
    12357                                        }
    12358                                } else {
    12359                                        while (it.hasNext()) {
    12360                                                long iax = it.aLong;
    12361                                                final long ibx = it.bLong;
    12362                                                short ox;
    12363                                                ox = (short) toLong(Math.max(iax, ibx));
    12364                                                oai16data[it.oIndex] = ox;
    12365                                                for (int j = 1; j < is; j++) {
    12366                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12367                                                        ox = (short) toLong(Math.max(iax, ibx));
    12368                                                        oai16data[it.oIndex + j] = ox;
    12369                                                }
    12370                                        }
    12371                                }
    12372                        } else if (as == 1) {
    12373                                if (it.isOutputDouble()) {
    12374                                        while (it.hasNext()) {
    12375                                                final double iax = it.aDouble;
    12376                                                final double ibx = it.bDouble;
    12377                                                short ox;
    12378                                                ox = (short) toLong(Math.max(iax, ibx));
    12379                                                for (int j = 0; j < is; j++) {
    12380                                                        oai16data[it.oIndex + j] = ox;
    12381                                                }
    12382                                        }
    12383                                } else {
    12384                                        while (it.hasNext()) {
    12385                                                final long iax = it.aLong;
    12386                                                final long ibx = it.bLong;
    12387                                                short ox;
    12388                                                ox = (short) toLong(Math.max(iax, ibx));
    12389                                                for (int j = 0; j < is; j++) {
    12390                                                        oai16data[it.oIndex + j] = ox;
    12391                                                }
    12392                                        }
    12393                                }
    12394                        } else {
    12395                                if (it.isOutputDouble()) {
    12396                                        while (it.hasNext()) {
    12397                                                double iax = it.aDouble;
    12398                                                double ibx = it.bDouble;
    12399                                                short ox;
    12400                                                ox = (short) toLong(Math.max(iax, ibx));
    12401                                                oai16data[it.oIndex] = ox;
    12402                                                for (int j = 1; j < is; j++) {
    12403                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12404                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12405                                                        ox = (short) toLong(Math.max(iax, ibx));
    12406                                                        oai16data[it.oIndex + j] = ox;
    12407                                                }
    12408                                        }
    12409                                } else {
    12410                                        while (it.hasNext()) {
    12411                                                long iax = it.aLong;
    12412                                                long ibx = it.bLong;
    12413                                                short ox;
    12414                                                ox = (short) toLong(Math.max(iax, ibx));
    12415                                                oai16data[it.oIndex] = ox;
    12416                                                for (int j = 1; j < is; j++) {
    12417                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12418                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12419                                                        ox = (short) toLong(Math.max(iax, ibx));
    12420                                                        oai16data[it.oIndex + j] = ox;
    12421                                                }
    12422                                        }
    12423                                }
    12424                        }
    12425                        break;
    12426                case Dataset.ARRAYINT64:
    12427                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    12428                        if (is == 1) {
    12429                                if (it.isOutputDouble()) {
    12430                                        while (it.hasNext()) {
    12431                                                final double iax = it.aDouble;
    12432                                                final double ibx = it.bDouble;
    12433                                                long ox;
    12434                                                ox = toLong(Math.max(iax, ibx));
    12435                                                oai64data[it.oIndex] = ox;
    12436                                        }
    12437                                } else {
    12438                                        while (it.hasNext()) {
    12439                                                final long iax = it.aLong;
    12440                                                final long ibx = it.bLong;
    12441                                                long ox;
    12442                                                ox = toLong(Math.max(iax, ibx));
    12443                                                oai64data[it.oIndex] = ox;
    12444                                        }
    12445                                }
    12446                        } else if (as < bs) {
    12447                                if (it.isOutputDouble()) {
    12448                                        while (it.hasNext()) {
    12449                                                final double iax = it.aDouble;
    12450                                                double ibx = it.bDouble;
    12451                                                long ox;
    12452                                                ox = toLong(Math.max(iax, ibx));
    12453                                                oai64data[it.oIndex] = ox;
    12454                                                for (int j = 1; j < is; j++) {
    12455                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12456                                                        ox = toLong(Math.max(iax, ibx));
    12457                                                        oai64data[it.oIndex + j] = ox;
    12458                                                }
    12459                                        }
    12460                                } else {
    12461                                        while (it.hasNext()) {
    12462                                                final long iax = it.aLong;
    12463                                                long ibx = it.bLong;
    12464                                                long ox;
    12465                                                ox = toLong(Math.max(iax, ibx));
    12466                                                oai64data[it.oIndex] = ox;
    12467                                                for (int j = 1; j < is; j++) {
    12468                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12469                                                        ox = toLong(Math.max(iax, ibx));
    12470                                                        oai64data[it.oIndex + j] = ox;
    12471                                                }
    12472                                        }
    12473                                }
    12474                        } else if (as > bs) {
    12475                                if (it.isOutputDouble()) {
    12476                                        while (it.hasNext()) {
    12477                                                double iax = it.aDouble;
    12478                                                final double ibx = it.bDouble;
    12479                                                long ox;
    12480                                                ox = toLong(Math.max(iax, ibx));
    12481                                                oai64data[it.oIndex] = ox;
    12482                                                for (int j = 1; j < is; j++) {
    12483                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12484                                                        ox = toLong(Math.max(iax, ibx));
    12485                                                        oai64data[it.oIndex + j] = ox;
    12486                                                }
    12487                                        }
    12488                                } else {
    12489                                        while (it.hasNext()) {
    12490                                                long iax = it.aLong;
    12491                                                final long ibx = it.bLong;
    12492                                                long ox;
    12493                                                ox = toLong(Math.max(iax, ibx));
    12494                                                oai64data[it.oIndex] = ox;
    12495                                                for (int j = 1; j < is; j++) {
    12496                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12497                                                        ox = toLong(Math.max(iax, ibx));
    12498                                                        oai64data[it.oIndex + j] = ox;
    12499                                                }
    12500                                        }
    12501                                }
    12502                        } else if (as == 1) {
    12503                                if (it.isOutputDouble()) {
    12504                                        while (it.hasNext()) {
    12505                                                final double iax = it.aDouble;
    12506                                                final double ibx = it.bDouble;
    12507                                                long ox;
    12508                                                ox = toLong(Math.max(iax, ibx));
    12509                                                for (int j = 0; j < is; j++) {
    12510                                                        oai64data[it.oIndex + j] = ox;
    12511                                                }
    12512                                        }
    12513                                } else {
    12514                                        while (it.hasNext()) {
    12515                                                final long iax = it.aLong;
    12516                                                final long ibx = it.bLong;
    12517                                                long ox;
    12518                                                ox = toLong(Math.max(iax, ibx));
    12519                                                for (int j = 0; j < is; j++) {
    12520                                                        oai64data[it.oIndex + j] = ox;
    12521                                                }
    12522                                        }
    12523                                }
    12524                        } else {
    12525                                if (it.isOutputDouble()) {
    12526                                        while (it.hasNext()) {
    12527                                                double iax = it.aDouble;
    12528                                                double ibx = it.bDouble;
    12529                                                long ox;
    12530                                                ox = toLong(Math.max(iax, ibx));
    12531                                                oai64data[it.oIndex] = ox;
    12532                                                for (int j = 1; j < is; j++) {
    12533                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12534                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12535                                                        ox = toLong(Math.max(iax, ibx));
    12536                                                        oai64data[it.oIndex + j] = ox;
    12537                                                }
    12538                                        }
    12539                                } else {
    12540                                        while (it.hasNext()) {
    12541                                                long iax = it.aLong;
    12542                                                long ibx = it.bLong;
    12543                                                long ox;
    12544                                                ox = toLong(Math.max(iax, ibx));
    12545                                                oai64data[it.oIndex] = ox;
    12546                                                for (int j = 1; j < is; j++) {
    12547                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12548                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12549                                                        ox = toLong(Math.max(iax, ibx));
    12550                                                        oai64data[it.oIndex + j] = ox;
    12551                                                }
    12552                                        }
    12553                                }
    12554                        }
    12555                        break;
    12556                case Dataset.ARRAYINT32:
    12557                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    12558                        if (is == 1) {
    12559                                if (it.isOutputDouble()) {
    12560                                        while (it.hasNext()) {
    12561                                                final double iax = it.aDouble;
    12562                                                final double ibx = it.bDouble;
    12563                                                int ox;
    12564                                                ox = (int) toLong(Math.max(iax, ibx));
    12565                                                oai32data[it.oIndex] = ox;
    12566                                        }
    12567                                } else {
    12568                                        while (it.hasNext()) {
    12569                                                final long iax = it.aLong;
    12570                                                final long ibx = it.bLong;
    12571                                                int ox;
    12572                                                ox = (int) toLong(Math.max(iax, ibx));
    12573                                                oai32data[it.oIndex] = ox;
    12574                                        }
    12575                                }
    12576                        } else if (as < bs) {
    12577                                if (it.isOutputDouble()) {
    12578                                        while (it.hasNext()) {
    12579                                                final double iax = it.aDouble;
    12580                                                double ibx = it.bDouble;
    12581                                                int ox;
    12582                                                ox = (int) toLong(Math.max(iax, ibx));
    12583                                                oai32data[it.oIndex] = ox;
    12584                                                for (int j = 1; j < is; j++) {
    12585                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12586                                                        ox = (int) toLong(Math.max(iax, ibx));
    12587                                                        oai32data[it.oIndex + j] = ox;
    12588                                                }
    12589                                        }
    12590                                } else {
    12591                                        while (it.hasNext()) {
    12592                                                final long iax = it.aLong;
    12593                                                long ibx = it.bLong;
    12594                                                int ox;
    12595                                                ox = (int) toLong(Math.max(iax, ibx));
    12596                                                oai32data[it.oIndex] = ox;
    12597                                                for (int j = 1; j < is; j++) {
    12598                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12599                                                        ox = (int) toLong(Math.max(iax, ibx));
    12600                                                        oai32data[it.oIndex + j] = ox;
    12601                                                }
    12602                                        }
    12603                                }
    12604                        } else if (as > bs) {
    12605                                if (it.isOutputDouble()) {
    12606                                        while (it.hasNext()) {
    12607                                                double iax = it.aDouble;
    12608                                                final double ibx = it.bDouble;
    12609                                                int ox;
    12610                                                ox = (int) toLong(Math.max(iax, ibx));
    12611                                                oai32data[it.oIndex] = ox;
    12612                                                for (int j = 1; j < is; j++) {
    12613                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12614                                                        ox = (int) toLong(Math.max(iax, ibx));
    12615                                                        oai32data[it.oIndex + j] = ox;
    12616                                                }
    12617                                        }
    12618                                } else {
    12619                                        while (it.hasNext()) {
    12620                                                long iax = it.aLong;
    12621                                                final long ibx = it.bLong;
    12622                                                int ox;
    12623                                                ox = (int) toLong(Math.max(iax, ibx));
    12624                                                oai32data[it.oIndex] = ox;
    12625                                                for (int j = 1; j < is; j++) {
    12626                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12627                                                        ox = (int) toLong(Math.max(iax, ibx));
    12628                                                        oai32data[it.oIndex + j] = ox;
    12629                                                }
    12630                                        }
    12631                                }
    12632                        } else if (as == 1) {
    12633                                if (it.isOutputDouble()) {
    12634                                        while (it.hasNext()) {
    12635                                                final double iax = it.aDouble;
    12636                                                final double ibx = it.bDouble;
    12637                                                int ox;
    12638                                                ox = (int) toLong(Math.max(iax, ibx));
    12639                                                for (int j = 0; j < is; j++) {
    12640                                                        oai32data[it.oIndex + j] = ox;
    12641                                                }
    12642                                        }
    12643                                } else {
    12644                                        while (it.hasNext()) {
    12645                                                final long iax = it.aLong;
    12646                                                final long ibx = it.bLong;
    12647                                                int ox;
    12648                                                ox = (int) toLong(Math.max(iax, ibx));
    12649                                                for (int j = 0; j < is; j++) {
    12650                                                        oai32data[it.oIndex + j] = ox;
    12651                                                }
    12652                                        }
    12653                                }
    12654                        } else {
    12655                                if (it.isOutputDouble()) {
    12656                                        while (it.hasNext()) {
    12657                                                double iax = it.aDouble;
    12658                                                double ibx = it.bDouble;
    12659                                                int ox;
    12660                                                ox = (int) toLong(Math.max(iax, ibx));
    12661                                                oai32data[it.oIndex] = ox;
    12662                                                for (int j = 1; j < is; j++) {
    12663                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12664                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12665                                                        ox = (int) toLong(Math.max(iax, ibx));
    12666                                                        oai32data[it.oIndex + j] = ox;
    12667                                                }
    12668                                        }
    12669                                } else {
    12670                                        while (it.hasNext()) {
    12671                                                long iax = it.aLong;
    12672                                                long ibx = it.bLong;
    12673                                                int ox;
    12674                                                ox = (int) toLong(Math.max(iax, ibx));
    12675                                                oai32data[it.oIndex] = ox;
    12676                                                for (int j = 1; j < is; j++) {
    12677                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12678                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12679                                                        ox = (int) toLong(Math.max(iax, ibx));
    12680                                                        oai32data[it.oIndex + j] = ox;
    12681                                                }
    12682                                        }
    12683                                }
    12684                        }
    12685                        break;
    12686                case Dataset.FLOAT32:
    12687                        final float[] of32data = ((FloatDataset) result).getData();
    12688                        if (it.isOutputDouble()) {
    12689                                while (it.hasNext()) {
    12690                                        final double iax = it.aDouble;
    12691                                        final double ibx = it.bDouble;
    12692                                        float ox;
    12693                                        ox = (float) (Math.max(iax, ibx));
    12694                                        of32data[it.oIndex] = ox;
    12695                                }
    12696                        } else {
    12697                                while (it.hasNext()) {
    12698                                        final long iax = it.aLong;
    12699                                        final long ibx = it.bLong;
    12700                                        float ox;
    12701                                        ox = (float) (Math.max(iax, ibx));
    12702                                        of32data[it.oIndex] = ox;
    12703                                }
    12704                        }
    12705                        break;
    12706                case Dataset.FLOAT64:
    12707                        final double[] of64data = ((DoubleDataset) result).getData();
    12708                        if (it.isOutputDouble()) {
    12709                                while (it.hasNext()) {
    12710                                        final double iax = it.aDouble;
    12711                                        final double ibx = it.bDouble;
    12712                                        double ox;
    12713                                        ox = (Math.max(iax, ibx));
    12714                                        of64data[it.oIndex] = ox;
    12715                                }
    12716                        } else {
    12717                                while (it.hasNext()) {
    12718                                        final long iax = it.aLong;
    12719                                        final long ibx = it.bLong;
    12720                                        double ox;
    12721                                        ox = (Math.max(iax, ibx));
    12722                                        of64data[it.oIndex] = ox;
    12723                                }
    12724                        }
    12725                        break;
    12726                case Dataset.ARRAYFLOAT32:
    12727                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    12728                        if (is == 1) {
    12729                                if (it.isOutputDouble()) {
    12730                                        while (it.hasNext()) {
    12731                                                final double iax = it.aDouble;
    12732                                                final double ibx = it.bDouble;
    12733                                                float ox;
    12734                                                ox = (float) (Math.max(iax, ibx));
    12735                                                oaf32data[it.oIndex] = ox;
    12736                                        }
    12737                                } else {
    12738                                        while (it.hasNext()) {
    12739                                                final long iax = it.aLong;
    12740                                                final long ibx = it.bLong;
    12741                                                float ox;
    12742                                                ox = (float) (Math.max(iax, ibx));
    12743                                                oaf32data[it.oIndex] = ox;
    12744                                        }
    12745                                }
    12746                        } else if (as < bs) {
    12747                                if (it.isOutputDouble()) {
    12748                                        while (it.hasNext()) {
    12749                                                final double iax = it.aDouble;
    12750                                                double ibx = it.bDouble;
    12751                                                float ox;
    12752                                                ox = (float) (Math.max(iax, ibx));
    12753                                                oaf32data[it.oIndex] = ox;
    12754                                                for (int j = 1; j < is; j++) {
    12755                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12756                                                        ox = (float) (Math.max(iax, ibx));
    12757                                                        oaf32data[it.oIndex + j] = ox;
    12758                                                }
    12759                                        }
    12760                                } else {
    12761                                        while (it.hasNext()) {
    12762                                                final long iax = it.aLong;
    12763                                                long ibx = it.bLong;
    12764                                                float ox;
    12765                                                ox = (float) (Math.max(iax, ibx));
    12766                                                oaf32data[it.oIndex] = ox;
    12767                                                for (int j = 1; j < is; j++) {
    12768                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12769                                                        ox = (float) (Math.max(iax, ibx));
    12770                                                        oaf32data[it.oIndex + j] = ox;
    12771                                                }
    12772                                        }
    12773                                }
    12774                        } else if (as > bs) {
    12775                                if (it.isOutputDouble()) {
    12776                                        while (it.hasNext()) {
    12777                                                double iax = it.aDouble;
    12778                                                final double ibx = it.bDouble;
    12779                                                float ox;
    12780                                                ox = (float) (Math.max(iax, ibx));
    12781                                                oaf32data[it.oIndex] = ox;
    12782                                                for (int j = 1; j < is; j++) {
    12783                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12784                                                        ox = (float) (Math.max(iax, ibx));
    12785                                                        oaf32data[it.oIndex + j] = ox;
    12786                                                }
    12787                                        }
    12788                                } else {
    12789                                        while (it.hasNext()) {
    12790                                                long iax = it.aLong;
    12791                                                final long ibx = it.bLong;
    12792                                                float ox;
    12793                                                ox = (float) (Math.max(iax, ibx));
    12794                                                oaf32data[it.oIndex] = ox;
    12795                                                for (int j = 1; j < is; j++) {
    12796                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12797                                                        ox = (float) (Math.max(iax, ibx));
    12798                                                        oaf32data[it.oIndex + j] = ox;
    12799                                                }
    12800                                        }
    12801                                }
    12802                        } else if (as == 1) {
    12803                                if (it.isOutputDouble()) {
    12804                                        while (it.hasNext()) {
    12805                                                final double iax = it.aDouble;
    12806                                                final double ibx = it.bDouble;
    12807                                                float ox;
    12808                                                ox = (float) (Math.max(iax, ibx));
    12809                                                for (int j = 0; j < is; j++) {
    12810                                                        oaf32data[it.oIndex + j] = ox;
    12811                                                }
    12812                                        }
    12813                                } else {
    12814                                        while (it.hasNext()) {
    12815                                                final long iax = it.aLong;
    12816                                                final long ibx = it.bLong;
    12817                                                float ox;
    12818                                                ox = (float) (Math.max(iax, ibx));
    12819                                                for (int j = 0; j < is; j++) {
    12820                                                        oaf32data[it.oIndex + j] = ox;
    12821                                                }
    12822                                        }
    12823                                }
    12824                        } else {
    12825                                if (it.isOutputDouble()) {
    12826                                        while (it.hasNext()) {
    12827                                                double iax = it.aDouble;
    12828                                                double ibx = it.bDouble;
    12829                                                float ox;
    12830                                                ox = (float) (Math.max(iax, ibx));
    12831                                                oaf32data[it.oIndex] = ox;
    12832                                                for (int j = 1; j < is; j++) {
    12833                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12834                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12835                                                        ox = (float) (Math.max(iax, ibx));
    12836                                                        oaf32data[it.oIndex + j] = ox;
    12837                                                }
    12838                                        }
    12839                                } else {
    12840                                        while (it.hasNext()) {
    12841                                                long iax = it.aLong;
    12842                                                long ibx = it.bLong;
    12843                                                float ox;
    12844                                                ox = (float) (Math.max(iax, ibx));
    12845                                                oaf32data[it.oIndex] = ox;
    12846                                                for (int j = 1; j < is; j++) {
    12847                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12848                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12849                                                        ox = (float) (Math.max(iax, ibx));
    12850                                                        oaf32data[it.oIndex + j] = ox;
    12851                                                }
    12852                                        }
    12853                                }
    12854                        }
    12855                        break;
    12856                case Dataset.ARRAYFLOAT64:
    12857                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    12858                        if (is == 1) {
    12859                                if (it.isOutputDouble()) {
    12860                                        while (it.hasNext()) {
    12861                                                final double iax = it.aDouble;
    12862                                                final double ibx = it.bDouble;
    12863                                                double ox;
    12864                                                ox = (Math.max(iax, ibx));
    12865                                                oaf64data[it.oIndex] = ox;
    12866                                        }
    12867                                } else {
    12868                                        while (it.hasNext()) {
    12869                                                final long iax = it.aLong;
    12870                                                final long ibx = it.bLong;
    12871                                                double ox;
    12872                                                ox = (Math.max(iax, ibx));
    12873                                                oaf64data[it.oIndex] = ox;
    12874                                        }
    12875                                }
    12876                        } else if (as < bs) {
    12877                                if (it.isOutputDouble()) {
    12878                                        while (it.hasNext()) {
    12879                                                final double iax = it.aDouble;
    12880                                                double ibx = it.bDouble;
    12881                                                double ox;
    12882                                                ox = (Math.max(iax, ibx));
    12883                                                oaf64data[it.oIndex] = ox;
    12884                                                for (int j = 1; j < is; j++) {
    12885                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12886                                                        ox = (Math.max(iax, ibx));
    12887                                                        oaf64data[it.oIndex + j] = ox;
    12888                                                }
    12889                                        }
    12890                                } else {
    12891                                        while (it.hasNext()) {
    12892                                                final long iax = it.aLong;
    12893                                                long ibx = it.bLong;
    12894                                                double ox;
    12895                                                ox = (Math.max(iax, ibx));
    12896                                                oaf64data[it.oIndex] = ox;
    12897                                                for (int j = 1; j < is; j++) {
    12898                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12899                                                        ox = (Math.max(iax, ibx));
    12900                                                        oaf64data[it.oIndex + j] = ox;
    12901                                                }
    12902                                        }
    12903                                }
    12904                        } else if (as > bs) {
    12905                                if (it.isOutputDouble()) {
    12906                                        while (it.hasNext()) {
    12907                                                double iax = it.aDouble;
    12908                                                final double ibx = it.bDouble;
    12909                                                double ox;
    12910                                                ox = (Math.max(iax, ibx));
    12911                                                oaf64data[it.oIndex] = ox;
    12912                                                for (int j = 1; j < is; j++) {
    12913                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12914                                                        ox = (Math.max(iax, ibx));
    12915                                                        oaf64data[it.oIndex + j] = ox;
    12916                                                }
    12917                                        }
    12918                                } else {
    12919                                        while (it.hasNext()) {
    12920                                                long iax = it.aLong;
    12921                                                final long ibx = it.bLong;
    12922                                                double ox;
    12923                                                ox = (Math.max(iax, ibx));
    12924                                                oaf64data[it.oIndex] = ox;
    12925                                                for (int j = 1; j < is; j++) {
    12926                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12927                                                        ox = (Math.max(iax, ibx));
    12928                                                        oaf64data[it.oIndex + j] = ox;
    12929                                                }
    12930                                        }
    12931                                }
    12932                        } else if (as == 1) {
    12933                                if (it.isOutputDouble()) {
    12934                                        while (it.hasNext()) {
    12935                                                final double iax = it.aDouble;
    12936                                                final double ibx = it.bDouble;
    12937                                                double ox;
    12938                                                ox = (Math.max(iax, ibx));
    12939                                                for (int j = 0; j < is; j++) {
    12940                                                        oaf64data[it.oIndex + j] = ox;
    12941                                                }
    12942                                        }
    12943                                } else {
    12944                                        while (it.hasNext()) {
    12945                                                final long iax = it.aLong;
    12946                                                final long ibx = it.bLong;
    12947                                                double ox;
    12948                                                ox = (Math.max(iax, ibx));
    12949                                                for (int j = 0; j < is; j++) {
    12950                                                        oaf64data[it.oIndex + j] = ox;
    12951                                                }
    12952                                        }
    12953                                }
    12954                        } else {
    12955                                if (it.isOutputDouble()) {
    12956                                        while (it.hasNext()) {
    12957                                                double iax = it.aDouble;
    12958                                                double ibx = it.bDouble;
    12959                                                double ox;
    12960                                                ox = (Math.max(iax, ibx));
    12961                                                oaf64data[it.oIndex] = ox;
    12962                                                for (int j = 1; j < is; j++) {
    12963                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    12964                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    12965                                                        ox = (Math.max(iax, ibx));
    12966                                                        oaf64data[it.oIndex + j] = ox;
    12967                                                }
    12968                                        }
    12969                                } else {
    12970                                        while (it.hasNext()) {
    12971                                                long iax = it.aLong;
    12972                                                long ibx = it.bLong;
    12973                                                double ox;
    12974                                                ox = (Math.max(iax, ibx));
    12975                                                oaf64data[it.oIndex] = ox;
    12976                                                for (int j = 1; j < is; j++) {
    12977                                                        iax = da.getElementLongAbs(it.aIndex + j);
    12978                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    12979                                                        ox = (Math.max(iax, ibx));
    12980                                                        oaf64data[it.oIndex + j] = ox;
    12981                                                }
    12982                                        }
    12983                                }
    12984                        }
    12985                        break;
    12986                case Dataset.COMPLEX64:
    12987                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    12988                        if (as == 1) {
    12989                                final double iay = 0;
    12990                                while (it.hasNext()) {
    12991                                        final double iax = it.aDouble;
    12992                                        final double ibx = it.bDouble;
    12993                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    12994                                        float ox;
    12995                                        float oy;
    12996                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    12997                                                ox = (float) (iax);
    12998                                                oy = (float) (iay);
    12999                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    13000                                                ox = (float) (ibx);
    13001                                                oy = (float) (iby);
    13002                                        } else {
    13003                                                ox = (float) (Math.max(iax, ibx));
    13004                                                oy = (float) (Math.max(iay, iby));
    13005                                        }
    13006                                        oc64data[it.oIndex] = ox;
    13007                                        oc64data[it.oIndex + 1] = oy;
    13008                                }
    13009                        } else if (bs == 1) {
    13010                                final double iby = 0;
    13011                                while (it.hasNext()) {
    13012                                        final double iax = it.aDouble;
    13013                                        final double ibx = it.bDouble;
    13014                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    13015                                        float ox;
    13016                                        float oy;
    13017                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    13018                                                ox = (float) (iax);
    13019                                                oy = (float) (iay);
    13020                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    13021                                                ox = (float) (ibx);
    13022                                                oy = (float) (iby);
    13023                                        } else {
    13024                                                ox = (float) (Math.max(iax, ibx));
    13025                                                oy = (float) (Math.max(iay, iby));
    13026                                        }
    13027                                        oc64data[it.oIndex] = ox;
    13028                                        oc64data[it.oIndex + 1] = oy;
    13029                                }
    13030                        } else {
    13031                                while (it.hasNext()) {
    13032                                        final double iax = it.aDouble;
    13033                                        final double ibx = it.bDouble;
    13034                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    13035                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    13036                                        float ox;
    13037                                        float oy;
    13038                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    13039                                                ox = (float) (iax);
    13040                                                oy = (float) (iay);
    13041                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    13042                                                ox = (float) (ibx);
    13043                                                oy = (float) (iby);
    13044                                        } else {
    13045                                                ox = (float) (Math.max(iax, ibx));
    13046                                                oy = (float) (Math.max(iay, iby));
    13047                                        }
    13048                                        oc64data[it.oIndex] = ox;
    13049                                        oc64data[it.oIndex + 1] = oy;
    13050                                }
    13051                        }
    13052                        break;
    13053                case Dataset.COMPLEX128:
    13054                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    13055                        if (as == 1) {
    13056                                final double iay = 0;
    13057                                while (it.hasNext()) {
    13058                                        final double iax = it.aDouble;
    13059                                        final double ibx = it.bDouble;
    13060                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    13061                                        double ox;
    13062                                        double oy;
    13063                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    13064                                                ox = (iax);
    13065                                                oy = (iay);
    13066                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    13067                                                ox = (ibx);
    13068                                                oy = (iby);
    13069                                        } else {
    13070                                                ox = (Math.max(iax, ibx));
    13071                                                oy = (Math.max(iay, iby));
    13072                                        }
    13073                                        oc128data[it.oIndex] = ox;
    13074                                        oc128data[it.oIndex + 1] = oy;
    13075                                }
    13076                        } else if (bs == 1) {
    13077                                final double iby = 0;
    13078                                while (it.hasNext()) {
    13079                                        final double iax = it.aDouble;
    13080                                        final double ibx = it.bDouble;
    13081                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    13082                                        double ox;
    13083                                        double oy;
    13084                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    13085                                                ox = (iax);
    13086                                                oy = (iay);
    13087                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    13088                                                ox = (ibx);
    13089                                                oy = (iby);
    13090                                        } else {
    13091                                                ox = (Math.max(iax, ibx));
    13092                                                oy = (Math.max(iay, iby));
    13093                                        }
    13094                                        oc128data[it.oIndex] = ox;
    13095                                        oc128data[it.oIndex + 1] = oy;
    13096                                }
    13097                        } else {
    13098                                while (it.hasNext()) {
    13099                                        final double iax = it.aDouble;
    13100                                        final double ibx = it.bDouble;
    13101                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    13102                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    13103                                        double ox;
    13104                                        double oy;
    13105                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    13106                                                ox = (iax);
    13107                                                oy = (iay);
    13108                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    13109                                                ox = (ibx);
    13110                                                oy = (iby);
    13111                                        } else {
    13112                                                ox = (Math.max(iax, ibx));
    13113                                                oy = (Math.max(iay, iby));
    13114                                        }
    13115                                        oc128data[it.oIndex] = ox;
    13116                                        oc128data[it.oIndex + 1] = oy;
    13117                                }
    13118                        }
    13119                        break;
    13120                default:
    13121                        throw new IllegalArgumentException("maximum supports integer, compound integer, real, compound real, complex datasets only");
    13122                }
    13123
    13124                addBinaryOperatorName(da, db, result, "maximum");
    13125                return result;
    13126        }
    13127
    13128        /**
    13129         * minimum operator
    13130         * @param a
    13131         * @param b
    13132         * @return return minimum of a and b
    13133         */
    13134        public static Dataset minimum(final Object a, final Object b) {
    13135                return minimum(a, b, null);
    13136        }
    13137
    13138        /**
    13139         * minimum operator
    13140         * @param a
    13141         * @param b
    13142         * @param o output can be null - in which case, a new dataset is created
    13143         * @return return minimum of a and b
    13144         */
    13145        public static Dataset minimum(final Object a, final Object b, final Dataset o) {
    13146                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    13147                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    13148                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    13149                final Dataset result = it.getOutput();
    13150                final int is = result.getElementsPerItem();
    13151                final int as = da.getElementsPerItem();
    13152                final int bs = db.getElementsPerItem();
    13153                final int dt = result.getDType();
    13154
    13155                switch(dt) {
    13156                case Dataset.INT8:
    13157                        final byte[] oi8data = ((ByteDataset) result).getData();
    13158                        if (it.isOutputDouble()) {
    13159                                while (it.hasNext()) {
    13160                                        final double iax = it.aDouble;
    13161                                        final double ibx = it.bDouble;
    13162                                        byte ox;
    13163                                        ox = (byte) toLong(Math.min(iax, ibx));
    13164                                        oi8data[it.oIndex] = ox;
    13165                                }
    13166                        } else {
    13167                                while (it.hasNext()) {
    13168                                        final long iax = it.aLong;
    13169                                        final long ibx = it.bLong;
    13170                                        byte ox;
    13171                                        ox = (byte) toLong(Math.min(iax, ibx));
    13172                                        oi8data[it.oIndex] = ox;
    13173                                }
    13174                        }
    13175                        break;
    13176                case Dataset.INT16:
    13177                        final short[] oi16data = ((ShortDataset) result).getData();
    13178                        if (it.isOutputDouble()) {
    13179                                while (it.hasNext()) {
    13180                                        final double iax = it.aDouble;
    13181                                        final double ibx = it.bDouble;
    13182                                        short ox;
    13183                                        ox = (short) toLong(Math.min(iax, ibx));
    13184                                        oi16data[it.oIndex] = ox;
    13185                                }
    13186                        } else {
    13187                                while (it.hasNext()) {
    13188                                        final long iax = it.aLong;
    13189                                        final long ibx = it.bLong;
    13190                                        short ox;
    13191                                        ox = (short) toLong(Math.min(iax, ibx));
    13192                                        oi16data[it.oIndex] = ox;
    13193                                }
    13194                        }
    13195                        break;
    13196                case Dataset.INT64:
    13197                        final long[] oi64data = ((LongDataset) result).getData();
    13198                        if (it.isOutputDouble()) {
    13199                                while (it.hasNext()) {
    13200                                        final double iax = it.aDouble;
    13201                                        final double ibx = it.bDouble;
    13202                                        long ox;
    13203                                        ox = toLong(Math.min(iax, ibx));
    13204                                        oi64data[it.oIndex] = ox;
    13205                                }
    13206                        } else {
    13207                                while (it.hasNext()) {
    13208                                        final long iax = it.aLong;
    13209                                        final long ibx = it.bLong;
    13210                                        long ox;
    13211                                        ox = toLong(Math.min(iax, ibx));
    13212                                        oi64data[it.oIndex] = ox;
    13213                                }
    13214                        }
    13215                        break;
    13216                case Dataset.INT32:
    13217                        final int[] oi32data = ((IntegerDataset) result).getData();
    13218                        if (it.isOutputDouble()) {
    13219                                while (it.hasNext()) {
    13220                                        final double iax = it.aDouble;
    13221                                        final double ibx = it.bDouble;
    13222                                        int ox;
    13223                                        ox = (int) toLong(Math.min(iax, ibx));
    13224                                        oi32data[it.oIndex] = ox;
    13225                                }
    13226                        } else {
    13227                                while (it.hasNext()) {
    13228                                        final long iax = it.aLong;
    13229                                        final long ibx = it.bLong;
    13230                                        int ox;
    13231                                        ox = (int) toLong(Math.min(iax, ibx));
    13232                                        oi32data[it.oIndex] = ox;
    13233                                }
    13234                        }
    13235                        break;
    13236                case Dataset.ARRAYINT8:
    13237                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    13238                        if (is == 1) {
    13239                                if (it.isOutputDouble()) {
    13240                                        while (it.hasNext()) {
    13241                                                final double iax = it.aDouble;
    13242                                                final double ibx = it.bDouble;
    13243                                                byte ox;
    13244                                                ox = (byte) toLong(Math.min(iax, ibx));
    13245                                                oai8data[it.oIndex] = ox;
    13246                                        }
    13247                                } else {
    13248                                        while (it.hasNext()) {
    13249                                                final long iax = it.aLong;
    13250                                                final long ibx = it.bLong;
    13251                                                byte ox;
    13252                                                ox = (byte) toLong(Math.min(iax, ibx));
    13253                                                oai8data[it.oIndex] = ox;
    13254                                        }
    13255                                }
    13256                        } else if (as < bs) {
    13257                                if (it.isOutputDouble()) {
    13258                                        while (it.hasNext()) {
    13259                                                final double iax = it.aDouble;
    13260                                                double ibx = it.bDouble;
    13261                                                byte ox;
    13262                                                ox = (byte) toLong(Math.min(iax, ibx));
    13263                                                oai8data[it.oIndex] = ox;
    13264                                                for (int j = 1; j < is; j++) {
    13265                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13266                                                        ox = (byte) toLong(Math.min(iax, ibx));
    13267                                                        oai8data[it.oIndex + j] = ox;
    13268                                                }
    13269                                        }
    13270                                } else {
    13271                                        while (it.hasNext()) {
    13272                                                final long iax = it.aLong;
    13273                                                long ibx = it.bLong;
    13274                                                byte ox;
    13275                                                ox = (byte) toLong(Math.min(iax, ibx));
    13276                                                oai8data[it.oIndex] = ox;
    13277                                                for (int j = 1; j < is; j++) {
    13278                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13279                                                        ox = (byte) toLong(Math.min(iax, ibx));
    13280                                                        oai8data[it.oIndex + j] = ox;
    13281                                                }
    13282                                        }
    13283                                }
    13284                        } else if (as > bs) {
    13285                                if (it.isOutputDouble()) {
    13286                                        while (it.hasNext()) {
    13287                                                double iax = it.aDouble;
    13288                                                final double ibx = it.bDouble;
    13289                                                byte ox;
    13290                                                ox = (byte) toLong(Math.min(iax, ibx));
    13291                                                oai8data[it.oIndex] = ox;
    13292                                                for (int j = 1; j < is; j++) {
    13293                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13294                                                        ox = (byte) toLong(Math.min(iax, ibx));
    13295                                                        oai8data[it.oIndex + j] = ox;
    13296                                                }
    13297                                        }
    13298                                } else {
    13299                                        while (it.hasNext()) {
    13300                                                long iax = it.aLong;
    13301                                                final long ibx = it.bLong;
    13302                                                byte ox;
    13303                                                ox = (byte) toLong(Math.min(iax, ibx));
    13304                                                oai8data[it.oIndex] = ox;
    13305                                                for (int j = 1; j < is; j++) {
    13306                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13307                                                        ox = (byte) toLong(Math.min(iax, ibx));
    13308                                                        oai8data[it.oIndex + j] = ox;
    13309                                                }
    13310                                        }
    13311                                }
    13312                        } else if (as == 1) {
    13313                                if (it.isOutputDouble()) {
    13314                                        while (it.hasNext()) {
    13315                                                final double iax = it.aDouble;
    13316                                                final double ibx = it.bDouble;
    13317                                                byte ox;
    13318                                                ox = (byte) toLong(Math.min(iax, ibx));
    13319                                                for (int j = 0; j < is; j++) {
    13320                                                        oai8data[it.oIndex + j] = ox;
    13321                                                }
    13322                                        }
    13323                                } else {
    13324                                        while (it.hasNext()) {
    13325                                                final long iax = it.aLong;
    13326                                                final long ibx = it.bLong;
    13327                                                byte ox;
    13328                                                ox = (byte) toLong(Math.min(iax, ibx));
    13329                                                for (int j = 0; j < is; j++) {
    13330                                                        oai8data[it.oIndex + j] = ox;
    13331                                                }
    13332                                        }
    13333                                }
    13334                        } else {
    13335                                if (it.isOutputDouble()) {
    13336                                        while (it.hasNext()) {
    13337                                                double iax = it.aDouble;
    13338                                                double ibx = it.bDouble;
    13339                                                byte ox;
    13340                                                ox = (byte) toLong(Math.min(iax, ibx));
    13341                                                oai8data[it.oIndex] = ox;
    13342                                                for (int j = 1; j < is; j++) {
    13343                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13344                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13345                                                        ox = (byte) toLong(Math.min(iax, ibx));
    13346                                                        oai8data[it.oIndex + j] = ox;
    13347                                                }
    13348                                        }
    13349                                } else {
    13350                                        while (it.hasNext()) {
    13351                                                long iax = it.aLong;
    13352                                                long ibx = it.bLong;
    13353                                                byte ox;
    13354                                                ox = (byte) toLong(Math.min(iax, ibx));
    13355                                                oai8data[it.oIndex] = ox;
    13356                                                for (int j = 1; j < is; j++) {
    13357                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13358                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13359                                                        ox = (byte) toLong(Math.min(iax, ibx));
    13360                                                        oai8data[it.oIndex + j] = ox;
    13361                                                }
    13362                                        }
    13363                                }
    13364                        }
    13365                        break;
    13366                case Dataset.ARRAYINT16:
    13367                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    13368                        if (is == 1) {
    13369                                if (it.isOutputDouble()) {
    13370                                        while (it.hasNext()) {
    13371                                                final double iax = it.aDouble;
    13372                                                final double ibx = it.bDouble;
    13373                                                short ox;
    13374                                                ox = (short) toLong(Math.min(iax, ibx));
    13375                                                oai16data[it.oIndex] = ox;
    13376                                        }
    13377                                } else {
    13378                                        while (it.hasNext()) {
    13379                                                final long iax = it.aLong;
    13380                                                final long ibx = it.bLong;
    13381                                                short ox;
    13382                                                ox = (short) toLong(Math.min(iax, ibx));
    13383                                                oai16data[it.oIndex] = ox;
    13384                                        }
    13385                                }
    13386                        } else if (as < bs) {
    13387                                if (it.isOutputDouble()) {
    13388                                        while (it.hasNext()) {
    13389                                                final double iax = it.aDouble;
    13390                                                double ibx = it.bDouble;
    13391                                                short ox;
    13392                                                ox = (short) toLong(Math.min(iax, ibx));
    13393                                                oai16data[it.oIndex] = ox;
    13394                                                for (int j = 1; j < is; j++) {
    13395                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13396                                                        ox = (short) toLong(Math.min(iax, ibx));
    13397                                                        oai16data[it.oIndex + j] = ox;
    13398                                                }
    13399                                        }
    13400                                } else {
    13401                                        while (it.hasNext()) {
    13402                                                final long iax = it.aLong;
    13403                                                long ibx = it.bLong;
    13404                                                short ox;
    13405                                                ox = (short) toLong(Math.min(iax, ibx));
    13406                                                oai16data[it.oIndex] = ox;
    13407                                                for (int j = 1; j < is; j++) {
    13408                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13409                                                        ox = (short) toLong(Math.min(iax, ibx));
    13410                                                        oai16data[it.oIndex + j] = ox;
    13411                                                }
    13412                                        }
    13413                                }
    13414                        } else if (as > bs) {
    13415                                if (it.isOutputDouble()) {
    13416                                        while (it.hasNext()) {
    13417                                                double iax = it.aDouble;
    13418                                                final double ibx = it.bDouble;
    13419                                                short ox;
    13420                                                ox = (short) toLong(Math.min(iax, ibx));
    13421                                                oai16data[it.oIndex] = ox;
    13422                                                for (int j = 1; j < is; j++) {
    13423                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13424                                                        ox = (short) toLong(Math.min(iax, ibx));
    13425                                                        oai16data[it.oIndex + j] = ox;
    13426                                                }
    13427                                        }
    13428                                } else {
    13429                                        while (it.hasNext()) {
    13430                                                long iax = it.aLong;
    13431                                                final long ibx = it.bLong;
    13432                                                short ox;
    13433                                                ox = (short) toLong(Math.min(iax, ibx));
    13434                                                oai16data[it.oIndex] = ox;
    13435                                                for (int j = 1; j < is; j++) {
    13436                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13437                                                        ox = (short) toLong(Math.min(iax, ibx));
    13438                                                        oai16data[it.oIndex + j] = ox;
    13439                                                }
    13440                                        }
    13441                                }
    13442                        } else if (as == 1) {
    13443                                if (it.isOutputDouble()) {
    13444                                        while (it.hasNext()) {
    13445                                                final double iax = it.aDouble;
    13446                                                final double ibx = it.bDouble;
    13447                                                short ox;
    13448                                                ox = (short) toLong(Math.min(iax, ibx));
    13449                                                for (int j = 0; j < is; j++) {
    13450                                                        oai16data[it.oIndex + j] = ox;
    13451                                                }
    13452                                        }
    13453                                } else {
    13454                                        while (it.hasNext()) {
    13455                                                final long iax = it.aLong;
    13456                                                final long ibx = it.bLong;
    13457                                                short ox;
    13458                                                ox = (short) toLong(Math.min(iax, ibx));
    13459                                                for (int j = 0; j < is; j++) {
    13460                                                        oai16data[it.oIndex + j] = ox;
    13461                                                }
    13462                                        }
    13463                                }
    13464                        } else {
    13465                                if (it.isOutputDouble()) {
    13466                                        while (it.hasNext()) {
    13467                                                double iax = it.aDouble;
    13468                                                double ibx = it.bDouble;
    13469                                                short ox;
    13470                                                ox = (short) toLong(Math.min(iax, ibx));
    13471                                                oai16data[it.oIndex] = ox;
    13472                                                for (int j = 1; j < is; j++) {
    13473                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13474                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13475                                                        ox = (short) toLong(Math.min(iax, ibx));
    13476                                                        oai16data[it.oIndex + j] = ox;
    13477                                                }
    13478                                        }
    13479                                } else {
    13480                                        while (it.hasNext()) {
    13481                                                long iax = it.aLong;
    13482                                                long ibx = it.bLong;
    13483                                                short ox;
    13484                                                ox = (short) toLong(Math.min(iax, ibx));
    13485                                                oai16data[it.oIndex] = ox;
    13486                                                for (int j = 1; j < is; j++) {
    13487                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13488                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13489                                                        ox = (short) toLong(Math.min(iax, ibx));
    13490                                                        oai16data[it.oIndex + j] = ox;
    13491                                                }
    13492                                        }
    13493                                }
    13494                        }
    13495                        break;
    13496                case Dataset.ARRAYINT64:
    13497                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    13498                        if (is == 1) {
    13499                                if (it.isOutputDouble()) {
    13500                                        while (it.hasNext()) {
    13501                                                final double iax = it.aDouble;
    13502                                                final double ibx = it.bDouble;
    13503                                                long ox;
    13504                                                ox = toLong(Math.min(iax, ibx));
    13505                                                oai64data[it.oIndex] = ox;
    13506                                        }
    13507                                } else {
    13508                                        while (it.hasNext()) {
    13509                                                final long iax = it.aLong;
    13510                                                final long ibx = it.bLong;
    13511                                                long ox;
    13512                                                ox = toLong(Math.min(iax, ibx));
    13513                                                oai64data[it.oIndex] = ox;
    13514                                        }
    13515                                }
    13516                        } else if (as < bs) {
    13517                                if (it.isOutputDouble()) {
    13518                                        while (it.hasNext()) {
    13519                                                final double iax = it.aDouble;
    13520                                                double ibx = it.bDouble;
    13521                                                long ox;
    13522                                                ox = toLong(Math.min(iax, ibx));
    13523                                                oai64data[it.oIndex] = ox;
    13524                                                for (int j = 1; j < is; j++) {
    13525                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13526                                                        ox = toLong(Math.min(iax, ibx));
    13527                                                        oai64data[it.oIndex + j] = ox;
    13528                                                }
    13529                                        }
    13530                                } else {
    13531                                        while (it.hasNext()) {
    13532                                                final long iax = it.aLong;
    13533                                                long ibx = it.bLong;
    13534                                                long ox;
    13535                                                ox = toLong(Math.min(iax, ibx));
    13536                                                oai64data[it.oIndex] = ox;
    13537                                                for (int j = 1; j < is; j++) {
    13538                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13539                                                        ox = toLong(Math.min(iax, ibx));
    13540                                                        oai64data[it.oIndex + j] = ox;
    13541                                                }
    13542                                        }
    13543                                }
    13544                        } else if (as > bs) {
    13545                                if (it.isOutputDouble()) {
    13546                                        while (it.hasNext()) {
    13547                                                double iax = it.aDouble;
    13548                                                final double ibx = it.bDouble;
    13549                                                long ox;
    13550                                                ox = toLong(Math.min(iax, ibx));
    13551                                                oai64data[it.oIndex] = ox;
    13552                                                for (int j = 1; j < is; j++) {
    13553                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13554                                                        ox = toLong(Math.min(iax, ibx));
    13555                                                        oai64data[it.oIndex + j] = ox;
    13556                                                }
    13557                                        }
    13558                                } else {
    13559                                        while (it.hasNext()) {
    13560                                                long iax = it.aLong;
    13561                                                final long ibx = it.bLong;
    13562                                                long ox;
    13563                                                ox = toLong(Math.min(iax, ibx));
    13564                                                oai64data[it.oIndex] = ox;
    13565                                                for (int j = 1; j < is; j++) {
    13566                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13567                                                        ox = toLong(Math.min(iax, ibx));
    13568                                                        oai64data[it.oIndex + j] = ox;
    13569                                                }
    13570                                        }
    13571                                }
    13572                        } else if (as == 1) {
    13573                                if (it.isOutputDouble()) {
    13574                                        while (it.hasNext()) {
    13575                                                final double iax = it.aDouble;
    13576                                                final double ibx = it.bDouble;
    13577                                                long ox;
    13578                                                ox = toLong(Math.min(iax, ibx));
    13579                                                for (int j = 0; j < is; j++) {
    13580                                                        oai64data[it.oIndex + j] = ox;
    13581                                                }
    13582                                        }
    13583                                } else {
    13584                                        while (it.hasNext()) {
    13585                                                final long iax = it.aLong;
    13586                                                final long ibx = it.bLong;
    13587                                                long ox;
    13588                                                ox = toLong(Math.min(iax, ibx));
    13589                                                for (int j = 0; j < is; j++) {
    13590                                                        oai64data[it.oIndex + j] = ox;
    13591                                                }
    13592                                        }
    13593                                }
    13594                        } else {
    13595                                if (it.isOutputDouble()) {
    13596                                        while (it.hasNext()) {
    13597                                                double iax = it.aDouble;
    13598                                                double ibx = it.bDouble;
    13599                                                long ox;
    13600                                                ox = toLong(Math.min(iax, ibx));
    13601                                                oai64data[it.oIndex] = ox;
    13602                                                for (int j = 1; j < is; j++) {
    13603                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13604                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13605                                                        ox = toLong(Math.min(iax, ibx));
    13606                                                        oai64data[it.oIndex + j] = ox;
    13607                                                }
    13608                                        }
    13609                                } else {
    13610                                        while (it.hasNext()) {
    13611                                                long iax = it.aLong;
    13612                                                long ibx = it.bLong;
    13613                                                long ox;
    13614                                                ox = toLong(Math.min(iax, ibx));
    13615                                                oai64data[it.oIndex] = ox;
    13616                                                for (int j = 1; j < is; j++) {
    13617                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13618                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13619                                                        ox = toLong(Math.min(iax, ibx));
    13620                                                        oai64data[it.oIndex + j] = ox;
    13621                                                }
    13622                                        }
    13623                                }
    13624                        }
    13625                        break;
    13626                case Dataset.ARRAYINT32:
    13627                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    13628                        if (is == 1) {
    13629                                if (it.isOutputDouble()) {
    13630                                        while (it.hasNext()) {
    13631                                                final double iax = it.aDouble;
    13632                                                final double ibx = it.bDouble;
    13633                                                int ox;
    13634                                                ox = (int) toLong(Math.min(iax, ibx));
    13635                                                oai32data[it.oIndex] = ox;
    13636                                        }
    13637                                } else {
    13638                                        while (it.hasNext()) {
    13639                                                final long iax = it.aLong;
    13640                                                final long ibx = it.bLong;
    13641                                                int ox;
    13642                                                ox = (int) toLong(Math.min(iax, ibx));
    13643                                                oai32data[it.oIndex] = ox;
    13644                                        }
    13645                                }
    13646                        } else if (as < bs) {
    13647                                if (it.isOutputDouble()) {
    13648                                        while (it.hasNext()) {
    13649                                                final double iax = it.aDouble;
    13650                                                double ibx = it.bDouble;
    13651                                                int ox;
    13652                                                ox = (int) toLong(Math.min(iax, ibx));
    13653                                                oai32data[it.oIndex] = ox;
    13654                                                for (int j = 1; j < is; j++) {
    13655                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13656                                                        ox = (int) toLong(Math.min(iax, ibx));
    13657                                                        oai32data[it.oIndex + j] = ox;
    13658                                                }
    13659                                        }
    13660                                } else {
    13661                                        while (it.hasNext()) {
    13662                                                final long iax = it.aLong;
    13663                                                long ibx = it.bLong;
    13664                                                int ox;
    13665                                                ox = (int) toLong(Math.min(iax, ibx));
    13666                                                oai32data[it.oIndex] = ox;
    13667                                                for (int j = 1; j < is; j++) {
    13668                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13669                                                        ox = (int) toLong(Math.min(iax, ibx));
    13670                                                        oai32data[it.oIndex + j] = ox;
    13671                                                }
    13672                                        }
    13673                                }
    13674                        } else if (as > bs) {
    13675                                if (it.isOutputDouble()) {
    13676                                        while (it.hasNext()) {
    13677                                                double iax = it.aDouble;
    13678                                                final double ibx = it.bDouble;
    13679                                                int ox;
    13680                                                ox = (int) toLong(Math.min(iax, ibx));
    13681                                                oai32data[it.oIndex] = ox;
    13682                                                for (int j = 1; j < is; j++) {
    13683                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13684                                                        ox = (int) toLong(Math.min(iax, ibx));
    13685                                                        oai32data[it.oIndex + j] = ox;
    13686                                                }
    13687                                        }
    13688                                } else {
    13689                                        while (it.hasNext()) {
    13690                                                long iax = it.aLong;
    13691                                                final long ibx = it.bLong;
    13692                                                int ox;
    13693                                                ox = (int) toLong(Math.min(iax, ibx));
    13694                                                oai32data[it.oIndex] = ox;
    13695                                                for (int j = 1; j < is; j++) {
    13696                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13697                                                        ox = (int) toLong(Math.min(iax, ibx));
    13698                                                        oai32data[it.oIndex + j] = ox;
    13699                                                }
    13700                                        }
    13701                                }
    13702                        } else if (as == 1) {
    13703                                if (it.isOutputDouble()) {
    13704                                        while (it.hasNext()) {
    13705                                                final double iax = it.aDouble;
    13706                                                final double ibx = it.bDouble;
    13707                                                int ox;
    13708                                                ox = (int) toLong(Math.min(iax, ibx));
    13709                                                for (int j = 0; j < is; j++) {
    13710                                                        oai32data[it.oIndex + j] = ox;
    13711                                                }
    13712                                        }
    13713                                } else {
    13714                                        while (it.hasNext()) {
    13715                                                final long iax = it.aLong;
    13716                                                final long ibx = it.bLong;
    13717                                                int ox;
    13718                                                ox = (int) toLong(Math.min(iax, ibx));
    13719                                                for (int j = 0; j < is; j++) {
    13720                                                        oai32data[it.oIndex + j] = ox;
    13721                                                }
    13722                                        }
    13723                                }
    13724                        } else {
    13725                                if (it.isOutputDouble()) {
    13726                                        while (it.hasNext()) {
    13727                                                double iax = it.aDouble;
    13728                                                double ibx = it.bDouble;
    13729                                                int ox;
    13730                                                ox = (int) toLong(Math.min(iax, ibx));
    13731                                                oai32data[it.oIndex] = ox;
    13732                                                for (int j = 1; j < is; j++) {
    13733                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13734                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13735                                                        ox = (int) toLong(Math.min(iax, ibx));
    13736                                                        oai32data[it.oIndex + j] = ox;
    13737                                                }
    13738                                        }
    13739                                } else {
    13740                                        while (it.hasNext()) {
    13741                                                long iax = it.aLong;
    13742                                                long ibx = it.bLong;
    13743                                                int ox;
    13744                                                ox = (int) toLong(Math.min(iax, ibx));
    13745                                                oai32data[it.oIndex] = ox;
    13746                                                for (int j = 1; j < is; j++) {
    13747                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13748                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13749                                                        ox = (int) toLong(Math.min(iax, ibx));
    13750                                                        oai32data[it.oIndex + j] = ox;
    13751                                                }
    13752                                        }
    13753                                }
    13754                        }
    13755                        break;
    13756                case Dataset.FLOAT32:
    13757                        final float[] of32data = ((FloatDataset) result).getData();
    13758                        if (it.isOutputDouble()) {
    13759                                while (it.hasNext()) {
    13760                                        final double iax = it.aDouble;
    13761                                        final double ibx = it.bDouble;
    13762                                        float ox;
    13763                                        ox = (float) (Math.min(iax, ibx));
    13764                                        of32data[it.oIndex] = ox;
    13765                                }
    13766                        } else {
    13767                                while (it.hasNext()) {
    13768                                        final long iax = it.aLong;
    13769                                        final long ibx = it.bLong;
    13770                                        float ox;
    13771                                        ox = (float) (Math.min(iax, ibx));
    13772                                        of32data[it.oIndex] = ox;
    13773                                }
    13774                        }
    13775                        break;
    13776                case Dataset.FLOAT64:
    13777                        final double[] of64data = ((DoubleDataset) result).getData();
    13778                        if (it.isOutputDouble()) {
    13779                                while (it.hasNext()) {
    13780                                        final double iax = it.aDouble;
    13781                                        final double ibx = it.bDouble;
    13782                                        double ox;
    13783                                        ox = (Math.min(iax, ibx));
    13784                                        of64data[it.oIndex] = ox;
    13785                                }
    13786                        } else {
    13787                                while (it.hasNext()) {
    13788                                        final long iax = it.aLong;
    13789                                        final long ibx = it.bLong;
    13790                                        double ox;
    13791                                        ox = (Math.min(iax, ibx));
    13792                                        of64data[it.oIndex] = ox;
    13793                                }
    13794                        }
    13795                        break;
    13796                case Dataset.ARRAYFLOAT32:
    13797                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    13798                        if (is == 1) {
    13799                                if (it.isOutputDouble()) {
    13800                                        while (it.hasNext()) {
    13801                                                final double iax = it.aDouble;
    13802                                                final double ibx = it.bDouble;
    13803                                                float ox;
    13804                                                ox = (float) (Math.min(iax, ibx));
    13805                                                oaf32data[it.oIndex] = ox;
    13806                                        }
    13807                                } else {
    13808                                        while (it.hasNext()) {
    13809                                                final long iax = it.aLong;
    13810                                                final long ibx = it.bLong;
    13811                                                float ox;
    13812                                                ox = (float) (Math.min(iax, ibx));
    13813                                                oaf32data[it.oIndex] = ox;
    13814                                        }
    13815                                }
    13816                        } else if (as < bs) {
    13817                                if (it.isOutputDouble()) {
    13818                                        while (it.hasNext()) {
    13819                                                final double iax = it.aDouble;
    13820                                                double ibx = it.bDouble;
    13821                                                float ox;
    13822                                                ox = (float) (Math.min(iax, ibx));
    13823                                                oaf32data[it.oIndex] = ox;
    13824                                                for (int j = 1; j < is; j++) {
    13825                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13826                                                        ox = (float) (Math.min(iax, ibx));
    13827                                                        oaf32data[it.oIndex + j] = ox;
    13828                                                }
    13829                                        }
    13830                                } else {
    13831                                        while (it.hasNext()) {
    13832                                                final long iax = it.aLong;
    13833                                                long ibx = it.bLong;
    13834                                                float ox;
    13835                                                ox = (float) (Math.min(iax, ibx));
    13836                                                oaf32data[it.oIndex] = ox;
    13837                                                for (int j = 1; j < is; j++) {
    13838                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13839                                                        ox = (float) (Math.min(iax, ibx));
    13840                                                        oaf32data[it.oIndex + j] = ox;
    13841                                                }
    13842                                        }
    13843                                }
    13844                        } else if (as > bs) {
    13845                                if (it.isOutputDouble()) {
    13846                                        while (it.hasNext()) {
    13847                                                double iax = it.aDouble;
    13848                                                final double ibx = it.bDouble;
    13849                                                float ox;
    13850                                                ox = (float) (Math.min(iax, ibx));
    13851                                                oaf32data[it.oIndex] = ox;
    13852                                                for (int j = 1; j < is; j++) {
    13853                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13854                                                        ox = (float) (Math.min(iax, ibx));
    13855                                                        oaf32data[it.oIndex + j] = ox;
    13856                                                }
    13857                                        }
    13858                                } else {
    13859                                        while (it.hasNext()) {
    13860                                                long iax = it.aLong;
    13861                                                final long ibx = it.bLong;
    13862                                                float ox;
    13863                                                ox = (float) (Math.min(iax, ibx));
    13864                                                oaf32data[it.oIndex] = ox;
    13865                                                for (int j = 1; j < is; j++) {
    13866                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13867                                                        ox = (float) (Math.min(iax, ibx));
    13868                                                        oaf32data[it.oIndex + j] = ox;
    13869                                                }
    13870                                        }
    13871                                }
    13872                        } else if (as == 1) {
    13873                                if (it.isOutputDouble()) {
    13874                                        while (it.hasNext()) {
    13875                                                final double iax = it.aDouble;
    13876                                                final double ibx = it.bDouble;
    13877                                                float ox;
    13878                                                ox = (float) (Math.min(iax, ibx));
    13879                                                for (int j = 0; j < is; j++) {
    13880                                                        oaf32data[it.oIndex + j] = ox;
    13881                                                }
    13882                                        }
    13883                                } else {
    13884                                        while (it.hasNext()) {
    13885                                                final long iax = it.aLong;
    13886                                                final long ibx = it.bLong;
    13887                                                float ox;
    13888                                                ox = (float) (Math.min(iax, ibx));
    13889                                                for (int j = 0; j < is; j++) {
    13890                                                        oaf32data[it.oIndex + j] = ox;
    13891                                                }
    13892                                        }
    13893                                }
    13894                        } else {
    13895                                if (it.isOutputDouble()) {
    13896                                        while (it.hasNext()) {
    13897                                                double iax = it.aDouble;
    13898                                                double ibx = it.bDouble;
    13899                                                float ox;
    13900                                                ox = (float) (Math.min(iax, ibx));
    13901                                                oaf32data[it.oIndex] = ox;
    13902                                                for (int j = 1; j < is; j++) {
    13903                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13904                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13905                                                        ox = (float) (Math.min(iax, ibx));
    13906                                                        oaf32data[it.oIndex + j] = ox;
    13907                                                }
    13908                                        }
    13909                                } else {
    13910                                        while (it.hasNext()) {
    13911                                                long iax = it.aLong;
    13912                                                long ibx = it.bLong;
    13913                                                float ox;
    13914                                                ox = (float) (Math.min(iax, ibx));
    13915                                                oaf32data[it.oIndex] = ox;
    13916                                                for (int j = 1; j < is; j++) {
    13917                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13918                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13919                                                        ox = (float) (Math.min(iax, ibx));
    13920                                                        oaf32data[it.oIndex + j] = ox;
    13921                                                }
    13922                                        }
    13923                                }
    13924                        }
    13925                        break;
    13926                case Dataset.ARRAYFLOAT64:
    13927                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    13928                        if (is == 1) {
    13929                                if (it.isOutputDouble()) {
    13930                                        while (it.hasNext()) {
    13931                                                final double iax = it.aDouble;
    13932                                                final double ibx = it.bDouble;
    13933                                                double ox;
    13934                                                ox = (Math.min(iax, ibx));
    13935                                                oaf64data[it.oIndex] = ox;
    13936                                        }
    13937                                } else {
    13938                                        while (it.hasNext()) {
    13939                                                final long iax = it.aLong;
    13940                                                final long ibx = it.bLong;
    13941                                                double ox;
    13942                                                ox = (Math.min(iax, ibx));
    13943                                                oaf64data[it.oIndex] = ox;
    13944                                        }
    13945                                }
    13946                        } else if (as < bs) {
    13947                                if (it.isOutputDouble()) {
    13948                                        while (it.hasNext()) {
    13949                                                final double iax = it.aDouble;
    13950                                                double ibx = it.bDouble;
    13951                                                double ox;
    13952                                                ox = (Math.min(iax, ibx));
    13953                                                oaf64data[it.oIndex] = ox;
    13954                                                for (int j = 1; j < is; j++) {
    13955                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    13956                                                        ox = (Math.min(iax, ibx));
    13957                                                        oaf64data[it.oIndex + j] = ox;
    13958                                                }
    13959                                        }
    13960                                } else {
    13961                                        while (it.hasNext()) {
    13962                                                final long iax = it.aLong;
    13963                                                long ibx = it.bLong;
    13964                                                double ox;
    13965                                                ox = (Math.min(iax, ibx));
    13966                                                oaf64data[it.oIndex] = ox;
    13967                                                for (int j = 1; j < is; j++) {
    13968                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    13969                                                        ox = (Math.min(iax, ibx));
    13970                                                        oaf64data[it.oIndex + j] = ox;
    13971                                                }
    13972                                        }
    13973                                }
    13974                        } else if (as > bs) {
    13975                                if (it.isOutputDouble()) {
    13976                                        while (it.hasNext()) {
    13977                                                double iax = it.aDouble;
    13978                                                final double ibx = it.bDouble;
    13979                                                double ox;
    13980                                                ox = (Math.min(iax, ibx));
    13981                                                oaf64data[it.oIndex] = ox;
    13982                                                for (int j = 1; j < is; j++) {
    13983                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    13984                                                        ox = (Math.min(iax, ibx));
    13985                                                        oaf64data[it.oIndex + j] = ox;
    13986                                                }
    13987                                        }
    13988                                } else {
    13989                                        while (it.hasNext()) {
    13990                                                long iax = it.aLong;
    13991                                                final long ibx = it.bLong;
    13992                                                double ox;
    13993                                                ox = (Math.min(iax, ibx));
    13994                                                oaf64data[it.oIndex] = ox;
    13995                                                for (int j = 1; j < is; j++) {
    13996                                                        iax = da.getElementLongAbs(it.aIndex + j);
    13997                                                        ox = (Math.min(iax, ibx));
    13998                                                        oaf64data[it.oIndex + j] = ox;
    13999                                                }
    14000                                        }
    14001                                }
    14002                        } else if (as == 1) {
    14003                                if (it.isOutputDouble()) {
    14004                                        while (it.hasNext()) {
    14005                                                final double iax = it.aDouble;
    14006                                                final double ibx = it.bDouble;
    14007                                                double ox;
    14008                                                ox = (Math.min(iax, ibx));
    14009                                                for (int j = 0; j < is; j++) {
    14010                                                        oaf64data[it.oIndex + j] = ox;
    14011                                                }
    14012                                        }
    14013                                } else {
    14014                                        while (it.hasNext()) {
    14015                                                final long iax = it.aLong;
    14016                                                final long ibx = it.bLong;
    14017                                                double ox;
    14018                                                ox = (Math.min(iax, ibx));
    14019                                                for (int j = 0; j < is; j++) {
    14020                                                        oaf64data[it.oIndex + j] = ox;
    14021                                                }
    14022                                        }
    14023                                }
    14024                        } else {
    14025                                if (it.isOutputDouble()) {
    14026                                        while (it.hasNext()) {
    14027                                                double iax = it.aDouble;
    14028                                                double ibx = it.bDouble;
    14029                                                double ox;
    14030                                                ox = (Math.min(iax, ibx));
    14031                                                oaf64data[it.oIndex] = ox;
    14032                                                for (int j = 1; j < is; j++) {
    14033                                                        iax = da.getElementDoubleAbs(it.aIndex + j);
    14034                                                        ibx = db.getElementDoubleAbs(it.bIndex + j);
    14035                                                        ox = (Math.min(iax, ibx));
    14036                                                        oaf64data[it.oIndex + j] = ox;
    14037                                                }
    14038                                        }
    14039                                } else {
    14040                                        while (it.hasNext()) {
    14041                                                long iax = it.aLong;
    14042                                                long ibx = it.bLong;
    14043                                                double ox;
    14044                                                ox = (Math.min(iax, ibx));
    14045                                                oaf64data[it.oIndex] = ox;
    14046                                                for (int j = 1; j < is; j++) {
    14047                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14048                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14049                                                        ox = (Math.min(iax, ibx));
    14050                                                        oaf64data[it.oIndex + j] = ox;
    14051                                                }
    14052                                        }
    14053                                }
    14054                        }
    14055                        break;
    14056                case Dataset.COMPLEX64:
    14057                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    14058                        if (as == 1) {
    14059                                final double iay = 0;
    14060                                while (it.hasNext()) {
    14061                                        final double iax = it.aDouble;
    14062                                        final double ibx = it.bDouble;
    14063                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    14064                                        float ox;
    14065                                        float oy;
    14066                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    14067                                                ox = (float) (iax);
    14068                                                oy = (float) (iay);
    14069                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    14070                                                ox = (float) (ibx);
    14071                                                oy = (float) (iby);
    14072                                        } else {
    14073                                                ox = (float) (Math.min(iax, ibx));
    14074                                                oy = (float) (Math.min(iay, iby));
    14075                                        }
    14076                                        oc64data[it.oIndex] = ox;
    14077                                        oc64data[it.oIndex + 1] = oy;
    14078                                }
    14079                        } else if (bs == 1) {
    14080                                final double iby = 0;
    14081                                while (it.hasNext()) {
    14082                                        final double iax = it.aDouble;
    14083                                        final double ibx = it.bDouble;
    14084                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    14085                                        float ox;
    14086                                        float oy;
    14087                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    14088                                                ox = (float) (iax);
    14089                                                oy = (float) (iay);
    14090                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    14091                                                ox = (float) (ibx);
    14092                                                oy = (float) (iby);
    14093                                        } else {
    14094                                                ox = (float) (Math.min(iax, ibx));
    14095                                                oy = (float) (Math.min(iay, iby));
    14096                                        }
    14097                                        oc64data[it.oIndex] = ox;
    14098                                        oc64data[it.oIndex + 1] = oy;
    14099                                }
    14100                        } else {
    14101                                while (it.hasNext()) {
    14102                                        final double iax = it.aDouble;
    14103                                        final double ibx = it.bDouble;
    14104                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    14105                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    14106                                        float ox;
    14107                                        float oy;
    14108                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    14109                                                ox = (float) (iax);
    14110                                                oy = (float) (iay);
    14111                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    14112                                                ox = (float) (ibx);
    14113                                                oy = (float) (iby);
    14114                                        } else {
    14115                                                ox = (float) (Math.min(iax, ibx));
    14116                                                oy = (float) (Math.min(iay, iby));
    14117                                        }
    14118                                        oc64data[it.oIndex] = ox;
    14119                                        oc64data[it.oIndex + 1] = oy;
    14120                                }
    14121                        }
    14122                        break;
    14123                case Dataset.COMPLEX128:
    14124                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    14125                        if (as == 1) {
    14126                                final double iay = 0;
    14127                                while (it.hasNext()) {
    14128                                        final double iax = it.aDouble;
    14129                                        final double ibx = it.bDouble;
    14130                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    14131                                        double ox;
    14132                                        double oy;
    14133                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    14134                                                ox = (iax);
    14135                                                oy = (iay);
    14136                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    14137                                                ox = (ibx);
    14138                                                oy = (iby);
    14139                                        } else {
    14140                                                ox = (Math.min(iax, ibx));
    14141                                                oy = (Math.min(iay, iby));
    14142                                        }
    14143                                        oc128data[it.oIndex] = ox;
    14144                                        oc128data[it.oIndex + 1] = oy;
    14145                                }
    14146                        } else if (bs == 1) {
    14147                                final double iby = 0;
    14148                                while (it.hasNext()) {
    14149                                        final double iax = it.aDouble;
    14150                                        final double ibx = it.bDouble;
    14151                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    14152                                        double ox;
    14153                                        double oy;
    14154                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    14155                                                ox = (iax);
    14156                                                oy = (iay);
    14157                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    14158                                                ox = (ibx);
    14159                                                oy = (iby);
    14160                                        } else {
    14161                                                ox = (Math.min(iax, ibx));
    14162                                                oy = (Math.min(iay, iby));
    14163                                        }
    14164                                        oc128data[it.oIndex] = ox;
    14165                                        oc128data[it.oIndex + 1] = oy;
    14166                                }
    14167                        } else {
    14168                                while (it.hasNext()) {
    14169                                        final double iax = it.aDouble;
    14170                                        final double ibx = it.bDouble;
    14171                                        final double iay = da.getElementDoubleAbs(it.aIndex + 1);
    14172                                        final double iby = db.getElementDoubleAbs(it.bIndex + 1);
    14173                                        double ox;
    14174                                        double oy;
    14175                                        if (Double.isNaN(iax) || Double.isNaN(iay)) {
    14176                                                ox = (iax);
    14177                                                oy = (iay);
    14178                                        } else if (Double.isNaN(ibx) || Double.isNaN(iby)) {
    14179                                                ox = (ibx);
    14180                                                oy = (iby);
    14181                                        } else {
    14182                                                ox = (Math.min(iax, ibx));
    14183                                                oy = (Math.min(iay, iby));
    14184                                        }
    14185                                        oc128data[it.oIndex] = ox;
    14186                                        oc128data[it.oIndex + 1] = oy;
    14187                                }
    14188                        }
    14189                        break;
    14190                default:
    14191                        throw new IllegalArgumentException("minimum supports integer, compound integer, real, compound real, complex datasets only");
    14192                }
    14193
    14194                addBinaryOperatorName(da, db, result, "minimum");
    14195                return result;
    14196        }
    14197
    14198        /**
    14199         * bitwiseAnd operator
    14200         * @param a
    14201         * @param b
    14202         * @return {@code a & b}, bitwise AND of a and b
    14203         */
    14204        public static Dataset bitwiseAnd(final Object a, final Object b) {
    14205                return bitwiseAnd(a, b, null);
    14206        }
    14207
    14208        /**
    14209         * bitwiseAnd operator
    14210         * @param a
    14211         * @param b
    14212         * @param o output can be null - in which case, a new dataset is created
    14213         * @return {@code a & b}, bitwise AND of a and b
    14214         */
    14215        public static Dataset bitwiseAnd(final Object a, final Object b, final Dataset o) {
    14216                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    14217                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    14218                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    14219                it.setOutputDouble(false);
    14220                final Dataset result = it.getOutput();
    14221                final int is = result.getElementsPerItem();
    14222                final int as = da.getElementsPerItem();
    14223                final int bs = db.getElementsPerItem();
    14224                final int dt = result.getDType();
    14225
    14226                switch(dt) {
    14227                case Dataset.INT8:
    14228                        final byte[] oi8data = ((ByteDataset) result).getData();
    14229                        {
    14230                                while (it.hasNext()) {
    14231                                        final long iax = it.aLong;
    14232                                        final long ibx = it.bLong;
    14233                                        byte ox;
    14234                                        ox = (byte) (iax & ibx);
    14235                                        oi8data[it.oIndex] = ox;
    14236                                }
    14237                        }
    14238                        break;
    14239                case Dataset.INT16:
    14240                        final short[] oi16data = ((ShortDataset) result).getData();
    14241                        {
    14242                                while (it.hasNext()) {
    14243                                        final long iax = it.aLong;
    14244                                        final long ibx = it.bLong;
    14245                                        short ox;
    14246                                        ox = (short) (iax & ibx);
    14247                                        oi16data[it.oIndex] = ox;
    14248                                }
    14249                        }
    14250                        break;
    14251                case Dataset.INT64:
    14252                        final long[] oi64data = ((LongDataset) result).getData();
    14253                        {
    14254                                while (it.hasNext()) {
    14255                                        final long iax = it.aLong;
    14256                                        final long ibx = it.bLong;
    14257                                        long ox;
    14258                                        ox = (iax & ibx);
    14259                                        oi64data[it.oIndex] = ox;
    14260                                }
    14261                        }
    14262                        break;
    14263                case Dataset.INT32:
    14264                        final int[] oi32data = ((IntegerDataset) result).getData();
    14265                        {
    14266                                while (it.hasNext()) {
    14267                                        final long iax = it.aLong;
    14268                                        final long ibx = it.bLong;
    14269                                        int ox;
    14270                                        ox = (int) (iax & ibx);
    14271                                        oi32data[it.oIndex] = ox;
    14272                                }
    14273                        }
    14274                        break;
    14275                case Dataset.ARRAYINT8:
    14276                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    14277                        if (is == 1) {
    14278                                {
    14279                                        while (it.hasNext()) {
    14280                                                final long iax = it.aLong;
    14281                                                final long ibx = it.bLong;
    14282                                                byte ox;
    14283                                                ox = (byte) (iax & ibx);
    14284                                                oai8data[it.oIndex] = ox;
    14285                                        }
    14286                                }
    14287                        } else if (as < bs) {
    14288                                {
    14289                                        while (it.hasNext()) {
    14290                                                final long iax = it.aLong;
    14291                                                long ibx = it.bLong;
    14292                                                byte ox;
    14293                                                ox = (byte) (iax & ibx);
    14294                                                oai8data[it.oIndex] = ox;
    14295                                                for (int j = 1; j < is; j++) {
    14296                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14297                                                        ox = (byte) (iax & ibx);
    14298                                                        oai8data[it.oIndex + j] = ox;
    14299                                                }
    14300                                        }
    14301                                }
    14302                        } else if (as > bs) {
    14303                                {
    14304                                        while (it.hasNext()) {
    14305                                                long iax = it.aLong;
    14306                                                final long ibx = it.bLong;
    14307                                                byte ox;
    14308                                                ox = (byte) (iax & ibx);
    14309                                                oai8data[it.oIndex] = ox;
    14310                                                for (int j = 1; j < is; j++) {
    14311                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14312                                                        ox = (byte) (iax & ibx);
    14313                                                        oai8data[it.oIndex + j] = ox;
    14314                                                }
    14315                                        }
    14316                                }
    14317                        } else if (as == 1) {
    14318                                {
    14319                                        while (it.hasNext()) {
    14320                                                final long iax = it.aLong;
    14321                                                final long ibx = it.bLong;
    14322                                                byte ox;
    14323                                                ox = (byte) (iax & ibx);
    14324                                                for (int j = 0; j < is; j++) {
    14325                                                        oai8data[it.oIndex + j] = ox;
    14326                                                }
    14327                                        }
    14328                                }
    14329                        } else {
    14330                                {
    14331                                        while (it.hasNext()) {
    14332                                                long iax = it.aLong;
    14333                                                long ibx = it.bLong;
    14334                                                byte ox;
    14335                                                ox = (byte) (iax & ibx);
    14336                                                oai8data[it.oIndex] = ox;
    14337                                                for (int j = 1; j < is; j++) {
    14338                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14339                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14340                                                        ox = (byte) (iax & ibx);
    14341                                                        oai8data[it.oIndex + j] = ox;
    14342                                                }
    14343                                        }
    14344                                }
    14345                        }
    14346                        break;
    14347                case Dataset.ARRAYINT16:
    14348                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    14349                        if (is == 1) {
    14350                                {
    14351                                        while (it.hasNext()) {
    14352                                                final long iax = it.aLong;
    14353                                                final long ibx = it.bLong;
    14354                                                short ox;
    14355                                                ox = (short) (iax & ibx);
    14356                                                oai16data[it.oIndex] = ox;
    14357                                        }
    14358                                }
    14359                        } else if (as < bs) {
    14360                                {
    14361                                        while (it.hasNext()) {
    14362                                                final long iax = it.aLong;
    14363                                                long ibx = it.bLong;
    14364                                                short ox;
    14365                                                ox = (short) (iax & ibx);
    14366                                                oai16data[it.oIndex] = ox;
    14367                                                for (int j = 1; j < is; j++) {
    14368                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14369                                                        ox = (short) (iax & ibx);
    14370                                                        oai16data[it.oIndex + j] = ox;
    14371                                                }
    14372                                        }
    14373                                }
    14374                        } else if (as > bs) {
    14375                                {
    14376                                        while (it.hasNext()) {
    14377                                                long iax = it.aLong;
    14378                                                final long ibx = it.bLong;
    14379                                                short ox;
    14380                                                ox = (short) (iax & ibx);
    14381                                                oai16data[it.oIndex] = ox;
    14382                                                for (int j = 1; j < is; j++) {
    14383                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14384                                                        ox = (short) (iax & ibx);
    14385                                                        oai16data[it.oIndex + j] = ox;
    14386                                                }
    14387                                        }
    14388                                }
    14389                        } else if (as == 1) {
    14390                                {
    14391                                        while (it.hasNext()) {
    14392                                                final long iax = it.aLong;
    14393                                                final long ibx = it.bLong;
    14394                                                short ox;
    14395                                                ox = (short) (iax & ibx);
    14396                                                for (int j = 0; j < is; j++) {
    14397                                                        oai16data[it.oIndex + j] = ox;
    14398                                                }
    14399                                        }
    14400                                }
    14401                        } else {
    14402                                {
    14403                                        while (it.hasNext()) {
    14404                                                long iax = it.aLong;
    14405                                                long ibx = it.bLong;
    14406                                                short ox;
    14407                                                ox = (short) (iax & ibx);
    14408                                                oai16data[it.oIndex] = ox;
    14409                                                for (int j = 1; j < is; j++) {
    14410                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14411                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14412                                                        ox = (short) (iax & ibx);
    14413                                                        oai16data[it.oIndex + j] = ox;
    14414                                                }
    14415                                        }
    14416                                }
    14417                        }
    14418                        break;
    14419                case Dataset.ARRAYINT64:
    14420                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    14421                        if (is == 1) {
    14422                                {
    14423                                        while (it.hasNext()) {
    14424                                                final long iax = it.aLong;
    14425                                                final long ibx = it.bLong;
    14426                                                long ox;
    14427                                                ox = (iax & ibx);
    14428                                                oai64data[it.oIndex] = ox;
    14429                                        }
    14430                                }
    14431                        } else if (as < bs) {
    14432                                {
    14433                                        while (it.hasNext()) {
    14434                                                final long iax = it.aLong;
    14435                                                long ibx = it.bLong;
    14436                                                long ox;
    14437                                                ox = (iax & ibx);
    14438                                                oai64data[it.oIndex] = ox;
    14439                                                for (int j = 1; j < is; j++) {
    14440                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14441                                                        ox = (iax & ibx);
    14442                                                        oai64data[it.oIndex + j] = ox;
    14443                                                }
    14444                                        }
    14445                                }
    14446                        } else if (as > bs) {
    14447                                {
    14448                                        while (it.hasNext()) {
    14449                                                long iax = it.aLong;
    14450                                                final long ibx = it.bLong;
    14451                                                long ox;
    14452                                                ox = (iax & ibx);
    14453                                                oai64data[it.oIndex] = ox;
    14454                                                for (int j = 1; j < is; j++) {
    14455                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14456                                                        ox = (iax & ibx);
    14457                                                        oai64data[it.oIndex + j] = ox;
    14458                                                }
    14459                                        }
    14460                                }
    14461                        } else if (as == 1) {
    14462                                {
    14463                                        while (it.hasNext()) {
    14464                                                final long iax = it.aLong;
    14465                                                final long ibx = it.bLong;
    14466                                                long ox;
    14467                                                ox = (iax & ibx);
    14468                                                for (int j = 0; j < is; j++) {
    14469                                                        oai64data[it.oIndex + j] = ox;
    14470                                                }
    14471                                        }
    14472                                }
    14473                        } else {
    14474                                {
    14475                                        while (it.hasNext()) {
    14476                                                long iax = it.aLong;
    14477                                                long ibx = it.bLong;
    14478                                                long ox;
    14479                                                ox = (iax & ibx);
    14480                                                oai64data[it.oIndex] = ox;
    14481                                                for (int j = 1; j < is; j++) {
    14482                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14483                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14484                                                        ox = (iax & ibx);
    14485                                                        oai64data[it.oIndex + j] = ox;
    14486                                                }
    14487                                        }
    14488                                }
    14489                        }
    14490                        break;
    14491                case Dataset.ARRAYINT32:
    14492                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    14493                        if (is == 1) {
    14494                                {
    14495                                        while (it.hasNext()) {
    14496                                                final long iax = it.aLong;
    14497                                                final long ibx = it.bLong;
    14498                                                int ox;
    14499                                                ox = (int) (iax & ibx);
    14500                                                oai32data[it.oIndex] = ox;
    14501                                        }
    14502                                }
    14503                        } else if (as < bs) {
    14504                                {
    14505                                        while (it.hasNext()) {
    14506                                                final long iax = it.aLong;
    14507                                                long ibx = it.bLong;
    14508                                                int ox;
    14509                                                ox = (int) (iax & ibx);
    14510                                                oai32data[it.oIndex] = ox;
    14511                                                for (int j = 1; j < is; j++) {
    14512                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14513                                                        ox = (int) (iax & ibx);
    14514                                                        oai32data[it.oIndex + j] = ox;
    14515                                                }
    14516                                        }
    14517                                }
    14518                        } else if (as > bs) {
    14519                                {
    14520                                        while (it.hasNext()) {
    14521                                                long iax = it.aLong;
    14522                                                final long ibx = it.bLong;
    14523                                                int ox;
    14524                                                ox = (int) (iax & ibx);
    14525                                                oai32data[it.oIndex] = ox;
    14526                                                for (int j = 1; j < is; j++) {
    14527                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14528                                                        ox = (int) (iax & ibx);
    14529                                                        oai32data[it.oIndex + j] = ox;
    14530                                                }
    14531                                        }
    14532                                }
    14533                        } else if (as == 1) {
    14534                                {
    14535                                        while (it.hasNext()) {
    14536                                                final long iax = it.aLong;
    14537                                                final long ibx = it.bLong;
    14538                                                int ox;
    14539                                                ox = (int) (iax & ibx);
    14540                                                for (int j = 0; j < is; j++) {
    14541                                                        oai32data[it.oIndex + j] = ox;
    14542                                                }
    14543                                        }
    14544                                }
    14545                        } else {
    14546                                {
    14547                                        while (it.hasNext()) {
    14548                                                long iax = it.aLong;
    14549                                                long ibx = it.bLong;
    14550                                                int ox;
    14551                                                ox = (int) (iax & ibx);
    14552                                                oai32data[it.oIndex] = ox;
    14553                                                for (int j = 1; j < is; j++) {
    14554                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14555                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14556                                                        ox = (int) (iax & ibx);
    14557                                                        oai32data[it.oIndex + j] = ox;
    14558                                                }
    14559                                        }
    14560                                }
    14561                        }
    14562                        break;
    14563                default:
    14564                        throw new IllegalArgumentException("bitwiseAnd supports integer, compound integer datasets only");
    14565                }
    14566
    14567                addBinaryOperatorName(da, db, result, "&");
    14568                return result;
    14569        }
    14570
    14571        /**
    14572         * bitwiseOr operator
    14573         * @param a
    14574         * @param b
    14575         * @return {@code a | b}, bitwise inclusive OR of a and b
    14576         */
    14577        public static Dataset bitwiseOr(final Object a, final Object b) {
    14578                return bitwiseOr(a, b, null);
    14579        }
    14580
    14581        /**
    14582         * bitwiseOr operator
    14583         * @param a
    14584         * @param b
    14585         * @param o output can be null - in which case, a new dataset is created
    14586         * @return {@code a | b}, bitwise inclusive OR of a and b
    14587         */
    14588        public static Dataset bitwiseOr(final Object a, final Object b, final Dataset o) {
    14589                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    14590                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    14591                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    14592                it.setOutputDouble(false);
    14593                final Dataset result = it.getOutput();
    14594                final int is = result.getElementsPerItem();
    14595                final int as = da.getElementsPerItem();
    14596                final int bs = db.getElementsPerItem();
    14597                final int dt = result.getDType();
    14598
    14599                switch(dt) {
    14600                case Dataset.INT8:
    14601                        final byte[] oi8data = ((ByteDataset) result).getData();
    14602                        {
    14603                                while (it.hasNext()) {
    14604                                        final long iax = it.aLong;
    14605                                        final long ibx = it.bLong;
    14606                                        byte ox;
    14607                                        ox = (byte) (iax | ibx);
    14608                                        oi8data[it.oIndex] = ox;
    14609                                }
    14610                        }
    14611                        break;
    14612                case Dataset.INT16:
    14613                        final short[] oi16data = ((ShortDataset) result).getData();
    14614                        {
    14615                                while (it.hasNext()) {
    14616                                        final long iax = it.aLong;
    14617                                        final long ibx = it.bLong;
    14618                                        short ox;
    14619                                        ox = (short) (iax | ibx);
    14620                                        oi16data[it.oIndex] = ox;
    14621                                }
    14622                        }
    14623                        break;
    14624                case Dataset.INT64:
    14625                        final long[] oi64data = ((LongDataset) result).getData();
    14626                        {
    14627                                while (it.hasNext()) {
    14628                                        final long iax = it.aLong;
    14629                                        final long ibx = it.bLong;
    14630                                        long ox;
    14631                                        ox = (iax | ibx);
    14632                                        oi64data[it.oIndex] = ox;
    14633                                }
    14634                        }
    14635                        break;
    14636                case Dataset.INT32:
    14637                        final int[] oi32data = ((IntegerDataset) result).getData();
    14638                        {
    14639                                while (it.hasNext()) {
    14640                                        final long iax = it.aLong;
    14641                                        final long ibx = it.bLong;
    14642                                        int ox;
    14643                                        ox = (int) (iax | ibx);
    14644                                        oi32data[it.oIndex] = ox;
    14645                                }
    14646                        }
    14647                        break;
    14648                case Dataset.ARRAYINT8:
    14649                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    14650                        if (is == 1) {
    14651                                {
    14652                                        while (it.hasNext()) {
    14653                                                final long iax = it.aLong;
    14654                                                final long ibx = it.bLong;
    14655                                                byte ox;
    14656                                                ox = (byte) (iax | ibx);
    14657                                                oai8data[it.oIndex] = ox;
    14658                                        }
    14659                                }
    14660                        } else if (as < bs) {
    14661                                {
    14662                                        while (it.hasNext()) {
    14663                                                final long iax = it.aLong;
    14664                                                long ibx = it.bLong;
    14665                                                byte ox;
    14666                                                ox = (byte) (iax | ibx);
    14667                                                oai8data[it.oIndex] = ox;
    14668                                                for (int j = 1; j < is; j++) {
    14669                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14670                                                        ox = (byte) (iax | ibx);
    14671                                                        oai8data[it.oIndex + j] = ox;
    14672                                                }
    14673                                        }
    14674                                }
    14675                        } else if (as > bs) {
    14676                                {
    14677                                        while (it.hasNext()) {
    14678                                                long iax = it.aLong;
    14679                                                final long ibx = it.bLong;
    14680                                                byte ox;
    14681                                                ox = (byte) (iax | ibx);
    14682                                                oai8data[it.oIndex] = ox;
    14683                                                for (int j = 1; j < is; j++) {
    14684                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14685                                                        ox = (byte) (iax | ibx);
    14686                                                        oai8data[it.oIndex + j] = ox;
    14687                                                }
    14688                                        }
    14689                                }
    14690                        } else if (as == 1) {
    14691                                {
    14692                                        while (it.hasNext()) {
    14693                                                final long iax = it.aLong;
    14694                                                final long ibx = it.bLong;
    14695                                                byte ox;
    14696                                                ox = (byte) (iax | ibx);
    14697                                                for (int j = 0; j < is; j++) {
    14698                                                        oai8data[it.oIndex + j] = ox;
    14699                                                }
    14700                                        }
    14701                                }
    14702                        } else {
    14703                                {
    14704                                        while (it.hasNext()) {
    14705                                                long iax = it.aLong;
    14706                                                long ibx = it.bLong;
    14707                                                byte ox;
    14708                                                ox = (byte) (iax | ibx);
    14709                                                oai8data[it.oIndex] = ox;
    14710                                                for (int j = 1; j < is; j++) {
    14711                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14712                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14713                                                        ox = (byte) (iax | ibx);
    14714                                                        oai8data[it.oIndex + j] = ox;
    14715                                                }
    14716                                        }
    14717                                }
    14718                        }
    14719                        break;
    14720                case Dataset.ARRAYINT16:
    14721                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    14722                        if (is == 1) {
    14723                                {
    14724                                        while (it.hasNext()) {
    14725                                                final long iax = it.aLong;
    14726                                                final long ibx = it.bLong;
    14727                                                short ox;
    14728                                                ox = (short) (iax | ibx);
    14729                                                oai16data[it.oIndex] = ox;
    14730                                        }
    14731                                }
    14732                        } else if (as < bs) {
    14733                                {
    14734                                        while (it.hasNext()) {
    14735                                                final long iax = it.aLong;
    14736                                                long ibx = it.bLong;
    14737                                                short ox;
    14738                                                ox = (short) (iax | ibx);
    14739                                                oai16data[it.oIndex] = ox;
    14740                                                for (int j = 1; j < is; j++) {
    14741                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14742                                                        ox = (short) (iax | ibx);
    14743                                                        oai16data[it.oIndex + j] = ox;
    14744                                                }
    14745                                        }
    14746                                }
    14747                        } else if (as > bs) {
    14748                                {
    14749                                        while (it.hasNext()) {
    14750                                                long iax = it.aLong;
    14751                                                final long ibx = it.bLong;
    14752                                                short ox;
    14753                                                ox = (short) (iax | ibx);
    14754                                                oai16data[it.oIndex] = ox;
    14755                                                for (int j = 1; j < is; j++) {
    14756                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14757                                                        ox = (short) (iax | ibx);
    14758                                                        oai16data[it.oIndex + j] = ox;
    14759                                                }
    14760                                        }
    14761                                }
    14762                        } else if (as == 1) {
    14763                                {
    14764                                        while (it.hasNext()) {
    14765                                                final long iax = it.aLong;
    14766                                                final long ibx = it.bLong;
    14767                                                short ox;
    14768                                                ox = (short) (iax | ibx);
    14769                                                for (int j = 0; j < is; j++) {
    14770                                                        oai16data[it.oIndex + j] = ox;
    14771                                                }
    14772                                        }
    14773                                }
    14774                        } else {
    14775                                {
    14776                                        while (it.hasNext()) {
    14777                                                long iax = it.aLong;
    14778                                                long ibx = it.bLong;
    14779                                                short ox;
    14780                                                ox = (short) (iax | ibx);
    14781                                                oai16data[it.oIndex] = ox;
    14782                                                for (int j = 1; j < is; j++) {
    14783                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14784                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14785                                                        ox = (short) (iax | ibx);
    14786                                                        oai16data[it.oIndex + j] = ox;
    14787                                                }
    14788                                        }
    14789                                }
    14790                        }
    14791                        break;
    14792                case Dataset.ARRAYINT64:
    14793                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    14794                        if (is == 1) {
    14795                                {
    14796                                        while (it.hasNext()) {
    14797                                                final long iax = it.aLong;
    14798                                                final long ibx = it.bLong;
    14799                                                long ox;
    14800                                                ox = (iax | ibx);
    14801                                                oai64data[it.oIndex] = ox;
    14802                                        }
    14803                                }
    14804                        } else if (as < bs) {
    14805                                {
    14806                                        while (it.hasNext()) {
    14807                                                final long iax = it.aLong;
    14808                                                long ibx = it.bLong;
    14809                                                long ox;
    14810                                                ox = (iax | ibx);
    14811                                                oai64data[it.oIndex] = ox;
    14812                                                for (int j = 1; j < is; j++) {
    14813                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14814                                                        ox = (iax | ibx);
    14815                                                        oai64data[it.oIndex + j] = ox;
    14816                                                }
    14817                                        }
    14818                                }
    14819                        } else if (as > bs) {
    14820                                {
    14821                                        while (it.hasNext()) {
    14822                                                long iax = it.aLong;
    14823                                                final long ibx = it.bLong;
    14824                                                long ox;
    14825                                                ox = (iax | ibx);
    14826                                                oai64data[it.oIndex] = ox;
    14827                                                for (int j = 1; j < is; j++) {
    14828                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14829                                                        ox = (iax | ibx);
    14830                                                        oai64data[it.oIndex + j] = ox;
    14831                                                }
    14832                                        }
    14833                                }
    14834                        } else if (as == 1) {
    14835                                {
    14836                                        while (it.hasNext()) {
    14837                                                final long iax = it.aLong;
    14838                                                final long ibx = it.bLong;
    14839                                                long ox;
    14840                                                ox = (iax | ibx);
    14841                                                for (int j = 0; j < is; j++) {
    14842                                                        oai64data[it.oIndex + j] = ox;
    14843                                                }
    14844                                        }
    14845                                }
    14846                        } else {
    14847                                {
    14848                                        while (it.hasNext()) {
    14849                                                long iax = it.aLong;
    14850                                                long ibx = it.bLong;
    14851                                                long ox;
    14852                                                ox = (iax | ibx);
    14853                                                oai64data[it.oIndex] = ox;
    14854                                                for (int j = 1; j < is; j++) {
    14855                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14856                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14857                                                        ox = (iax | ibx);
    14858                                                        oai64data[it.oIndex + j] = ox;
    14859                                                }
    14860                                        }
    14861                                }
    14862                        }
    14863                        break;
    14864                case Dataset.ARRAYINT32:
    14865                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    14866                        if (is == 1) {
    14867                                {
    14868                                        while (it.hasNext()) {
    14869                                                final long iax = it.aLong;
    14870                                                final long ibx = it.bLong;
    14871                                                int ox;
    14872                                                ox = (int) (iax | ibx);
    14873                                                oai32data[it.oIndex] = ox;
    14874                                        }
    14875                                }
    14876                        } else if (as < bs) {
    14877                                {
    14878                                        while (it.hasNext()) {
    14879                                                final long iax = it.aLong;
    14880                                                long ibx = it.bLong;
    14881                                                int ox;
    14882                                                ox = (int) (iax | ibx);
    14883                                                oai32data[it.oIndex] = ox;
    14884                                                for (int j = 1; j < is; j++) {
    14885                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14886                                                        ox = (int) (iax | ibx);
    14887                                                        oai32data[it.oIndex + j] = ox;
    14888                                                }
    14889                                        }
    14890                                }
    14891                        } else if (as > bs) {
    14892                                {
    14893                                        while (it.hasNext()) {
    14894                                                long iax = it.aLong;
    14895                                                final long ibx = it.bLong;
    14896                                                int ox;
    14897                                                ox = (int) (iax | ibx);
    14898                                                oai32data[it.oIndex] = ox;
    14899                                                for (int j = 1; j < is; j++) {
    14900                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14901                                                        ox = (int) (iax | ibx);
    14902                                                        oai32data[it.oIndex + j] = ox;
    14903                                                }
    14904                                        }
    14905                                }
    14906                        } else if (as == 1) {
    14907                                {
    14908                                        while (it.hasNext()) {
    14909                                                final long iax = it.aLong;
    14910                                                final long ibx = it.bLong;
    14911                                                int ox;
    14912                                                ox = (int) (iax | ibx);
    14913                                                for (int j = 0; j < is; j++) {
    14914                                                        oai32data[it.oIndex + j] = ox;
    14915                                                }
    14916                                        }
    14917                                }
    14918                        } else {
    14919                                {
    14920                                        while (it.hasNext()) {
    14921                                                long iax = it.aLong;
    14922                                                long ibx = it.bLong;
    14923                                                int ox;
    14924                                                ox = (int) (iax | ibx);
    14925                                                oai32data[it.oIndex] = ox;
    14926                                                for (int j = 1; j < is; j++) {
    14927                                                        iax = da.getElementLongAbs(it.aIndex + j);
    14928                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    14929                                                        ox = (int) (iax | ibx);
    14930                                                        oai32data[it.oIndex + j] = ox;
    14931                                                }
    14932                                        }
    14933                                }
    14934                        }
    14935                        break;
    14936                default:
    14937                        throw new IllegalArgumentException("bitwiseOr supports integer, compound integer datasets only");
    14938                }
    14939
    14940                addBinaryOperatorName(da, db, result, "|");
    14941                return result;
    14942        }
    14943
    14944        /**
    14945         * bitwiseXor operator
    14946         * @param a
    14947         * @param b
    14948         * @return {@code a ^ b}, bitwise exclusive OR of a and b
    14949         */
    14950        public static Dataset bitwiseXor(final Object a, final Object b) {
    14951                return bitwiseXor(a, b, null);
    14952        }
    14953
    14954        /**
    14955         * bitwiseXor operator
    14956         * @param a
    14957         * @param b
    14958         * @param o output can be null - in which case, a new dataset is created
    14959         * @return {@code a ^ b}, bitwise exclusive OR of a and b
    14960         */
    14961        public static Dataset bitwiseXor(final Object a, final Object b, final Dataset o) {
    14962                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    14963                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    14964                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    14965                it.setOutputDouble(false);
    14966                final Dataset result = it.getOutput();
    14967                final int is = result.getElementsPerItem();
    14968                final int as = da.getElementsPerItem();
    14969                final int bs = db.getElementsPerItem();
    14970                final int dt = result.getDType();
    14971
    14972                switch(dt) {
    14973                case Dataset.INT8:
    14974                        final byte[] oi8data = ((ByteDataset) result).getData();
    14975                        {
    14976                                while (it.hasNext()) {
    14977                                        final long iax = it.aLong;
    14978                                        final long ibx = it.bLong;
    14979                                        byte ox;
    14980                                        ox = (byte) (iax ^ ibx);
    14981                                        oi8data[it.oIndex] = ox;
    14982                                }
    14983                        }
    14984                        break;
    14985                case Dataset.INT16:
    14986                        final short[] oi16data = ((ShortDataset) result).getData();
    14987                        {
    14988                                while (it.hasNext()) {
    14989                                        final long iax = it.aLong;
    14990                                        final long ibx = it.bLong;
    14991                                        short ox;
    14992                                        ox = (short) (iax ^ ibx);
    14993                                        oi16data[it.oIndex] = ox;
    14994                                }
    14995                        }
    14996                        break;
    14997                case Dataset.INT64:
    14998                        final long[] oi64data = ((LongDataset) result).getData();
    14999                        {
    15000                                while (it.hasNext()) {
    15001                                        final long iax = it.aLong;
    15002                                        final long ibx = it.bLong;
    15003                                        long ox;
    15004                                        ox = (iax ^ ibx);
    15005                                        oi64data[it.oIndex] = ox;
    15006                                }
    15007                        }
    15008                        break;
    15009                case Dataset.INT32:
    15010                        final int[] oi32data = ((IntegerDataset) result).getData();
    15011                        {
    15012                                while (it.hasNext()) {
    15013                                        final long iax = it.aLong;
    15014                                        final long ibx = it.bLong;
    15015                                        int ox;
    15016                                        ox = (int) (iax ^ ibx);
    15017                                        oi32data[it.oIndex] = ox;
    15018                                }
    15019                        }
    15020                        break;
    15021                case Dataset.ARRAYINT8:
    15022                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    15023                        if (is == 1) {
    15024                                {
    15025                                        while (it.hasNext()) {
    15026                                                final long iax = it.aLong;
    15027                                                final long ibx = it.bLong;
    15028                                                byte ox;
    15029                                                ox = (byte) (iax ^ ibx);
    15030                                                oai8data[it.oIndex] = ox;
    15031                                        }
    15032                                }
    15033                        } else if (as < bs) {
    15034                                {
    15035                                        while (it.hasNext()) {
    15036                                                final long iax = it.aLong;
    15037                                                long ibx = it.bLong;
    15038                                                byte ox;
    15039                                                ox = (byte) (iax ^ ibx);
    15040                                                oai8data[it.oIndex] = ox;
    15041                                                for (int j = 1; j < is; j++) {
    15042                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15043                                                        ox = (byte) (iax ^ ibx);
    15044                                                        oai8data[it.oIndex + j] = ox;
    15045                                                }
    15046                                        }
    15047                                }
    15048                        } else if (as > bs) {
    15049                                {
    15050                                        while (it.hasNext()) {
    15051                                                long iax = it.aLong;
    15052                                                final long ibx = it.bLong;
    15053                                                byte ox;
    15054                                                ox = (byte) (iax ^ ibx);
    15055                                                oai8data[it.oIndex] = ox;
    15056                                                for (int j = 1; j < is; j++) {
    15057                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15058                                                        ox = (byte) (iax ^ ibx);
    15059                                                        oai8data[it.oIndex + j] = ox;
    15060                                                }
    15061                                        }
    15062                                }
    15063                        } else if (as == 1) {
    15064                                {
    15065                                        while (it.hasNext()) {
    15066                                                final long iax = it.aLong;
    15067                                                final long ibx = it.bLong;
    15068                                                byte ox;
    15069                                                ox = (byte) (iax ^ ibx);
    15070                                                for (int j = 0; j < is; j++) {
    15071                                                        oai8data[it.oIndex + j] = ox;
    15072                                                }
    15073                                        }
    15074                                }
    15075                        } else {
    15076                                {
    15077                                        while (it.hasNext()) {
    15078                                                long iax = it.aLong;
    15079                                                long ibx = it.bLong;
    15080                                                byte ox;
    15081                                                ox = (byte) (iax ^ ibx);
    15082                                                oai8data[it.oIndex] = ox;
    15083                                                for (int j = 1; j < is; j++) {
    15084                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15085                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15086                                                        ox = (byte) (iax ^ ibx);
    15087                                                        oai8data[it.oIndex + j] = ox;
    15088                                                }
    15089                                        }
    15090                                }
    15091                        }
    15092                        break;
    15093                case Dataset.ARRAYINT16:
    15094                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    15095                        if (is == 1) {
    15096                                {
    15097                                        while (it.hasNext()) {
    15098                                                final long iax = it.aLong;
    15099                                                final long ibx = it.bLong;
    15100                                                short ox;
    15101                                                ox = (short) (iax ^ ibx);
    15102                                                oai16data[it.oIndex] = ox;
    15103                                        }
    15104                                }
    15105                        } else if (as < bs) {
    15106                                {
    15107                                        while (it.hasNext()) {
    15108                                                final long iax = it.aLong;
    15109                                                long ibx = it.bLong;
    15110                                                short ox;
    15111                                                ox = (short) (iax ^ ibx);
    15112                                                oai16data[it.oIndex] = ox;
    15113                                                for (int j = 1; j < is; j++) {
    15114                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15115                                                        ox = (short) (iax ^ ibx);
    15116                                                        oai16data[it.oIndex + j] = ox;
    15117                                                }
    15118                                        }
    15119                                }
    15120                        } else if (as > bs) {
    15121                                {
    15122                                        while (it.hasNext()) {
    15123                                                long iax = it.aLong;
    15124                                                final long ibx = it.bLong;
    15125                                                short ox;
    15126                                                ox = (short) (iax ^ ibx);
    15127                                                oai16data[it.oIndex] = ox;
    15128                                                for (int j = 1; j < is; j++) {
    15129                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15130                                                        ox = (short) (iax ^ ibx);
    15131                                                        oai16data[it.oIndex + j] = ox;
    15132                                                }
    15133                                        }
    15134                                }
    15135                        } else if (as == 1) {
    15136                                {
    15137                                        while (it.hasNext()) {
    15138                                                final long iax = it.aLong;
    15139                                                final long ibx = it.bLong;
    15140                                                short ox;
    15141                                                ox = (short) (iax ^ ibx);
    15142                                                for (int j = 0; j < is; j++) {
    15143                                                        oai16data[it.oIndex + j] = ox;
    15144                                                }
    15145                                        }
    15146                                }
    15147                        } else {
    15148                                {
    15149                                        while (it.hasNext()) {
    15150                                                long iax = it.aLong;
    15151                                                long ibx = it.bLong;
    15152                                                short ox;
    15153                                                ox = (short) (iax ^ ibx);
    15154                                                oai16data[it.oIndex] = ox;
    15155                                                for (int j = 1; j < is; j++) {
    15156                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15157                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15158                                                        ox = (short) (iax ^ ibx);
    15159                                                        oai16data[it.oIndex + j] = ox;
    15160                                                }
    15161                                        }
    15162                                }
    15163                        }
    15164                        break;
    15165                case Dataset.ARRAYINT64:
    15166                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    15167                        if (is == 1) {
    15168                                {
    15169                                        while (it.hasNext()) {
    15170                                                final long iax = it.aLong;
    15171                                                final long ibx = it.bLong;
    15172                                                long ox;
    15173                                                ox = (iax ^ ibx);
    15174                                                oai64data[it.oIndex] = ox;
    15175                                        }
    15176                                }
    15177                        } else if (as < bs) {
    15178                                {
    15179                                        while (it.hasNext()) {
    15180                                                final long iax = it.aLong;
    15181                                                long ibx = it.bLong;
    15182                                                long ox;
    15183                                                ox = (iax ^ ibx);
    15184                                                oai64data[it.oIndex] = ox;
    15185                                                for (int j = 1; j < is; j++) {
    15186                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15187                                                        ox = (iax ^ ibx);
    15188                                                        oai64data[it.oIndex + j] = ox;
    15189                                                }
    15190                                        }
    15191                                }
    15192                        } else if (as > bs) {
    15193                                {
    15194                                        while (it.hasNext()) {
    15195                                                long iax = it.aLong;
    15196                                                final long ibx = it.bLong;
    15197                                                long ox;
    15198                                                ox = (iax ^ ibx);
    15199                                                oai64data[it.oIndex] = ox;
    15200                                                for (int j = 1; j < is; j++) {
    15201                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15202                                                        ox = (iax ^ ibx);
    15203                                                        oai64data[it.oIndex + j] = ox;
    15204                                                }
    15205                                        }
    15206                                }
    15207                        } else if (as == 1) {
    15208                                {
    15209                                        while (it.hasNext()) {
    15210                                                final long iax = it.aLong;
    15211                                                final long ibx = it.bLong;
    15212                                                long ox;
    15213                                                ox = (iax ^ ibx);
    15214                                                for (int j = 0; j < is; j++) {
    15215                                                        oai64data[it.oIndex + j] = ox;
    15216                                                }
    15217                                        }
    15218                                }
    15219                        } else {
    15220                                {
    15221                                        while (it.hasNext()) {
    15222                                                long iax = it.aLong;
    15223                                                long ibx = it.bLong;
    15224                                                long ox;
    15225                                                ox = (iax ^ ibx);
    15226                                                oai64data[it.oIndex] = ox;
    15227                                                for (int j = 1; j < is; j++) {
    15228                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15229                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15230                                                        ox = (iax ^ ibx);
    15231                                                        oai64data[it.oIndex + j] = ox;
    15232                                                }
    15233                                        }
    15234                                }
    15235                        }
    15236                        break;
    15237                case Dataset.ARRAYINT32:
    15238                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    15239                        if (is == 1) {
    15240                                {
    15241                                        while (it.hasNext()) {
    15242                                                final long iax = it.aLong;
    15243                                                final long ibx = it.bLong;
    15244                                                int ox;
    15245                                                ox = (int) (iax ^ ibx);
    15246                                                oai32data[it.oIndex] = ox;
    15247                                        }
    15248                                }
    15249                        } else if (as < bs) {
    15250                                {
    15251                                        while (it.hasNext()) {
    15252                                                final long iax = it.aLong;
    15253                                                long ibx = it.bLong;
    15254                                                int ox;
    15255                                                ox = (int) (iax ^ ibx);
    15256                                                oai32data[it.oIndex] = ox;
    15257                                                for (int j = 1; j < is; j++) {
    15258                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15259                                                        ox = (int) (iax ^ ibx);
    15260                                                        oai32data[it.oIndex + j] = ox;
    15261                                                }
    15262                                        }
    15263                                }
    15264                        } else if (as > bs) {
    15265                                {
    15266                                        while (it.hasNext()) {
    15267                                                long iax = it.aLong;
    15268                                                final long ibx = it.bLong;
    15269                                                int ox;
    15270                                                ox = (int) (iax ^ ibx);
    15271                                                oai32data[it.oIndex] = ox;
    15272                                                for (int j = 1; j < is; j++) {
    15273                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15274                                                        ox = (int) (iax ^ ibx);
    15275                                                        oai32data[it.oIndex + j] = ox;
    15276                                                }
    15277                                        }
    15278                                }
    15279                        } else if (as == 1) {
    15280                                {
    15281                                        while (it.hasNext()) {
    15282                                                final long iax = it.aLong;
    15283                                                final long ibx = it.bLong;
    15284                                                int ox;
    15285                                                ox = (int) (iax ^ ibx);
    15286                                                for (int j = 0; j < is; j++) {
    15287                                                        oai32data[it.oIndex + j] = ox;
    15288                                                }
    15289                                        }
    15290                                }
    15291                        } else {
    15292                                {
    15293                                        while (it.hasNext()) {
    15294                                                long iax = it.aLong;
    15295                                                long ibx = it.bLong;
    15296                                                int ox;
    15297                                                ox = (int) (iax ^ ibx);
    15298                                                oai32data[it.oIndex] = ox;
    15299                                                for (int j = 1; j < is; j++) {
    15300                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15301                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15302                                                        ox = (int) (iax ^ ibx);
    15303                                                        oai32data[it.oIndex + j] = ox;
    15304                                                }
    15305                                        }
    15306                                }
    15307                        }
    15308                        break;
    15309                default:
    15310                        throw new IllegalArgumentException("bitwiseXor supports integer, compound integer datasets only");
    15311                }
    15312
    15313                addBinaryOperatorName(da, db, result, "^");
    15314                return result;
    15315        }
    15316
    15317        /**
    15318         * leftShift operator
    15319         * @param a
    15320         * @param b
    15321         * @return {@code a << b}, bitwise left shift of a by b
    15322         */
    15323        public static Dataset leftShift(final Object a, final Object b) {
    15324                return leftShift(a, b, null);
    15325        }
    15326
    15327        /**
    15328         * leftShift operator
    15329         * @param a
    15330         * @param b
    15331         * @param o output can be null - in which case, a new dataset is created
    15332         * @return {@code a << b}, bitwise left shift of a by b
    15333         */
    15334        public static Dataset leftShift(final Object a, final Object b, final Dataset o) {
    15335                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    15336                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    15337                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    15338                it.setOutputDouble(false);
    15339                final Dataset result = it.getOutput();
    15340                final int is = result.getElementsPerItem();
    15341                final int as = da.getElementsPerItem();
    15342                final int bs = db.getElementsPerItem();
    15343                final int dt = result.getDType();
    15344
    15345                switch(dt) {
    15346                case Dataset.INT8:
    15347                        final byte[] oi8data = ((ByteDataset) result).getData();
    15348                        {
    15349                                while (it.hasNext()) {
    15350                                        final long iax = it.aLong;
    15351                                        final long ibx = it.bLong;
    15352                                        byte ox;
    15353                                        ox = (byte) (iax << ibx);
    15354                                        oi8data[it.oIndex] = ox;
    15355                                }
    15356                        }
    15357                        break;
    15358                case Dataset.INT16:
    15359                        final short[] oi16data = ((ShortDataset) result).getData();
    15360                        {
    15361                                while (it.hasNext()) {
    15362                                        final long iax = it.aLong;
    15363                                        final long ibx = it.bLong;
    15364                                        short ox;
    15365                                        ox = (short) (iax << ibx);
    15366                                        oi16data[it.oIndex] = ox;
    15367                                }
    15368                        }
    15369                        break;
    15370                case Dataset.INT64:
    15371                        final long[] oi64data = ((LongDataset) result).getData();
    15372                        {
    15373                                while (it.hasNext()) {
    15374                                        final long iax = it.aLong;
    15375                                        final long ibx = it.bLong;
    15376                                        long ox;
    15377                                        ox = (iax << ibx);
    15378                                        oi64data[it.oIndex] = ox;
    15379                                }
    15380                        }
    15381                        break;
    15382                case Dataset.INT32:
    15383                        final int[] oi32data = ((IntegerDataset) result).getData();
    15384                        {
    15385                                while (it.hasNext()) {
    15386                                        final long iax = it.aLong;
    15387                                        final long ibx = it.bLong;
    15388                                        int ox;
    15389                                        ox = (int) (iax << ibx);
    15390                                        oi32data[it.oIndex] = ox;
    15391                                }
    15392                        }
    15393                        break;
    15394                case Dataset.ARRAYINT8:
    15395                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    15396                        if (is == 1) {
    15397                                {
    15398                                        while (it.hasNext()) {
    15399                                                final long iax = it.aLong;
    15400                                                final long ibx = it.bLong;
    15401                                                byte ox;
    15402                                                ox = (byte) (iax << ibx);
    15403                                                oai8data[it.oIndex] = ox;
    15404                                        }
    15405                                }
    15406                        } else if (as < bs) {
    15407                                {
    15408                                        while (it.hasNext()) {
    15409                                                final long iax = it.aLong;
    15410                                                long ibx = it.bLong;
    15411                                                byte ox;
    15412                                                ox = (byte) (iax << ibx);
    15413                                                oai8data[it.oIndex] = ox;
    15414                                                for (int j = 1; j < is; j++) {
    15415                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15416                                                        ox = (byte) (iax << ibx);
    15417                                                        oai8data[it.oIndex + j] = ox;
    15418                                                }
    15419                                        }
    15420                                }
    15421                        } else if (as > bs) {
    15422                                {
    15423                                        while (it.hasNext()) {
    15424                                                long iax = it.aLong;
    15425                                                final long ibx = it.bLong;
    15426                                                byte ox;
    15427                                                ox = (byte) (iax << ibx);
    15428                                                oai8data[it.oIndex] = ox;
    15429                                                for (int j = 1; j < is; j++) {
    15430                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15431                                                        ox = (byte) (iax << ibx);
    15432                                                        oai8data[it.oIndex + j] = ox;
    15433                                                }
    15434                                        }
    15435                                }
    15436                        } else if (as == 1) {
    15437                                {
    15438                                        while (it.hasNext()) {
    15439                                                final long iax = it.aLong;
    15440                                                final long ibx = it.bLong;
    15441                                                byte ox;
    15442                                                ox = (byte) (iax << ibx);
    15443                                                for (int j = 0; j < is; j++) {
    15444                                                        oai8data[it.oIndex + j] = ox;
    15445                                                }
    15446                                        }
    15447                                }
    15448                        } else {
    15449                                {
    15450                                        while (it.hasNext()) {
    15451                                                long iax = it.aLong;
    15452                                                long ibx = it.bLong;
    15453                                                byte ox;
    15454                                                ox = (byte) (iax << ibx);
    15455                                                oai8data[it.oIndex] = ox;
    15456                                                for (int j = 1; j < is; j++) {
    15457                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15458                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15459                                                        ox = (byte) (iax << ibx);
    15460                                                        oai8data[it.oIndex + j] = ox;
    15461                                                }
    15462                                        }
    15463                                }
    15464                        }
    15465                        break;
    15466                case Dataset.ARRAYINT16:
    15467                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    15468                        if (is == 1) {
    15469                                {
    15470                                        while (it.hasNext()) {
    15471                                                final long iax = it.aLong;
    15472                                                final long ibx = it.bLong;
    15473                                                short ox;
    15474                                                ox = (short) (iax << ibx);
    15475                                                oai16data[it.oIndex] = ox;
    15476                                        }
    15477                                }
    15478                        } else if (as < bs) {
    15479                                {
    15480                                        while (it.hasNext()) {
    15481                                                final long iax = it.aLong;
    15482                                                long ibx = it.bLong;
    15483                                                short ox;
    15484                                                ox = (short) (iax << ibx);
    15485                                                oai16data[it.oIndex] = ox;
    15486                                                for (int j = 1; j < is; j++) {
    15487                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15488                                                        ox = (short) (iax << ibx);
    15489                                                        oai16data[it.oIndex + j] = ox;
    15490                                                }
    15491                                        }
    15492                                }
    15493                        } else if (as > bs) {
    15494                                {
    15495                                        while (it.hasNext()) {
    15496                                                long iax = it.aLong;
    15497                                                final long ibx = it.bLong;
    15498                                                short ox;
    15499                                                ox = (short) (iax << ibx);
    15500                                                oai16data[it.oIndex] = ox;
    15501                                                for (int j = 1; j < is; j++) {
    15502                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15503                                                        ox = (short) (iax << ibx);
    15504                                                        oai16data[it.oIndex + j] = ox;
    15505                                                }
    15506                                        }
    15507                                }
    15508                        } else if (as == 1) {
    15509                                {
    15510                                        while (it.hasNext()) {
    15511                                                final long iax = it.aLong;
    15512                                                final long ibx = it.bLong;
    15513                                                short ox;
    15514                                                ox = (short) (iax << ibx);
    15515                                                for (int j = 0; j < is; j++) {
    15516                                                        oai16data[it.oIndex + j] = ox;
    15517                                                }
    15518                                        }
    15519                                }
    15520                        } else {
    15521                                {
    15522                                        while (it.hasNext()) {
    15523                                                long iax = it.aLong;
    15524                                                long ibx = it.bLong;
    15525                                                short ox;
    15526                                                ox = (short) (iax << ibx);
    15527                                                oai16data[it.oIndex] = ox;
    15528                                                for (int j = 1; j < is; j++) {
    15529                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15530                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15531                                                        ox = (short) (iax << ibx);
    15532                                                        oai16data[it.oIndex + j] = ox;
    15533                                                }
    15534                                        }
    15535                                }
    15536                        }
    15537                        break;
    15538                case Dataset.ARRAYINT64:
    15539                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    15540                        if (is == 1) {
    15541                                {
    15542                                        while (it.hasNext()) {
    15543                                                final long iax = it.aLong;
    15544                                                final long ibx = it.bLong;
    15545                                                long ox;
    15546                                                ox = (iax << ibx);
    15547                                                oai64data[it.oIndex] = ox;
    15548                                        }
    15549                                }
    15550                        } else if (as < bs) {
    15551                                {
    15552                                        while (it.hasNext()) {
    15553                                                final long iax = it.aLong;
    15554                                                long ibx = it.bLong;
    15555                                                long ox;
    15556                                                ox = (iax << ibx);
    15557                                                oai64data[it.oIndex] = ox;
    15558                                                for (int j = 1; j < is; j++) {
    15559                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15560                                                        ox = (iax << ibx);
    15561                                                        oai64data[it.oIndex + j] = ox;
    15562                                                }
    15563                                        }
    15564                                }
    15565                        } else if (as > bs) {
    15566                                {
    15567                                        while (it.hasNext()) {
    15568                                                long iax = it.aLong;
    15569                                                final long ibx = it.bLong;
    15570                                                long ox;
    15571                                                ox = (iax << ibx);
    15572                                                oai64data[it.oIndex] = ox;
    15573                                                for (int j = 1; j < is; j++) {
    15574                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15575                                                        ox = (iax << ibx);
    15576                                                        oai64data[it.oIndex + j] = ox;
    15577                                                }
    15578                                        }
    15579                                }
    15580                        } else if (as == 1) {
    15581                                {
    15582                                        while (it.hasNext()) {
    15583                                                final long iax = it.aLong;
    15584                                                final long ibx = it.bLong;
    15585                                                long ox;
    15586                                                ox = (iax << ibx);
    15587                                                for (int j = 0; j < is; j++) {
    15588                                                        oai64data[it.oIndex + j] = ox;
    15589                                                }
    15590                                        }
    15591                                }
    15592                        } else {
    15593                                {
    15594                                        while (it.hasNext()) {
    15595                                                long iax = it.aLong;
    15596                                                long ibx = it.bLong;
    15597                                                long ox;
    15598                                                ox = (iax << ibx);
    15599                                                oai64data[it.oIndex] = ox;
    15600                                                for (int j = 1; j < is; j++) {
    15601                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15602                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15603                                                        ox = (iax << ibx);
    15604                                                        oai64data[it.oIndex + j] = ox;
    15605                                                }
    15606                                        }
    15607                                }
    15608                        }
    15609                        break;
    15610                case Dataset.ARRAYINT32:
    15611                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    15612                        if (is == 1) {
    15613                                {
    15614                                        while (it.hasNext()) {
    15615                                                final long iax = it.aLong;
    15616                                                final long ibx = it.bLong;
    15617                                                int ox;
    15618                                                ox = (int) (iax << ibx);
    15619                                                oai32data[it.oIndex] = ox;
    15620                                        }
    15621                                }
    15622                        } else if (as < bs) {
    15623                                {
    15624                                        while (it.hasNext()) {
    15625                                                final long iax = it.aLong;
    15626                                                long ibx = it.bLong;
    15627                                                int ox;
    15628                                                ox = (int) (iax << ibx);
    15629                                                oai32data[it.oIndex] = ox;
    15630                                                for (int j = 1; j < is; j++) {
    15631                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15632                                                        ox = (int) (iax << ibx);
    15633                                                        oai32data[it.oIndex + j] = ox;
    15634                                                }
    15635                                        }
    15636                                }
    15637                        } else if (as > bs) {
    15638                                {
    15639                                        while (it.hasNext()) {
    15640                                                long iax = it.aLong;
    15641                                                final long ibx = it.bLong;
    15642                                                int ox;
    15643                                                ox = (int) (iax << ibx);
    15644                                                oai32data[it.oIndex] = ox;
    15645                                                for (int j = 1; j < is; j++) {
    15646                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15647                                                        ox = (int) (iax << ibx);
    15648                                                        oai32data[it.oIndex + j] = ox;
    15649                                                }
    15650                                        }
    15651                                }
    15652                        } else if (as == 1) {
    15653                                {
    15654                                        while (it.hasNext()) {
    15655                                                final long iax = it.aLong;
    15656                                                final long ibx = it.bLong;
    15657                                                int ox;
    15658                                                ox = (int) (iax << ibx);
    15659                                                for (int j = 0; j < is; j++) {
    15660                                                        oai32data[it.oIndex + j] = ox;
    15661                                                }
    15662                                        }
    15663                                }
    15664                        } else {
    15665                                {
    15666                                        while (it.hasNext()) {
    15667                                                long iax = it.aLong;
    15668                                                long ibx = it.bLong;
    15669                                                int ox;
    15670                                                ox = (int) (iax << ibx);
    15671                                                oai32data[it.oIndex] = ox;
    15672                                                for (int j = 1; j < is; j++) {
    15673                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15674                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15675                                                        ox = (int) (iax << ibx);
    15676                                                        oai32data[it.oIndex + j] = ox;
    15677                                                }
    15678                                        }
    15679                                }
    15680                        }
    15681                        break;
    15682                default:
    15683                        throw new IllegalArgumentException("leftShift supports integer, compound integer datasets only");
    15684                }
    15685
    15686                addBinaryOperatorName(da, db, result, "<<");
    15687                return result;
    15688        }
    15689
    15690        /**
    15691         * rightShift operator
    15692         * @param a
    15693         * @param b
    15694         * @return {@code a >> b}, bitwise right shift of a by b
    15695         */
    15696        public static Dataset rightShift(final Object a, final Object b) {
    15697                return rightShift(a, b, null);
    15698        }
    15699
    15700        /**
    15701         * rightShift operator
    15702         * @param a
    15703         * @param b
    15704         * @param o output can be null - in which case, a new dataset is created
    15705         * @return {@code a >> b}, bitwise right shift of a by b
    15706         */
    15707        public static Dataset rightShift(final Object a, final Object b, final Dataset o) {
    15708                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    15709                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    15710                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    15711                it.setOutputDouble(false);
    15712                final Dataset result = it.getOutput();
    15713                final int is = result.getElementsPerItem();
    15714                final int as = da.getElementsPerItem();
    15715                final int bs = db.getElementsPerItem();
    15716                final int dt = result.getDType();
    15717
    15718                switch(dt) {
    15719                case Dataset.INT8:
    15720                        final byte[] oi8data = ((ByteDataset) result).getData();
    15721                        {
    15722                                while (it.hasNext()) {
    15723                                        final long iax = it.aLong;
    15724                                        final long ibx = it.bLong;
    15725                                        byte ox;
    15726                                        ox = (byte) (iax >> ibx);
    15727                                        oi8data[it.oIndex] = ox;
    15728                                }
    15729                        }
    15730                        break;
    15731                case Dataset.INT16:
    15732                        final short[] oi16data = ((ShortDataset) result).getData();
    15733                        {
    15734                                while (it.hasNext()) {
    15735                                        final long iax = it.aLong;
    15736                                        final long ibx = it.bLong;
    15737                                        short ox;
    15738                                        ox = (short) (iax >> ibx);
    15739                                        oi16data[it.oIndex] = ox;
    15740                                }
    15741                        }
    15742                        break;
    15743                case Dataset.INT64:
    15744                        final long[] oi64data = ((LongDataset) result).getData();
    15745                        {
    15746                                while (it.hasNext()) {
    15747                                        final long iax = it.aLong;
    15748                                        final long ibx = it.bLong;
    15749                                        long ox;
    15750                                        ox = (iax >> ibx);
    15751                                        oi64data[it.oIndex] = ox;
    15752                                }
    15753                        }
    15754                        break;
    15755                case Dataset.INT32:
    15756                        final int[] oi32data = ((IntegerDataset) result).getData();
    15757                        {
    15758                                while (it.hasNext()) {
    15759                                        final long iax = it.aLong;
    15760                                        final long ibx = it.bLong;
    15761                                        int ox;
    15762                                        ox = (int) (iax >> ibx);
    15763                                        oi32data[it.oIndex] = ox;
    15764                                }
    15765                        }
    15766                        break;
    15767                case Dataset.ARRAYINT8:
    15768                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    15769                        if (is == 1) {
    15770                                {
    15771                                        while (it.hasNext()) {
    15772                                                final long iax = it.aLong;
    15773                                                final long ibx = it.bLong;
    15774                                                byte ox;
    15775                                                ox = (byte) (iax >> ibx);
    15776                                                oai8data[it.oIndex] = ox;
    15777                                        }
    15778                                }
    15779                        } else if (as < bs) {
    15780                                {
    15781                                        while (it.hasNext()) {
    15782                                                final long iax = it.aLong;
    15783                                                long ibx = it.bLong;
    15784                                                byte ox;
    15785                                                ox = (byte) (iax >> ibx);
    15786                                                oai8data[it.oIndex] = ox;
    15787                                                for (int j = 1; j < is; j++) {
    15788                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15789                                                        ox = (byte) (iax >> ibx);
    15790                                                        oai8data[it.oIndex + j] = ox;
    15791                                                }
    15792                                        }
    15793                                }
    15794                        } else if (as > bs) {
    15795                                {
    15796                                        while (it.hasNext()) {
    15797                                                long iax = it.aLong;
    15798                                                final long ibx = it.bLong;
    15799                                                byte ox;
    15800                                                ox = (byte) (iax >> ibx);
    15801                                                oai8data[it.oIndex] = ox;
    15802                                                for (int j = 1; j < is; j++) {
    15803                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15804                                                        ox = (byte) (iax >> ibx);
    15805                                                        oai8data[it.oIndex + j] = ox;
    15806                                                }
    15807                                        }
    15808                                }
    15809                        } else if (as == 1) {
    15810                                {
    15811                                        while (it.hasNext()) {
    15812                                                final long iax = it.aLong;
    15813                                                final long ibx = it.bLong;
    15814                                                byte ox;
    15815                                                ox = (byte) (iax >> ibx);
    15816                                                for (int j = 0; j < is; j++) {
    15817                                                        oai8data[it.oIndex + j] = ox;
    15818                                                }
    15819                                        }
    15820                                }
    15821                        } else {
    15822                                {
    15823                                        while (it.hasNext()) {
    15824                                                long iax = it.aLong;
    15825                                                long ibx = it.bLong;
    15826                                                byte ox;
    15827                                                ox = (byte) (iax >> ibx);
    15828                                                oai8data[it.oIndex] = ox;
    15829                                                for (int j = 1; j < is; j++) {
    15830                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15831                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15832                                                        ox = (byte) (iax >> ibx);
    15833                                                        oai8data[it.oIndex + j] = ox;
    15834                                                }
    15835                                        }
    15836                                }
    15837                        }
    15838                        break;
    15839                case Dataset.ARRAYINT16:
    15840                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    15841                        if (is == 1) {
    15842                                {
    15843                                        while (it.hasNext()) {
    15844                                                final long iax = it.aLong;
    15845                                                final long ibx = it.bLong;
    15846                                                short ox;
    15847                                                ox = (short) (iax >> ibx);
    15848                                                oai16data[it.oIndex] = ox;
    15849                                        }
    15850                                }
    15851                        } else if (as < bs) {
    15852                                {
    15853                                        while (it.hasNext()) {
    15854                                                final long iax = it.aLong;
    15855                                                long ibx = it.bLong;
    15856                                                short ox;
    15857                                                ox = (short) (iax >> ibx);
    15858                                                oai16data[it.oIndex] = ox;
    15859                                                for (int j = 1; j < is; j++) {
    15860                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15861                                                        ox = (short) (iax >> ibx);
    15862                                                        oai16data[it.oIndex + j] = ox;
    15863                                                }
    15864                                        }
    15865                                }
    15866                        } else if (as > bs) {
    15867                                {
    15868                                        while (it.hasNext()) {
    15869                                                long iax = it.aLong;
    15870                                                final long ibx = it.bLong;
    15871                                                short ox;
    15872                                                ox = (short) (iax >> ibx);
    15873                                                oai16data[it.oIndex] = ox;
    15874                                                for (int j = 1; j < is; j++) {
    15875                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15876                                                        ox = (short) (iax >> ibx);
    15877                                                        oai16data[it.oIndex + j] = ox;
    15878                                                }
    15879                                        }
    15880                                }
    15881                        } else if (as == 1) {
    15882                                {
    15883                                        while (it.hasNext()) {
    15884                                                final long iax = it.aLong;
    15885                                                final long ibx = it.bLong;
    15886                                                short ox;
    15887                                                ox = (short) (iax >> ibx);
    15888                                                for (int j = 0; j < is; j++) {
    15889                                                        oai16data[it.oIndex + j] = ox;
    15890                                                }
    15891                                        }
    15892                                }
    15893                        } else {
    15894                                {
    15895                                        while (it.hasNext()) {
    15896                                                long iax = it.aLong;
    15897                                                long ibx = it.bLong;
    15898                                                short ox;
    15899                                                ox = (short) (iax >> ibx);
    15900                                                oai16data[it.oIndex] = ox;
    15901                                                for (int j = 1; j < is; j++) {
    15902                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15903                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15904                                                        ox = (short) (iax >> ibx);
    15905                                                        oai16data[it.oIndex + j] = ox;
    15906                                                }
    15907                                        }
    15908                                }
    15909                        }
    15910                        break;
    15911                case Dataset.ARRAYINT64:
    15912                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    15913                        if (is == 1) {
    15914                                {
    15915                                        while (it.hasNext()) {
    15916                                                final long iax = it.aLong;
    15917                                                final long ibx = it.bLong;
    15918                                                long ox;
    15919                                                ox = (iax >> ibx);
    15920                                                oai64data[it.oIndex] = ox;
    15921                                        }
    15922                                }
    15923                        } else if (as < bs) {
    15924                                {
    15925                                        while (it.hasNext()) {
    15926                                                final long iax = it.aLong;
    15927                                                long ibx = it.bLong;
    15928                                                long ox;
    15929                                                ox = (iax >> ibx);
    15930                                                oai64data[it.oIndex] = ox;
    15931                                                for (int j = 1; j < is; j++) {
    15932                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15933                                                        ox = (iax >> ibx);
    15934                                                        oai64data[it.oIndex + j] = ox;
    15935                                                }
    15936                                        }
    15937                                }
    15938                        } else if (as > bs) {
    15939                                {
    15940                                        while (it.hasNext()) {
    15941                                                long iax = it.aLong;
    15942                                                final long ibx = it.bLong;
    15943                                                long ox;
    15944                                                ox = (iax >> ibx);
    15945                                                oai64data[it.oIndex] = ox;
    15946                                                for (int j = 1; j < is; j++) {
    15947                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15948                                                        ox = (iax >> ibx);
    15949                                                        oai64data[it.oIndex + j] = ox;
    15950                                                }
    15951                                        }
    15952                                }
    15953                        } else if (as == 1) {
    15954                                {
    15955                                        while (it.hasNext()) {
    15956                                                final long iax = it.aLong;
    15957                                                final long ibx = it.bLong;
    15958                                                long ox;
    15959                                                ox = (iax >> ibx);
    15960                                                for (int j = 0; j < is; j++) {
    15961                                                        oai64data[it.oIndex + j] = ox;
    15962                                                }
    15963                                        }
    15964                                }
    15965                        } else {
    15966                                {
    15967                                        while (it.hasNext()) {
    15968                                                long iax = it.aLong;
    15969                                                long ibx = it.bLong;
    15970                                                long ox;
    15971                                                ox = (iax >> ibx);
    15972                                                oai64data[it.oIndex] = ox;
    15973                                                for (int j = 1; j < is; j++) {
    15974                                                        iax = da.getElementLongAbs(it.aIndex + j);
    15975                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    15976                                                        ox = (iax >> ibx);
    15977                                                        oai64data[it.oIndex + j] = ox;
    15978                                                }
    15979                                        }
    15980                                }
    15981                        }
    15982                        break;
    15983                case Dataset.ARRAYINT32:
    15984                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    15985                        if (is == 1) {
    15986                                {
    15987                                        while (it.hasNext()) {
    15988                                                final long iax = it.aLong;
    15989                                                final long ibx = it.bLong;
    15990                                                int ox;
    15991                                                ox = (int) (iax >> ibx);
    15992                                                oai32data[it.oIndex] = ox;
    15993                                        }
    15994                                }
    15995                        } else if (as < bs) {
    15996                                {
    15997                                        while (it.hasNext()) {
    15998                                                final long iax = it.aLong;
    15999                                                long ibx = it.bLong;
    16000                                                int ox;
    16001                                                ox = (int) (iax >> ibx);
    16002                                                oai32data[it.oIndex] = ox;
    16003                                                for (int j = 1; j < is; j++) {
    16004                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16005                                                        ox = (int) (iax >> ibx);
    16006                                                        oai32data[it.oIndex + j] = ox;
    16007                                                }
    16008                                        }
    16009                                }
    16010                        } else if (as > bs) {
    16011                                {
    16012                                        while (it.hasNext()) {
    16013                                                long iax = it.aLong;
    16014                                                final long ibx = it.bLong;
    16015                                                int ox;
    16016                                                ox = (int) (iax >> ibx);
    16017                                                oai32data[it.oIndex] = ox;
    16018                                                for (int j = 1; j < is; j++) {
    16019                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16020                                                        ox = (int) (iax >> ibx);
    16021                                                        oai32data[it.oIndex + j] = ox;
    16022                                                }
    16023                                        }
    16024                                }
    16025                        } else if (as == 1) {
    16026                                {
    16027                                        while (it.hasNext()) {
    16028                                                final long iax = it.aLong;
    16029                                                final long ibx = it.bLong;
    16030                                                int ox;
    16031                                                ox = (int) (iax >> ibx);
    16032                                                for (int j = 0; j < is; j++) {
    16033                                                        oai32data[it.oIndex + j] = ox;
    16034                                                }
    16035                                        }
    16036                                }
    16037                        } else {
    16038                                {
    16039                                        while (it.hasNext()) {
    16040                                                long iax = it.aLong;
    16041                                                long ibx = it.bLong;
    16042                                                int ox;
    16043                                                ox = (int) (iax >> ibx);
    16044                                                oai32data[it.oIndex] = ox;
    16045                                                for (int j = 1; j < is; j++) {
    16046                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16047                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16048                                                        ox = (int) (iax >> ibx);
    16049                                                        oai32data[it.oIndex + j] = ox;
    16050                                                }
    16051                                        }
    16052                                }
    16053                        }
    16054                        break;
    16055                default:
    16056                        throw new IllegalArgumentException("rightShift supports integer, compound integer datasets only");
    16057                }
    16058
    16059                addBinaryOperatorName(da, db, result, ">>");
    16060                return result;
    16061        }
    16062
    16063        /**
    16064         * unsignedRightShift operator
    16065         * @param a
    16066         * @param b
    16067         * @return {@code a >>> b}, bitwise right shift of a by b with zeros added
    16068         */
    16069        public static Dataset unsignedRightShift(final Object a, final Object b) {
    16070                return unsignedRightShift(a, b, null);
    16071        }
    16072
    16073        /**
    16074         * unsignedRightShift operator
    16075         * @param a
    16076         * @param b
    16077         * @param o output can be null - in which case, a new dataset is created
    16078         * @return {@code a >>> b}, bitwise right shift of a by b with zeros added
    16079         */
    16080        public static Dataset unsignedRightShift(final Object a, final Object b, final Dataset o) {
    16081                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    16082                final Dataset db = b instanceof Dataset ? (Dataset) b : DatasetFactory.createFromObject(b);
    16083                final BroadcastIterator it = BroadcastIterator.createIterator(da, db, o, true);
    16084                it.setOutputDouble(false);
    16085                final long unsignedMask;
    16086                final Dataset result = it.getOutput();
    16087                final int is = result.getElementsPerItem();
    16088                final int as = da.getElementsPerItem();
    16089                final int bs = db.getElementsPerItem();
    16090                final int dt = result.getDType();
    16091
    16092                switch(dt) {
    16093                case Dataset.INT8:
    16094                        final byte[] oi8data = ((ByteDataset) result).getData();
    16095                        unsignedMask = 0xffL;
    16096                        {
    16097                                while (it.hasNext()) {
    16098                                        final long iax = it.aLong;
    16099                                        final long ibx = it.bLong;
    16100                                        byte ox;
    16101                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
    16102                                        oi8data[it.oIndex] = ox;
    16103                                }
    16104                        }
    16105                        break;
    16106                case Dataset.INT16:
    16107                        final short[] oi16data = ((ShortDataset) result).getData();
    16108                        unsignedMask = 0xffffL;
    16109                        {
    16110                                while (it.hasNext()) {
    16111                                        final long iax = it.aLong;
    16112                                        final long ibx = it.bLong;
    16113                                        short ox;
    16114                                        ox = (short) ((unsignedMask & iax) >>> ibx);
    16115                                        oi16data[it.oIndex] = ox;
    16116                                }
    16117                        }
    16118                        break;
    16119                case Dataset.INT64:
    16120                        final long[] oi64data = ((LongDataset) result).getData();
    16121                        unsignedMask = 0xffffffffffffffffL;
    16122                        {
    16123                                while (it.hasNext()) {
    16124                                        final long iax = it.aLong;
    16125                                        final long ibx = it.bLong;
    16126                                        long ox;
    16127                                        ox = ((unsignedMask & iax) >>> ibx);
    16128                                        oi64data[it.oIndex] = ox;
    16129                                }
    16130                        }
    16131                        break;
    16132                case Dataset.INT32:
    16133                        final int[] oi32data = ((IntegerDataset) result).getData();
    16134                        unsignedMask = 0xffffffffL;
    16135                        {
    16136                                while (it.hasNext()) {
    16137                                        final long iax = it.aLong;
    16138                                        final long ibx = it.bLong;
    16139                                        int ox;
    16140                                        ox = (int) ((unsignedMask & iax) >>> ibx);
    16141                                        oi32data[it.oIndex] = ox;
    16142                                }
    16143                        }
    16144                        break;
    16145                case Dataset.ARRAYINT8:
    16146                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    16147                        unsignedMask = 0xffL;
    16148                        if (is == 1) {
    16149                                {
    16150                                        while (it.hasNext()) {
    16151                                                final long iax = it.aLong;
    16152                                                final long ibx = it.bLong;
    16153                                                byte ox;
    16154                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
    16155                                                oai8data[it.oIndex] = ox;
    16156                                        }
    16157                                }
    16158                        } else if (as < bs) {
    16159                                {
    16160                                        while (it.hasNext()) {
    16161                                                final long iax = it.aLong;
    16162                                                long ibx = it.bLong;
    16163                                                byte ox;
    16164                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
    16165                                                oai8data[it.oIndex] = ox;
    16166                                                for (int j = 1; j < is; j++) {
    16167                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16168                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
    16169                                                        oai8data[it.oIndex + j] = ox;
    16170                                                }
    16171                                        }
    16172                                }
    16173                        } else if (as > bs) {
    16174                                {
    16175                                        while (it.hasNext()) {
    16176                                                long iax = it.aLong;
    16177                                                final long ibx = it.bLong;
    16178                                                byte ox;
    16179                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
    16180                                                oai8data[it.oIndex] = ox;
    16181                                                for (int j = 1; j < is; j++) {
    16182                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16183                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
    16184                                                        oai8data[it.oIndex + j] = ox;
    16185                                                }
    16186                                        }
    16187                                }
    16188                        } else if (as == 1) {
    16189                                {
    16190                                        while (it.hasNext()) {
    16191                                                final long iax = it.aLong;
    16192                                                final long ibx = it.bLong;
    16193                                                byte ox;
    16194                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
    16195                                                for (int j = 0; j < is; j++) {
    16196                                                        oai8data[it.oIndex + j] = ox;
    16197                                                }
    16198                                        }
    16199                                }
    16200                        } else {
    16201                                {
    16202                                        while (it.hasNext()) {
    16203                                                long iax = it.aLong;
    16204                                                long ibx = it.bLong;
    16205                                                byte ox;
    16206                                                ox = (byte) ((unsignedMask & iax) >>> ibx);
    16207                                                oai8data[it.oIndex] = ox;
    16208                                                for (int j = 1; j < is; j++) {
    16209                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16210                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16211                                                        ox = (byte) ((unsignedMask & iax) >>> ibx);
    16212                                                        oai8data[it.oIndex + j] = ox;
    16213                                                }
    16214                                        }
    16215                                }
    16216                        }
    16217                        break;
    16218                case Dataset.ARRAYINT16:
    16219                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    16220                        unsignedMask = 0xffffL;
    16221                        if (is == 1) {
    16222                                {
    16223                                        while (it.hasNext()) {
    16224                                                final long iax = it.aLong;
    16225                                                final long ibx = it.bLong;
    16226                                                short ox;
    16227                                                ox = (short) ((unsignedMask & iax) >>> ibx);
    16228                                                oai16data[it.oIndex] = ox;
    16229                                        }
    16230                                }
    16231                        } else if (as < bs) {
    16232                                {
    16233                                        while (it.hasNext()) {
    16234                                                final long iax = it.aLong;
    16235                                                long ibx = it.bLong;
    16236                                                short ox;
    16237                                                ox = (short) ((unsignedMask & iax) >>> ibx);
    16238                                                oai16data[it.oIndex] = ox;
    16239                                                for (int j = 1; j < is; j++) {
    16240                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16241                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
    16242                                                        oai16data[it.oIndex + j] = ox;
    16243                                                }
    16244                                        }
    16245                                }
    16246                        } else if (as > bs) {
    16247                                {
    16248                                        while (it.hasNext()) {
    16249                                                long iax = it.aLong;
    16250                                                final long ibx = it.bLong;
    16251                                                short ox;
    16252                                                ox = (short) ((unsignedMask & iax) >>> ibx);
    16253                                                oai16data[it.oIndex] = ox;
    16254                                                for (int j = 1; j < is; j++) {
    16255                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16256                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
    16257                                                        oai16data[it.oIndex + j] = ox;
    16258                                                }
    16259                                        }
    16260                                }
    16261                        } else if (as == 1) {
    16262                                {
    16263                                        while (it.hasNext()) {
    16264                                                final long iax = it.aLong;
    16265                                                final long ibx = it.bLong;
    16266                                                short ox;
    16267                                                ox = (short) ((unsignedMask & iax) >>> ibx);
    16268                                                for (int j = 0; j < is; j++) {
    16269                                                        oai16data[it.oIndex + j] = ox;
    16270                                                }
    16271                                        }
    16272                                }
    16273                        } else {
    16274                                {
    16275                                        while (it.hasNext()) {
    16276                                                long iax = it.aLong;
    16277                                                long ibx = it.bLong;
    16278                                                short ox;
    16279                                                ox = (short) ((unsignedMask & iax) >>> ibx);
    16280                                                oai16data[it.oIndex] = ox;
    16281                                                for (int j = 1; j < is; j++) {
    16282                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16283                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16284                                                        ox = (short) ((unsignedMask & iax) >>> ibx);
    16285                                                        oai16data[it.oIndex + j] = ox;
    16286                                                }
    16287                                        }
    16288                                }
    16289                        }
    16290                        break;
    16291                case Dataset.ARRAYINT64:
    16292                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    16293                        unsignedMask = 0xffffffffffffffffL;
    16294                        if (is == 1) {
    16295                                {
    16296                                        while (it.hasNext()) {
    16297                                                final long iax = it.aLong;
    16298                                                final long ibx = it.bLong;
    16299                                                long ox;
    16300                                                ox = ((unsignedMask & iax) >>> ibx);
    16301                                                oai64data[it.oIndex] = ox;
    16302                                        }
    16303                                }
    16304                        } else if (as < bs) {
    16305                                {
    16306                                        while (it.hasNext()) {
    16307                                                final long iax = it.aLong;
    16308                                                long ibx = it.bLong;
    16309                                                long ox;
    16310                                                ox = ((unsignedMask & iax) >>> ibx);
    16311                                                oai64data[it.oIndex] = ox;
    16312                                                for (int j = 1; j < is; j++) {
    16313                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16314                                                        ox = ((unsignedMask & iax) >>> ibx);
    16315                                                        oai64data[it.oIndex + j] = ox;
    16316                                                }
    16317                                        }
    16318                                }
    16319                        } else if (as > bs) {
    16320                                {
    16321                                        while (it.hasNext()) {
    16322                                                long iax = it.aLong;
    16323                                                final long ibx = it.bLong;
    16324                                                long ox;
    16325                                                ox = ((unsignedMask & iax) >>> ibx);
    16326                                                oai64data[it.oIndex] = ox;
    16327                                                for (int j = 1; j < is; j++) {
    16328                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16329                                                        ox = ((unsignedMask & iax) >>> ibx);
    16330                                                        oai64data[it.oIndex + j] = ox;
    16331                                                }
    16332                                        }
    16333                                }
    16334                        } else if (as == 1) {
    16335                                {
    16336                                        while (it.hasNext()) {
    16337                                                final long iax = it.aLong;
    16338                                                final long ibx = it.bLong;
    16339                                                long ox;
    16340                                                ox = ((unsignedMask & iax) >>> ibx);
    16341                                                for (int j = 0; j < is; j++) {
    16342                                                        oai64data[it.oIndex + j] = ox;
    16343                                                }
    16344                                        }
    16345                                }
    16346                        } else {
    16347                                {
    16348                                        while (it.hasNext()) {
    16349                                                long iax = it.aLong;
    16350                                                long ibx = it.bLong;
    16351                                                long ox;
    16352                                                ox = ((unsignedMask & iax) >>> ibx);
    16353                                                oai64data[it.oIndex] = ox;
    16354                                                for (int j = 1; j < is; j++) {
    16355                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16356                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16357                                                        ox = ((unsignedMask & iax) >>> ibx);
    16358                                                        oai64data[it.oIndex + j] = ox;
    16359                                                }
    16360                                        }
    16361                                }
    16362                        }
    16363                        break;
    16364                case Dataset.ARRAYINT32:
    16365                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    16366                        unsignedMask = 0xffffffffL;
    16367                        if (is == 1) {
    16368                                {
    16369                                        while (it.hasNext()) {
    16370                                                final long iax = it.aLong;
    16371                                                final long ibx = it.bLong;
    16372                                                int ox;
    16373                                                ox = (int) ((unsignedMask & iax) >>> ibx);
    16374                                                oai32data[it.oIndex] = ox;
    16375                                        }
    16376                                }
    16377                        } else if (as < bs) {
    16378                                {
    16379                                        while (it.hasNext()) {
    16380                                                final long iax = it.aLong;
    16381                                                long ibx = it.bLong;
    16382                                                int ox;
    16383                                                ox = (int) ((unsignedMask & iax) >>> ibx);
    16384                                                oai32data[it.oIndex] = ox;
    16385                                                for (int j = 1; j < is; j++) {
    16386                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16387                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
    16388                                                        oai32data[it.oIndex + j] = ox;
    16389                                                }
    16390                                        }
    16391                                }
    16392                        } else if (as > bs) {
    16393                                {
    16394                                        while (it.hasNext()) {
    16395                                                long iax = it.aLong;
    16396                                                final long ibx = it.bLong;
    16397                                                int ox;
    16398                                                ox = (int) ((unsignedMask & iax) >>> ibx);
    16399                                                oai32data[it.oIndex] = ox;
    16400                                                for (int j = 1; j < is; j++) {
    16401                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16402                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
    16403                                                        oai32data[it.oIndex + j] = ox;
    16404                                                }
    16405                                        }
    16406                                }
    16407                        } else if (as == 1) {
    16408                                {
    16409                                        while (it.hasNext()) {
    16410                                                final long iax = it.aLong;
    16411                                                final long ibx = it.bLong;
    16412                                                int ox;
    16413                                                ox = (int) ((unsignedMask & iax) >>> ibx);
    16414                                                for (int j = 0; j < is; j++) {
    16415                                                        oai32data[it.oIndex + j] = ox;
    16416                                                }
    16417                                        }
    16418                                }
    16419                        } else {
    16420                                {
    16421                                        while (it.hasNext()) {
    16422                                                long iax = it.aLong;
    16423                                                long ibx = it.bLong;
    16424                                                int ox;
    16425                                                ox = (int) ((unsignedMask & iax) >>> ibx);
    16426                                                oai32data[it.oIndex] = ox;
    16427                                                for (int j = 1; j < is; j++) {
    16428                                                        iax = da.getElementLongAbs(it.aIndex + j);
    16429                                                        ibx = db.getElementLongAbs(it.bIndex + j);
    16430                                                        ox = (int) ((unsignedMask & iax) >>> ibx);
    16431                                                        oai32data[it.oIndex + j] = ox;
    16432                                                }
    16433                                        }
    16434                                }
    16435                        }
    16436                        break;
    16437                default:
    16438                        throw new IllegalArgumentException("unsignedRightShift supports integer, compound integer datasets only");
    16439                }
    16440
    16441                addBinaryOperatorName(da, db, result, ">>>");
    16442                return result;
    16443        }
    16444
    16445        /**
    16446         * bitwiseInvert - {@code ~a}, bitwise invert (or NOT) each element
    16447         * @param a
    16448         * @return dataset
    16449         */
    16450        public static Dataset bitwiseInvert(final Object a) {
    16451                return bitwiseInvert(a, null);
    16452        }
    16453
    16454        /**
    16455         * bitwiseInvert - {@code ~a}, bitwise invert (or NOT) each element
    16456         * @param a
    16457         * @param o output can be null - in which case, a new dataset is created
    16458         * @return dataset
    16459         */
    16460        public static Dataset bitwiseInvert(final Object a, final Dataset o) {
    16461                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    16462                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true, true, true);
    16463                final Dataset result = it.getOutput();
    16464                final int is = result.getElementsPerItem();
    16465                final int as = da.getElementsPerItem();
    16466                final int dt = result.getDType();
    16467
    16468                switch(dt) {
    16469                case Dataset.INT8:
    16470                        final byte[] oi8data = ((ByteDataset) result).getData();
    16471                        {
    16472                                while (it.hasNext()) {
    16473                                        final long ix = it.aLong;
    16474                                        byte ox;
    16475                                        ox = (byte) toLong(~ix);
    16476                                        oi8data[it.oIndex] = ox;
    16477                                }
    16478                        }
    16479                        break;
    16480                case Dataset.INT16:
    16481                        final short[] oi16data = ((ShortDataset) result).getData();
    16482                        {
    16483                                while (it.hasNext()) {
    16484                                        final long ix = it.aLong;
    16485                                        short ox;
    16486                                        ox = (short) toLong(~ix);
    16487                                        oi16data[it.oIndex] = ox;
    16488                                }
    16489                        }
    16490                        break;
    16491                case Dataset.INT64:
    16492                        final long[] oi64data = ((LongDataset) result).getData();
    16493                        {
    16494                                while (it.hasNext()) {
    16495                                        final long ix = it.aLong;
    16496                                        long ox;
    16497                                        ox = toLong(~ix);
    16498                                        oi64data[it.oIndex] = ox;
    16499                                }
    16500                        }
    16501                        break;
    16502                case Dataset.INT32:
    16503                        final int[] oi32data = ((IntegerDataset) result).getData();
    16504                        {
    16505                                while (it.hasNext()) {
    16506                                        final long ix = it.aLong;
    16507                                        int ox;
    16508                                        ox = (int) toLong(~ix);
    16509                                        oi32data[it.oIndex] = ox;
    16510                                }
    16511                        }
    16512                        break;
    16513                case Dataset.ARRAYINT8:
    16514                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    16515                        if (is == 1) {
    16516                                {
    16517                                        while (it.hasNext()) {
    16518                                                final long ix = it.aLong;
    16519                                                byte ox;
    16520                                                ox = (byte) toLong(~ix);
    16521                                                oai8data[it.oIndex] = ox;
    16522                                        }
    16523                                }
    16524                        } else if (as == 1) {
    16525                                {
    16526                                        while (it.hasNext()) {
    16527                                                final long ix = it.aLong;
    16528                                                byte ox;
    16529                                                ox = (byte) toLong(~ix);
    16530                                                for (int j = 0; j < is; j++) {
    16531                                                        oai8data[it.oIndex + j] = ox;
    16532                                                }
    16533                                        }
    16534                                }
    16535                        } else {
    16536                                {
    16537                                        while (it.hasNext()) {
    16538                                                for (int j = 0; j < is; j++) {
    16539                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16540                                                        byte ox;
    16541                                                        ox = (byte) toLong(~ix);
    16542                                                        oai8data[it.oIndex + j] = ox;
    16543                                                }
    16544                                        }
    16545                                }
    16546                        }
    16547                        break;
    16548                case Dataset.ARRAYINT16:
    16549                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    16550                        if (is == 1) {
    16551                                {
    16552                                        while (it.hasNext()) {
    16553                                                final long ix = it.aLong;
    16554                                                short ox;
    16555                                                ox = (short) toLong(~ix);
    16556                                                oai16data[it.oIndex] = ox;
    16557                                        }
    16558                                }
    16559                        } else if (as == 1) {
    16560                                {
    16561                                        while (it.hasNext()) {
    16562                                                final long ix = it.aLong;
    16563                                                short ox;
    16564                                                ox = (short) toLong(~ix);
    16565                                                for (int j = 0; j < is; j++) {
    16566                                                        oai16data[it.oIndex + j] = ox;
    16567                                                }
    16568                                        }
    16569                                }
    16570                        } else {
    16571                                {
    16572                                        while (it.hasNext()) {
    16573                                                for (int j = 0; j < is; j++) {
    16574                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16575                                                        short ox;
    16576                                                        ox = (short) toLong(~ix);
    16577                                                        oai16data[it.oIndex + j] = ox;
    16578                                                }
    16579                                        }
    16580                                }
    16581                        }
    16582                        break;
    16583                case Dataset.ARRAYINT64:
    16584                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    16585                        if (is == 1) {
    16586                                {
    16587                                        while (it.hasNext()) {
    16588                                                final long ix = it.aLong;
    16589                                                long ox;
    16590                                                ox = toLong(~ix);
    16591                                                oai64data[it.oIndex] = ox;
    16592                                        }
    16593                                }
    16594                        } else if (as == 1) {
    16595                                {
    16596                                        while (it.hasNext()) {
    16597                                                final long ix = it.aLong;
    16598                                                long ox;
    16599                                                ox = toLong(~ix);
    16600                                                for (int j = 0; j < is; j++) {
    16601                                                        oai64data[it.oIndex + j] = ox;
    16602                                                }
    16603                                        }
    16604                                }
    16605                        } else {
    16606                                {
    16607                                        while (it.hasNext()) {
    16608                                                for (int j = 0; j < is; j++) {
    16609                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16610                                                        long ox;
    16611                                                        ox = toLong(~ix);
    16612                                                        oai64data[it.oIndex + j] = ox;
    16613                                                }
    16614                                        }
    16615                                }
    16616                        }
    16617                        break;
    16618                case Dataset.ARRAYINT32:
    16619                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    16620                        if (is == 1) {
    16621                                {
    16622                                        while (it.hasNext()) {
    16623                                                final long ix = it.aLong;
    16624                                                int ox;
    16625                                                ox = (int) toLong(~ix);
    16626                                                oai32data[it.oIndex] = ox;
    16627                                        }
    16628                                }
    16629                        } else if (as == 1) {
    16630                                {
    16631                                        while (it.hasNext()) {
    16632                                                final long ix = it.aLong;
    16633                                                int ox;
    16634                                                ox = (int) toLong(~ix);
    16635                                                for (int j = 0; j < is; j++) {
    16636                                                        oai32data[it.oIndex + j] = ox;
    16637                                                }
    16638                                        }
    16639                                }
    16640                        } else {
    16641                                {
    16642                                        while (it.hasNext()) {
    16643                                                for (int j = 0; j < is; j++) {
    16644                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16645                                                        int ox;
    16646                                                        ox = (int) toLong(~ix);
    16647                                                        oai32data[it.oIndex + j] = ox;
    16648                                                }
    16649                                        }
    16650                                }
    16651                        }
    16652                        break;
    16653                default:
    16654                        throw new IllegalArgumentException("bitwiseInvert supports integer, compound integer datasets only");
    16655                }
    16656
    16657                addFunctionName(result, "bitwiseInvert");
    16658                return result;
    16659        }
    16660
    16661        /**
    16662         * sin - evaluate the sine function on each element of the dataset
    16663         * @param a
    16664         * @return dataset
    16665         */
    16666        public static Dataset sin(final Object a) {
    16667                return sin(a, null);
    16668        }
    16669
    16670        /**
    16671         * sin - evaluate the sine function on each element of the dataset
    16672         * @param a
    16673         * @param o output can be null - in which case, a new dataset is created
    16674         * @return dataset
    16675         */
    16676        public static Dataset sin(final Object a, final Dataset o) {
    16677                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    16678                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    16679                final Dataset result = it.getOutput();
    16680                final int is = result.getElementsPerItem();
    16681                final int as = da.getElementsPerItem();
    16682                final int dt = result.getDType();
    16683
    16684                switch(dt) {
    16685                case Dataset.INT8:
    16686                        final byte[] oi8data = ((ByteDataset) result).getData();
    16687                        if (it.isOutputDouble()) {
    16688                                while (it.hasNext()) {
    16689                                        final double ix = it.aDouble;
    16690                                        byte ox;
    16691                                        ox = (byte) toLong(Math.sin(ix));
    16692                                        oi8data[it.oIndex] = ox;
    16693                                }
    16694                        } else {
    16695                                while (it.hasNext()) {
    16696                                        final long ix = it.aLong;
    16697                                        byte ox;
    16698                                        ox = (byte) toLong(Math.sin(ix));
    16699                                        oi8data[it.oIndex] = ox;
    16700                                }
    16701                        }
    16702                        break;
    16703                case Dataset.INT16:
    16704                        final short[] oi16data = ((ShortDataset) result).getData();
    16705                        if (it.isOutputDouble()) {
    16706                                while (it.hasNext()) {
    16707                                        final double ix = it.aDouble;
    16708                                        short ox;
    16709                                        ox = (short) toLong(Math.sin(ix));
    16710                                        oi16data[it.oIndex] = ox;
    16711                                }
    16712                        } else {
    16713                                while (it.hasNext()) {
    16714                                        final long ix = it.aLong;
    16715                                        short ox;
    16716                                        ox = (short) toLong(Math.sin(ix));
    16717                                        oi16data[it.oIndex] = ox;
    16718                                }
    16719                        }
    16720                        break;
    16721                case Dataset.INT64:
    16722                        final long[] oi64data = ((LongDataset) result).getData();
    16723                        if (it.isOutputDouble()) {
    16724                                while (it.hasNext()) {
    16725                                        final double ix = it.aDouble;
    16726                                        long ox;
    16727                                        ox = toLong(Math.sin(ix));
    16728                                        oi64data[it.oIndex] = ox;
    16729                                }
    16730                        } else {
    16731                                while (it.hasNext()) {
    16732                                        final long ix = it.aLong;
    16733                                        long ox;
    16734                                        ox = toLong(Math.sin(ix));
    16735                                        oi64data[it.oIndex] = ox;
    16736                                }
    16737                        }
    16738                        break;
    16739                case Dataset.INT32:
    16740                        final int[] oi32data = ((IntegerDataset) result).getData();
    16741                        if (it.isOutputDouble()) {
    16742                                while (it.hasNext()) {
    16743                                        final double ix = it.aDouble;
    16744                                        int ox;
    16745                                        ox = (int) toLong(Math.sin(ix));
    16746                                        oi32data[it.oIndex] = ox;
    16747                                }
    16748                        } else {
    16749                                while (it.hasNext()) {
    16750                                        final long ix = it.aLong;
    16751                                        int ox;
    16752                                        ox = (int) toLong(Math.sin(ix));
    16753                                        oi32data[it.oIndex] = ox;
    16754                                }
    16755                        }
    16756                        break;
    16757                case Dataset.ARRAYINT8:
    16758                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    16759                        if (is == 1) {
    16760                                if (it.isOutputDouble()) {
    16761                                        while (it.hasNext()) {
    16762                                                final double ix = it.aDouble;
    16763                                                byte ox;
    16764                                                ox = (byte) toLong(Math.sin(ix));
    16765                                                oai8data[it.oIndex] = ox;
    16766                                        }
    16767                                } else {
    16768                                        while (it.hasNext()) {
    16769                                                final long ix = it.aLong;
    16770                                                byte ox;
    16771                                                ox = (byte) toLong(Math.sin(ix));
    16772                                                oai8data[it.oIndex] = ox;
    16773                                        }
    16774                                }
    16775                        } else if (as == 1) {
    16776                                if (it.isOutputDouble()) {
    16777                                        while (it.hasNext()) {
    16778                                                final double ix = it.aDouble;
    16779                                                byte ox;
    16780                                                ox = (byte) toLong(Math.sin(ix));
    16781                                                for (int j = 0; j < is; j++) {
    16782                                                        oai8data[it.oIndex + j] = ox;
    16783                                                }
    16784                                        }
    16785                                } else {
    16786                                        while (it.hasNext()) {
    16787                                                final long ix = it.aLong;
    16788                                                byte ox;
    16789                                                ox = (byte) toLong(Math.sin(ix));
    16790                                                for (int j = 0; j < is; j++) {
    16791                                                        oai8data[it.oIndex + j] = ox;
    16792                                                }
    16793                                        }
    16794                                }
    16795                        } else {
    16796                                if (it.isOutputDouble()) {
    16797                                        while (it.hasNext()) {
    16798                                                for (int j = 0; j < is; j++) {
    16799                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    16800                                                        byte ox;
    16801                                                        ox = (byte) toLong(Math.sin(ix));
    16802                                                        oai8data[it.oIndex + j] = ox;
    16803                                                }
    16804                                        }
    16805                                } else {
    16806                                        while (it.hasNext()) {
    16807                                                for (int j = 0; j < is; j++) {
    16808                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16809                                                        byte ox;
    16810                                                        ox = (byte) toLong(Math.sin(ix));
    16811                                                        oai8data[it.oIndex + j] = ox;
    16812                                                }
    16813                                        }
    16814                                }
    16815                        }
    16816                        break;
    16817                case Dataset.ARRAYINT16:
    16818                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    16819                        if (is == 1) {
    16820                                if (it.isOutputDouble()) {
    16821                                        while (it.hasNext()) {
    16822                                                final double ix = it.aDouble;
    16823                                                short ox;
    16824                                                ox = (short) toLong(Math.sin(ix));
    16825                                                oai16data[it.oIndex] = ox;
    16826                                        }
    16827                                } else {
    16828                                        while (it.hasNext()) {
    16829                                                final long ix = it.aLong;
    16830                                                short ox;
    16831                                                ox = (short) toLong(Math.sin(ix));
    16832                                                oai16data[it.oIndex] = ox;
    16833                                        }
    16834                                }
    16835                        } else if (as == 1) {
    16836                                if (it.isOutputDouble()) {
    16837                                        while (it.hasNext()) {
    16838                                                final double ix = it.aDouble;
    16839                                                short ox;
    16840                                                ox = (short) toLong(Math.sin(ix));
    16841                                                for (int j = 0; j < is; j++) {
    16842                                                        oai16data[it.oIndex + j] = ox;
    16843                                                }
    16844                                        }
    16845                                } else {
    16846                                        while (it.hasNext()) {
    16847                                                final long ix = it.aLong;
    16848                                                short ox;
    16849                                                ox = (short) toLong(Math.sin(ix));
    16850                                                for (int j = 0; j < is; j++) {
    16851                                                        oai16data[it.oIndex + j] = ox;
    16852                                                }
    16853                                        }
    16854                                }
    16855                        } else {
    16856                                if (it.isOutputDouble()) {
    16857                                        while (it.hasNext()) {
    16858                                                for (int j = 0; j < is; j++) {
    16859                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    16860                                                        short ox;
    16861                                                        ox = (short) toLong(Math.sin(ix));
    16862                                                        oai16data[it.oIndex + j] = ox;
    16863                                                }
    16864                                        }
    16865                                } else {
    16866                                        while (it.hasNext()) {
    16867                                                for (int j = 0; j < is; j++) {
    16868                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16869                                                        short ox;
    16870                                                        ox = (short) toLong(Math.sin(ix));
    16871                                                        oai16data[it.oIndex + j] = ox;
    16872                                                }
    16873                                        }
    16874                                }
    16875                        }
    16876                        break;
    16877                case Dataset.ARRAYINT64:
    16878                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    16879                        if (is == 1) {
    16880                                if (it.isOutputDouble()) {
    16881                                        while (it.hasNext()) {
    16882                                                final double ix = it.aDouble;
    16883                                                long ox;
    16884                                                ox = toLong(Math.sin(ix));
    16885                                                oai64data[it.oIndex] = ox;
    16886                                        }
    16887                                } else {
    16888                                        while (it.hasNext()) {
    16889                                                final long ix = it.aLong;
    16890                                                long ox;
    16891                                                ox = toLong(Math.sin(ix));
    16892                                                oai64data[it.oIndex] = ox;
    16893                                        }
    16894                                }
    16895                        } else if (as == 1) {
    16896                                if (it.isOutputDouble()) {
    16897                                        while (it.hasNext()) {
    16898                                                final double ix = it.aDouble;
    16899                                                long ox;
    16900                                                ox = toLong(Math.sin(ix));
    16901                                                for (int j = 0; j < is; j++) {
    16902                                                        oai64data[it.oIndex + j] = ox;
    16903                                                }
    16904                                        }
    16905                                } else {
    16906                                        while (it.hasNext()) {
    16907                                                final long ix = it.aLong;
    16908                                                long ox;
    16909                                                ox = toLong(Math.sin(ix));
    16910                                                for (int j = 0; j < is; j++) {
    16911                                                        oai64data[it.oIndex + j] = ox;
    16912                                                }
    16913                                        }
    16914                                }
    16915                        } else {
    16916                                if (it.isOutputDouble()) {
    16917                                        while (it.hasNext()) {
    16918                                                for (int j = 0; j < is; j++) {
    16919                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    16920                                                        long ox;
    16921                                                        ox = toLong(Math.sin(ix));
    16922                                                        oai64data[it.oIndex + j] = ox;
    16923                                                }
    16924                                        }
    16925                                } else {
    16926                                        while (it.hasNext()) {
    16927                                                for (int j = 0; j < is; j++) {
    16928                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16929                                                        long ox;
    16930                                                        ox = toLong(Math.sin(ix));
    16931                                                        oai64data[it.oIndex + j] = ox;
    16932                                                }
    16933                                        }
    16934                                }
    16935                        }
    16936                        break;
    16937                case Dataset.ARRAYINT32:
    16938                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    16939                        if (is == 1) {
    16940                                if (it.isOutputDouble()) {
    16941                                        while (it.hasNext()) {
    16942                                                final double ix = it.aDouble;
    16943                                                int ox;
    16944                                                ox = (int) toLong(Math.sin(ix));
    16945                                                oai32data[it.oIndex] = ox;
    16946                                        }
    16947                                } else {
    16948                                        while (it.hasNext()) {
    16949                                                final long ix = it.aLong;
    16950                                                int ox;
    16951                                                ox = (int) toLong(Math.sin(ix));
    16952                                                oai32data[it.oIndex] = ox;
    16953                                        }
    16954                                }
    16955                        } else if (as == 1) {
    16956                                if (it.isOutputDouble()) {
    16957                                        while (it.hasNext()) {
    16958                                                final double ix = it.aDouble;
    16959                                                int ox;
    16960                                                ox = (int) toLong(Math.sin(ix));
    16961                                                for (int j = 0; j < is; j++) {
    16962                                                        oai32data[it.oIndex + j] = ox;
    16963                                                }
    16964                                        }
    16965                                } else {
    16966                                        while (it.hasNext()) {
    16967                                                final long ix = it.aLong;
    16968                                                int ox;
    16969                                                ox = (int) toLong(Math.sin(ix));
    16970                                                for (int j = 0; j < is; j++) {
    16971                                                        oai32data[it.oIndex + j] = ox;
    16972                                                }
    16973                                        }
    16974                                }
    16975                        } else {
    16976                                if (it.isOutputDouble()) {
    16977                                        while (it.hasNext()) {
    16978                                                for (int j = 0; j < is; j++) {
    16979                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    16980                                                        int ox;
    16981                                                        ox = (int) toLong(Math.sin(ix));
    16982                                                        oai32data[it.oIndex + j] = ox;
    16983                                                }
    16984                                        }
    16985                                } else {
    16986                                        while (it.hasNext()) {
    16987                                                for (int j = 0; j < is; j++) {
    16988                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    16989                                                        int ox;
    16990                                                        ox = (int) toLong(Math.sin(ix));
    16991                                                        oai32data[it.oIndex + j] = ox;
    16992                                                }
    16993                                        }
    16994                                }
    16995                        }
    16996                        break;
    16997                case Dataset.FLOAT32:
    16998                        final float[] of32data = ((FloatDataset) result).getData();
    16999                        if (it.isOutputDouble()) {
    17000                                while (it.hasNext()) {
    17001                                        final double ix = it.aDouble;
    17002                                        float ox;
    17003                                        ox = (float) (Math.sin(ix));
    17004                                        of32data[it.oIndex] = ox;
    17005                                }
    17006                        } else {
    17007                                while (it.hasNext()) {
    17008                                        final long ix = it.aLong;
    17009                                        float ox;
    17010                                        ox = (float) (Math.sin(ix));
    17011                                        of32data[it.oIndex] = ox;
    17012                                }
    17013                        }
    17014                        break;
    17015                case Dataset.FLOAT64:
    17016                        final double[] of64data = ((DoubleDataset) result).getData();
    17017                        if (it.isOutputDouble()) {
    17018                                while (it.hasNext()) {
    17019                                        final double ix = it.aDouble;
    17020                                        double ox;
    17021                                        ox = (Math.sin(ix));
    17022                                        of64data[it.oIndex] = ox;
    17023                                }
    17024                        } else {
    17025                                while (it.hasNext()) {
    17026                                        final long ix = it.aLong;
    17027                                        double ox;
    17028                                        ox = (Math.sin(ix));
    17029                                        of64data[it.oIndex] = ox;
    17030                                }
    17031                        }
    17032                        break;
    17033                case Dataset.ARRAYFLOAT32:
    17034                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    17035                        if (is == 1) {
    17036                                if (it.isOutputDouble()) {
    17037                                        while (it.hasNext()) {
    17038                                                final double ix = it.aDouble;
    17039                                                float ox;
    17040                                                ox = (float) (Math.sin(ix));
    17041                                                oaf32data[it.oIndex] = ox;
    17042                                        }
    17043                                } else {
    17044                                        while (it.hasNext()) {
    17045                                                final long ix = it.aLong;
    17046                                                float ox;
    17047                                                ox = (float) (Math.sin(ix));
    17048                                                oaf32data[it.oIndex] = ox;
    17049                                        }
    17050                                }
    17051                        } else if (as == 1) {
    17052                                if (it.isOutputDouble()) {
    17053                                        while (it.hasNext()) {
    17054                                                final double ix = it.aDouble;
    17055                                                float ox;
    17056                                                ox = (float) (Math.sin(ix));
    17057                                                for (int j = 0; j < is; j++) {
    17058                                                        oaf32data[it.oIndex + j] = ox;
    17059                                                }
    17060                                        }
    17061                                } else {
    17062                                        while (it.hasNext()) {
    17063                                                final long ix = it.aLong;
    17064                                                float ox;
    17065                                                ox = (float) (Math.sin(ix));
    17066                                                for (int j = 0; j < is; j++) {
    17067                                                        oaf32data[it.oIndex + j] = ox;
    17068                                                }
    17069                                        }
    17070                                }
    17071                        } else {
    17072                                if (it.isOutputDouble()) {
    17073                                        while (it.hasNext()) {
    17074                                                for (int j = 0; j < is; j++) {
    17075                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17076                                                        float ox;
    17077                                                        ox = (float) (Math.sin(ix));
    17078                                                        oaf32data[it.oIndex + j] = ox;
    17079                                                }
    17080                                        }
    17081                                } else {
    17082                                        while (it.hasNext()) {
    17083                                                for (int j = 0; j < is; j++) {
    17084                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17085                                                        float ox;
    17086                                                        ox = (float) (Math.sin(ix));
    17087                                                        oaf32data[it.oIndex + j] = ox;
    17088                                                }
    17089                                        }
    17090                                }
    17091                        }
    17092                        break;
    17093                case Dataset.ARRAYFLOAT64:
    17094                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    17095                        if (is == 1) {
    17096                                if (it.isOutputDouble()) {
    17097                                        while (it.hasNext()) {
    17098                                                final double ix = it.aDouble;
    17099                                                double ox;
    17100                                                ox = (Math.sin(ix));
    17101                                                oaf64data[it.oIndex] = ox;
    17102                                        }
    17103                                } else {
    17104                                        while (it.hasNext()) {
    17105                                                final long ix = it.aLong;
    17106                                                double ox;
    17107                                                ox = (Math.sin(ix));
    17108                                                oaf64data[it.oIndex] = ox;
    17109                                        }
    17110                                }
    17111                        } else if (as == 1) {
    17112                                if (it.isOutputDouble()) {
    17113                                        while (it.hasNext()) {
    17114                                                final double ix = it.aDouble;
    17115                                                double ox;
    17116                                                ox = (Math.sin(ix));
    17117                                                for (int j = 0; j < is; j++) {
    17118                                                        oaf64data[it.oIndex + j] = ox;
    17119                                                }
    17120                                        }
    17121                                } else {
    17122                                        while (it.hasNext()) {
    17123                                                final long ix = it.aLong;
    17124                                                double ox;
    17125                                                ox = (Math.sin(ix));
    17126                                                for (int j = 0; j < is; j++) {
    17127                                                        oaf64data[it.oIndex + j] = ox;
    17128                                                }
    17129                                        }
    17130                                }
    17131                        } else {
    17132                                if (it.isOutputDouble()) {
    17133                                        while (it.hasNext()) {
    17134                                                for (int j = 0; j < is; j++) {
    17135                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17136                                                        double ox;
    17137                                                        ox = (Math.sin(ix));
    17138                                                        oaf64data[it.oIndex + j] = ox;
    17139                                                }
    17140                                        }
    17141                                } else {
    17142                                        while (it.hasNext()) {
    17143                                                for (int j = 0; j < is; j++) {
    17144                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17145                                                        double ox;
    17146                                                        ox = (Math.sin(ix));
    17147                                                        oaf64data[it.oIndex + j] = ox;
    17148                                                }
    17149                                        }
    17150                                }
    17151                        }
    17152                        break;
    17153                case Dataset.COMPLEX64:
    17154                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    17155                        if (as == 1) {
    17156                                final double iy = 0;
    17157                                while (it.hasNext()) {
    17158                                        final double ix = it.aDouble;
    17159                                        float ox;
    17160                                        float oy;
    17161                                        ox = (float) (Math.sin(ix)*Math.cosh(iy));
    17162                                        oy = (float) (Math.cos(ix)*Math.sinh(iy));
    17163                                        oc64data[it.oIndex] = ox;
    17164                                        oc64data[it.oIndex + 1] = oy;
    17165                                }
    17166                        } else {
    17167                                while (it.hasNext()) {
    17168                                        final double ix = it.aDouble;
    17169                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    17170                                        float ox;
    17171                                        float oy;
    17172                                        ox = (float) (Math.sin(ix)*Math.cosh(iy));
    17173                                        oy = (float) (Math.cos(ix)*Math.sinh(iy));
    17174                                        oc64data[it.oIndex] = ox;
    17175                                        oc64data[it.oIndex + 1] = oy;
    17176                                }
    17177                        }
    17178                        break;
    17179                case Dataset.COMPLEX128:
    17180                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    17181                        if (as == 1) {
    17182                                final double iy = 0;
    17183                                while (it.hasNext()) {
    17184                                        final double ix = it.aDouble;
    17185                                        double ox;
    17186                                        double oy;
    17187                                        ox = (Math.sin(ix)*Math.cosh(iy));
    17188                                        oy = (Math.cos(ix)*Math.sinh(iy));
    17189                                        oc128data[it.oIndex] = ox;
    17190                                        oc128data[it.oIndex + 1] = oy;
    17191                                }
    17192                        } else {
    17193                                while (it.hasNext()) {
    17194                                        final double ix = it.aDouble;
    17195                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    17196                                        double ox;
    17197                                        double oy;
    17198                                        ox = (Math.sin(ix)*Math.cosh(iy));
    17199                                        oy = (Math.cos(ix)*Math.sinh(iy));
    17200                                        oc128data[it.oIndex] = ox;
    17201                                        oc128data[it.oIndex + 1] = oy;
    17202                                }
    17203                        }
    17204                        break;
    17205                default:
    17206                        throw new IllegalArgumentException("sin supports integer, compound integer, real, compound real, complex datasets only");
    17207                }
    17208
    17209                addFunctionName(result, "sin");
    17210                return result;
    17211        }
    17212
    17213        /**
    17214         * cos - evaluate the cosine function on each element of the dataset
    17215         * @param a
    17216         * @return dataset
    17217         */
    17218        public static Dataset cos(final Object a) {
    17219                return cos(a, null);
    17220        }
    17221
    17222        /**
    17223         * cos - evaluate the cosine function on each element of the dataset
    17224         * @param a
    17225         * @param o output can be null - in which case, a new dataset is created
    17226         * @return dataset
    17227         */
    17228        public static Dataset cos(final Object a, final Dataset o) {
    17229                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    17230                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    17231                final Dataset result = it.getOutput();
    17232                final int is = result.getElementsPerItem();
    17233                final int as = da.getElementsPerItem();
    17234                final int dt = result.getDType();
    17235
    17236                switch(dt) {
    17237                case Dataset.INT8:
    17238                        final byte[] oi8data = ((ByteDataset) result).getData();
    17239                        if (it.isOutputDouble()) {
    17240                                while (it.hasNext()) {
    17241                                        final double ix = it.aDouble;
    17242                                        byte ox;
    17243                                        ox = (byte) toLong(Math.cos(ix));
    17244                                        oi8data[it.oIndex] = ox;
    17245                                }
    17246                        } else {
    17247                                while (it.hasNext()) {
    17248                                        final long ix = it.aLong;
    17249                                        byte ox;
    17250                                        ox = (byte) toLong(Math.cos(ix));
    17251                                        oi8data[it.oIndex] = ox;
    17252                                }
    17253                        }
    17254                        break;
    17255                case Dataset.INT16:
    17256                        final short[] oi16data = ((ShortDataset) result).getData();
    17257                        if (it.isOutputDouble()) {
    17258                                while (it.hasNext()) {
    17259                                        final double ix = it.aDouble;
    17260                                        short ox;
    17261                                        ox = (short) toLong(Math.cos(ix));
    17262                                        oi16data[it.oIndex] = ox;
    17263                                }
    17264                        } else {
    17265                                while (it.hasNext()) {
    17266                                        final long ix = it.aLong;
    17267                                        short ox;
    17268                                        ox = (short) toLong(Math.cos(ix));
    17269                                        oi16data[it.oIndex] = ox;
    17270                                }
    17271                        }
    17272                        break;
    17273                case Dataset.INT64:
    17274                        final long[] oi64data = ((LongDataset) result).getData();
    17275                        if (it.isOutputDouble()) {
    17276                                while (it.hasNext()) {
    17277                                        final double ix = it.aDouble;
    17278                                        long ox;
    17279                                        ox = toLong(Math.cos(ix));
    17280                                        oi64data[it.oIndex] = ox;
    17281                                }
    17282                        } else {
    17283                                while (it.hasNext()) {
    17284                                        final long ix = it.aLong;
    17285                                        long ox;
    17286                                        ox = toLong(Math.cos(ix));
    17287                                        oi64data[it.oIndex] = ox;
    17288                                }
    17289                        }
    17290                        break;
    17291                case Dataset.INT32:
    17292                        final int[] oi32data = ((IntegerDataset) result).getData();
    17293                        if (it.isOutputDouble()) {
    17294                                while (it.hasNext()) {
    17295                                        final double ix = it.aDouble;
    17296                                        int ox;
    17297                                        ox = (int) toLong(Math.cos(ix));
    17298                                        oi32data[it.oIndex] = ox;
    17299                                }
    17300                        } else {
    17301                                while (it.hasNext()) {
    17302                                        final long ix = it.aLong;
    17303                                        int ox;
    17304                                        ox = (int) toLong(Math.cos(ix));
    17305                                        oi32data[it.oIndex] = ox;
    17306                                }
    17307                        }
    17308                        break;
    17309                case Dataset.ARRAYINT8:
    17310                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    17311                        if (is == 1) {
    17312                                if (it.isOutputDouble()) {
    17313                                        while (it.hasNext()) {
    17314                                                final double ix = it.aDouble;
    17315                                                byte ox;
    17316                                                ox = (byte) toLong(Math.cos(ix));
    17317                                                oai8data[it.oIndex] = ox;
    17318                                        }
    17319                                } else {
    17320                                        while (it.hasNext()) {
    17321                                                final long ix = it.aLong;
    17322                                                byte ox;
    17323                                                ox = (byte) toLong(Math.cos(ix));
    17324                                                oai8data[it.oIndex] = ox;
    17325                                        }
    17326                                }
    17327                        } else if (as == 1) {
    17328                                if (it.isOutputDouble()) {
    17329                                        while (it.hasNext()) {
    17330                                                final double ix = it.aDouble;
    17331                                                byte ox;
    17332                                                ox = (byte) toLong(Math.cos(ix));
    17333                                                for (int j = 0; j < is; j++) {
    17334                                                        oai8data[it.oIndex + j] = ox;
    17335                                                }
    17336                                        }
    17337                                } else {
    17338                                        while (it.hasNext()) {
    17339                                                final long ix = it.aLong;
    17340                                                byte ox;
    17341                                                ox = (byte) toLong(Math.cos(ix));
    17342                                                for (int j = 0; j < is; j++) {
    17343                                                        oai8data[it.oIndex + j] = ox;
    17344                                                }
    17345                                        }
    17346                                }
    17347                        } else {
    17348                                if (it.isOutputDouble()) {
    17349                                        while (it.hasNext()) {
    17350                                                for (int j = 0; j < is; j++) {
    17351                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17352                                                        byte ox;
    17353                                                        ox = (byte) toLong(Math.cos(ix));
    17354                                                        oai8data[it.oIndex + j] = ox;
    17355                                                }
    17356                                        }
    17357                                } else {
    17358                                        while (it.hasNext()) {
    17359                                                for (int j = 0; j < is; j++) {
    17360                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17361                                                        byte ox;
    17362                                                        ox = (byte) toLong(Math.cos(ix));
    17363                                                        oai8data[it.oIndex + j] = ox;
    17364                                                }
    17365                                        }
    17366                                }
    17367                        }
    17368                        break;
    17369                case Dataset.ARRAYINT16:
    17370                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    17371                        if (is == 1) {
    17372                                if (it.isOutputDouble()) {
    17373                                        while (it.hasNext()) {
    17374                                                final double ix = it.aDouble;
    17375                                                short ox;
    17376                                                ox = (short) toLong(Math.cos(ix));
    17377                                                oai16data[it.oIndex] = ox;
    17378                                        }
    17379                                } else {
    17380                                        while (it.hasNext()) {
    17381                                                final long ix = it.aLong;
    17382                                                short ox;
    17383                                                ox = (short) toLong(Math.cos(ix));
    17384                                                oai16data[it.oIndex] = ox;
    17385                                        }
    17386                                }
    17387                        } else if (as == 1) {
    17388                                if (it.isOutputDouble()) {
    17389                                        while (it.hasNext()) {
    17390                                                final double ix = it.aDouble;
    17391                                                short ox;
    17392                                                ox = (short) toLong(Math.cos(ix));
    17393                                                for (int j = 0; j < is; j++) {
    17394                                                        oai16data[it.oIndex + j] = ox;
    17395                                                }
    17396                                        }
    17397                                } else {
    17398                                        while (it.hasNext()) {
    17399                                                final long ix = it.aLong;
    17400                                                short ox;
    17401                                                ox = (short) toLong(Math.cos(ix));
    17402                                                for (int j = 0; j < is; j++) {
    17403                                                        oai16data[it.oIndex + j] = ox;
    17404                                                }
    17405                                        }
    17406                                }
    17407                        } else {
    17408                                if (it.isOutputDouble()) {
    17409                                        while (it.hasNext()) {
    17410                                                for (int j = 0; j < is; j++) {
    17411                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17412                                                        short ox;
    17413                                                        ox = (short) toLong(Math.cos(ix));
    17414                                                        oai16data[it.oIndex + j] = ox;
    17415                                                }
    17416                                        }
    17417                                } else {
    17418                                        while (it.hasNext()) {
    17419                                                for (int j = 0; j < is; j++) {
    17420                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17421                                                        short ox;
    17422                                                        ox = (short) toLong(Math.cos(ix));
    17423                                                        oai16data[it.oIndex + j] = ox;
    17424                                                }
    17425                                        }
    17426                                }
    17427                        }
    17428                        break;
    17429                case Dataset.ARRAYINT64:
    17430                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    17431                        if (is == 1) {
    17432                                if (it.isOutputDouble()) {
    17433                                        while (it.hasNext()) {
    17434                                                final double ix = it.aDouble;
    17435                                                long ox;
    17436                                                ox = toLong(Math.cos(ix));
    17437                                                oai64data[it.oIndex] = ox;
    17438                                        }
    17439                                } else {
    17440                                        while (it.hasNext()) {
    17441                                                final long ix = it.aLong;
    17442                                                long ox;
    17443                                                ox = toLong(Math.cos(ix));
    17444                                                oai64data[it.oIndex] = ox;
    17445                                        }
    17446                                }
    17447                        } else if (as == 1) {
    17448                                if (it.isOutputDouble()) {
    17449                                        while (it.hasNext()) {
    17450                                                final double ix = it.aDouble;
    17451                                                long ox;
    17452                                                ox = toLong(Math.cos(ix));
    17453                                                for (int j = 0; j < is; j++) {
    17454                                                        oai64data[it.oIndex + j] = ox;
    17455                                                }
    17456                                        }
    17457                                } else {
    17458                                        while (it.hasNext()) {
    17459                                                final long ix = it.aLong;
    17460                                                long ox;
    17461                                                ox = toLong(Math.cos(ix));
    17462                                                for (int j = 0; j < is; j++) {
    17463                                                        oai64data[it.oIndex + j] = ox;
    17464                                                }
    17465                                        }
    17466                                }
    17467                        } else {
    17468                                if (it.isOutputDouble()) {
    17469                                        while (it.hasNext()) {
    17470                                                for (int j = 0; j < is; j++) {
    17471                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17472                                                        long ox;
    17473                                                        ox = toLong(Math.cos(ix));
    17474                                                        oai64data[it.oIndex + j] = ox;
    17475                                                }
    17476                                        }
    17477                                } else {
    17478                                        while (it.hasNext()) {
    17479                                                for (int j = 0; j < is; j++) {
    17480                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17481                                                        long ox;
    17482                                                        ox = toLong(Math.cos(ix));
    17483                                                        oai64data[it.oIndex + j] = ox;
    17484                                                }
    17485                                        }
    17486                                }
    17487                        }
    17488                        break;
    17489                case Dataset.ARRAYINT32:
    17490                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    17491                        if (is == 1) {
    17492                                if (it.isOutputDouble()) {
    17493                                        while (it.hasNext()) {
    17494                                                final double ix = it.aDouble;
    17495                                                int ox;
    17496                                                ox = (int) toLong(Math.cos(ix));
    17497                                                oai32data[it.oIndex] = ox;
    17498                                        }
    17499                                } else {
    17500                                        while (it.hasNext()) {
    17501                                                final long ix = it.aLong;
    17502                                                int ox;
    17503                                                ox = (int) toLong(Math.cos(ix));
    17504                                                oai32data[it.oIndex] = ox;
    17505                                        }
    17506                                }
    17507                        } else if (as == 1) {
    17508                                if (it.isOutputDouble()) {
    17509                                        while (it.hasNext()) {
    17510                                                final double ix = it.aDouble;
    17511                                                int ox;
    17512                                                ox = (int) toLong(Math.cos(ix));
    17513                                                for (int j = 0; j < is; j++) {
    17514                                                        oai32data[it.oIndex + j] = ox;
    17515                                                }
    17516                                        }
    17517                                } else {
    17518                                        while (it.hasNext()) {
    17519                                                final long ix = it.aLong;
    17520                                                int ox;
    17521                                                ox = (int) toLong(Math.cos(ix));
    17522                                                for (int j = 0; j < is; j++) {
    17523                                                        oai32data[it.oIndex + j] = ox;
    17524                                                }
    17525                                        }
    17526                                }
    17527                        } else {
    17528                                if (it.isOutputDouble()) {
    17529                                        while (it.hasNext()) {
    17530                                                for (int j = 0; j < is; j++) {
    17531                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17532                                                        int ox;
    17533                                                        ox = (int) toLong(Math.cos(ix));
    17534                                                        oai32data[it.oIndex + j] = ox;
    17535                                                }
    17536                                        }
    17537                                } else {
    17538                                        while (it.hasNext()) {
    17539                                                for (int j = 0; j < is; j++) {
    17540                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17541                                                        int ox;
    17542                                                        ox = (int) toLong(Math.cos(ix));
    17543                                                        oai32data[it.oIndex + j] = ox;
    17544                                                }
    17545                                        }
    17546                                }
    17547                        }
    17548                        break;
    17549                case Dataset.FLOAT32:
    17550                        final float[] of32data = ((FloatDataset) result).getData();
    17551                        if (it.isOutputDouble()) {
    17552                                while (it.hasNext()) {
    17553                                        final double ix = it.aDouble;
    17554                                        float ox;
    17555                                        ox = (float) (Math.cos(ix));
    17556                                        of32data[it.oIndex] = ox;
    17557                                }
    17558                        } else {
    17559                                while (it.hasNext()) {
    17560                                        final long ix = it.aLong;
    17561                                        float ox;
    17562                                        ox = (float) (Math.cos(ix));
    17563                                        of32data[it.oIndex] = ox;
    17564                                }
    17565                        }
    17566                        break;
    17567                case Dataset.FLOAT64:
    17568                        final double[] of64data = ((DoubleDataset) result).getData();
    17569                        if (it.isOutputDouble()) {
    17570                                while (it.hasNext()) {
    17571                                        final double ix = it.aDouble;
    17572                                        double ox;
    17573                                        ox = (Math.cos(ix));
    17574                                        of64data[it.oIndex] = ox;
    17575                                }
    17576                        } else {
    17577                                while (it.hasNext()) {
    17578                                        final long ix = it.aLong;
    17579                                        double ox;
    17580                                        ox = (Math.cos(ix));
    17581                                        of64data[it.oIndex] = ox;
    17582                                }
    17583                        }
    17584                        break;
    17585                case Dataset.ARRAYFLOAT32:
    17586                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    17587                        if (is == 1) {
    17588                                if (it.isOutputDouble()) {
    17589                                        while (it.hasNext()) {
    17590                                                final double ix = it.aDouble;
    17591                                                float ox;
    17592                                                ox = (float) (Math.cos(ix));
    17593                                                oaf32data[it.oIndex] = ox;
    17594                                        }
    17595                                } else {
    17596                                        while (it.hasNext()) {
    17597                                                final long ix = it.aLong;
    17598                                                float ox;
    17599                                                ox = (float) (Math.cos(ix));
    17600                                                oaf32data[it.oIndex] = ox;
    17601                                        }
    17602                                }
    17603                        } else if (as == 1) {
    17604                                if (it.isOutputDouble()) {
    17605                                        while (it.hasNext()) {
    17606                                                final double ix = it.aDouble;
    17607                                                float ox;
    17608                                                ox = (float) (Math.cos(ix));
    17609                                                for (int j = 0; j < is; j++) {
    17610                                                        oaf32data[it.oIndex + j] = ox;
    17611                                                }
    17612                                        }
    17613                                } else {
    17614                                        while (it.hasNext()) {
    17615                                                final long ix = it.aLong;
    17616                                                float ox;
    17617                                                ox = (float) (Math.cos(ix));
    17618                                                for (int j = 0; j < is; j++) {
    17619                                                        oaf32data[it.oIndex + j] = ox;
    17620                                                }
    17621                                        }
    17622                                }
    17623                        } else {
    17624                                if (it.isOutputDouble()) {
    17625                                        while (it.hasNext()) {
    17626                                                for (int j = 0; j < is; j++) {
    17627                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17628                                                        float ox;
    17629                                                        ox = (float) (Math.cos(ix));
    17630                                                        oaf32data[it.oIndex + j] = ox;
    17631                                                }
    17632                                        }
    17633                                } else {
    17634                                        while (it.hasNext()) {
    17635                                                for (int j = 0; j < is; j++) {
    17636                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17637                                                        float ox;
    17638                                                        ox = (float) (Math.cos(ix));
    17639                                                        oaf32data[it.oIndex + j] = ox;
    17640                                                }
    17641                                        }
    17642                                }
    17643                        }
    17644                        break;
    17645                case Dataset.ARRAYFLOAT64:
    17646                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    17647                        if (is == 1) {
    17648                                if (it.isOutputDouble()) {
    17649                                        while (it.hasNext()) {
    17650                                                final double ix = it.aDouble;
    17651                                                double ox;
    17652                                                ox = (Math.cos(ix));
    17653                                                oaf64data[it.oIndex] = ox;
    17654                                        }
    17655                                } else {
    17656                                        while (it.hasNext()) {
    17657                                                final long ix = it.aLong;
    17658                                                double ox;
    17659                                                ox = (Math.cos(ix));
    17660                                                oaf64data[it.oIndex] = ox;
    17661                                        }
    17662                                }
    17663                        } else if (as == 1) {
    17664                                if (it.isOutputDouble()) {
    17665                                        while (it.hasNext()) {
    17666                                                final double ix = it.aDouble;
    17667                                                double ox;
    17668                                                ox = (Math.cos(ix));
    17669                                                for (int j = 0; j < is; j++) {
    17670                                                        oaf64data[it.oIndex + j] = ox;
    17671                                                }
    17672                                        }
    17673                                } else {
    17674                                        while (it.hasNext()) {
    17675                                                final long ix = it.aLong;
    17676                                                double ox;
    17677                                                ox = (Math.cos(ix));
    17678                                                for (int j = 0; j < is; j++) {
    17679                                                        oaf64data[it.oIndex + j] = ox;
    17680                                                }
    17681                                        }
    17682                                }
    17683                        } else {
    17684                                if (it.isOutputDouble()) {
    17685                                        while (it.hasNext()) {
    17686                                                for (int j = 0; j < is; j++) {
    17687                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17688                                                        double ox;
    17689                                                        ox = (Math.cos(ix));
    17690                                                        oaf64data[it.oIndex + j] = ox;
    17691                                                }
    17692                                        }
    17693                                } else {
    17694                                        while (it.hasNext()) {
    17695                                                for (int j = 0; j < is; j++) {
    17696                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17697                                                        double ox;
    17698                                                        ox = (Math.cos(ix));
    17699                                                        oaf64data[it.oIndex + j] = ox;
    17700                                                }
    17701                                        }
    17702                                }
    17703                        }
    17704                        break;
    17705                case Dataset.COMPLEX64:
    17706                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    17707                        if (as == 1) {
    17708                                final double iy = 0;
    17709                                while (it.hasNext()) {
    17710                                        final double ix = it.aDouble;
    17711                                        float ox;
    17712                                        float oy;
    17713                                        ox = (float) (Math.cos(ix)*Math.cosh(iy));
    17714                                        oy = (float) (-Math.sin(ix)*Math.sinh(iy));
    17715                                        oc64data[it.oIndex] = ox;
    17716                                        oc64data[it.oIndex + 1] = oy;
    17717                                }
    17718                        } else {
    17719                                while (it.hasNext()) {
    17720                                        final double ix = it.aDouble;
    17721                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    17722                                        float ox;
    17723                                        float oy;
    17724                                        ox = (float) (Math.cos(ix)*Math.cosh(iy));
    17725                                        oy = (float) (-Math.sin(ix)*Math.sinh(iy));
    17726                                        oc64data[it.oIndex] = ox;
    17727                                        oc64data[it.oIndex + 1] = oy;
    17728                                }
    17729                        }
    17730                        break;
    17731                case Dataset.COMPLEX128:
    17732                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    17733                        if (as == 1) {
    17734                                final double iy = 0;
    17735                                while (it.hasNext()) {
    17736                                        final double ix = it.aDouble;
    17737                                        double ox;
    17738                                        double oy;
    17739                                        ox = (Math.cos(ix)*Math.cosh(iy));
    17740                                        oy = (-Math.sin(ix)*Math.sinh(iy));
    17741                                        oc128data[it.oIndex] = ox;
    17742                                        oc128data[it.oIndex + 1] = oy;
    17743                                }
    17744                        } else {
    17745                                while (it.hasNext()) {
    17746                                        final double ix = it.aDouble;
    17747                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    17748                                        double ox;
    17749                                        double oy;
    17750                                        ox = (Math.cos(ix)*Math.cosh(iy));
    17751                                        oy = (-Math.sin(ix)*Math.sinh(iy));
    17752                                        oc128data[it.oIndex] = ox;
    17753                                        oc128data[it.oIndex + 1] = oy;
    17754                                }
    17755                        }
    17756                        break;
    17757                default:
    17758                        throw new IllegalArgumentException("cos supports integer, compound integer, real, compound real, complex datasets only");
    17759                }
    17760
    17761                addFunctionName(result, "cos");
    17762                return result;
    17763        }
    17764
    17765        /**
    17766         * tan - evaluate the tangent function on each element of the dataset
    17767         * @param a
    17768         * @return dataset
    17769         */
    17770        public static Dataset tan(final Object a) {
    17771                return tan(a, null);
    17772        }
    17773
    17774        /**
    17775         * tan - evaluate the tangent function on each element of the dataset
    17776         * @param a
    17777         * @param o output can be null - in which case, a new dataset is created
    17778         * @return dataset
    17779         */
    17780        public static Dataset tan(final Object a, final Dataset o) {
    17781                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    17782                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    17783                final Dataset result = it.getOutput();
    17784                final int is = result.getElementsPerItem();
    17785                final int as = da.getElementsPerItem();
    17786                final int dt = result.getDType();
    17787
    17788                switch(dt) {
    17789                case Dataset.INT8:
    17790                        final byte[] oi8data = ((ByteDataset) result).getData();
    17791                        if (it.isOutputDouble()) {
    17792                                while (it.hasNext()) {
    17793                                        final double ix = it.aDouble;
    17794                                        byte ox;
    17795                                        ox = (byte) toLong(Math.tan(ix));
    17796                                        oi8data[it.oIndex] = ox;
    17797                                }
    17798                        } else {
    17799                                while (it.hasNext()) {
    17800                                        final long ix = it.aLong;
    17801                                        byte ox;
    17802                                        ox = (byte) toLong(Math.tan(ix));
    17803                                        oi8data[it.oIndex] = ox;
    17804                                }
    17805                        }
    17806                        break;
    17807                case Dataset.INT16:
    17808                        final short[] oi16data = ((ShortDataset) result).getData();
    17809                        if (it.isOutputDouble()) {
    17810                                while (it.hasNext()) {
    17811                                        final double ix = it.aDouble;
    17812                                        short ox;
    17813                                        ox = (short) toLong(Math.tan(ix));
    17814                                        oi16data[it.oIndex] = ox;
    17815                                }
    17816                        } else {
    17817                                while (it.hasNext()) {
    17818                                        final long ix = it.aLong;
    17819                                        short ox;
    17820                                        ox = (short) toLong(Math.tan(ix));
    17821                                        oi16data[it.oIndex] = ox;
    17822                                }
    17823                        }
    17824                        break;
    17825                case Dataset.INT64:
    17826                        final long[] oi64data = ((LongDataset) result).getData();
    17827                        if (it.isOutputDouble()) {
    17828                                while (it.hasNext()) {
    17829                                        final double ix = it.aDouble;
    17830                                        long ox;
    17831                                        ox = toLong(Math.tan(ix));
    17832                                        oi64data[it.oIndex] = ox;
    17833                                }
    17834                        } else {
    17835                                while (it.hasNext()) {
    17836                                        final long ix = it.aLong;
    17837                                        long ox;
    17838                                        ox = toLong(Math.tan(ix));
    17839                                        oi64data[it.oIndex] = ox;
    17840                                }
    17841                        }
    17842                        break;
    17843                case Dataset.INT32:
    17844                        final int[] oi32data = ((IntegerDataset) result).getData();
    17845                        if (it.isOutputDouble()) {
    17846                                while (it.hasNext()) {
    17847                                        final double ix = it.aDouble;
    17848                                        int ox;
    17849                                        ox = (int) toLong(Math.tan(ix));
    17850                                        oi32data[it.oIndex] = ox;
    17851                                }
    17852                        } else {
    17853                                while (it.hasNext()) {
    17854                                        final long ix = it.aLong;
    17855                                        int ox;
    17856                                        ox = (int) toLong(Math.tan(ix));
    17857                                        oi32data[it.oIndex] = ox;
    17858                                }
    17859                        }
    17860                        break;
    17861                case Dataset.ARRAYINT8:
    17862                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    17863                        if (is == 1) {
    17864                                if (it.isOutputDouble()) {
    17865                                        while (it.hasNext()) {
    17866                                                final double ix = it.aDouble;
    17867                                                byte ox;
    17868                                                ox = (byte) toLong(Math.tan(ix));
    17869                                                oai8data[it.oIndex] = ox;
    17870                                        }
    17871                                } else {
    17872                                        while (it.hasNext()) {
    17873                                                final long ix = it.aLong;
    17874                                                byte ox;
    17875                                                ox = (byte) toLong(Math.tan(ix));
    17876                                                oai8data[it.oIndex] = ox;
    17877                                        }
    17878                                }
    17879                        } else if (as == 1) {
    17880                                if (it.isOutputDouble()) {
    17881                                        while (it.hasNext()) {
    17882                                                final double ix = it.aDouble;
    17883                                                byte ox;
    17884                                                ox = (byte) toLong(Math.tan(ix));
    17885                                                for (int j = 0; j < is; j++) {
    17886                                                        oai8data[it.oIndex + j] = ox;
    17887                                                }
    17888                                        }
    17889                                } else {
    17890                                        while (it.hasNext()) {
    17891                                                final long ix = it.aLong;
    17892                                                byte ox;
    17893                                                ox = (byte) toLong(Math.tan(ix));
    17894                                                for (int j = 0; j < is; j++) {
    17895                                                        oai8data[it.oIndex + j] = ox;
    17896                                                }
    17897                                        }
    17898                                }
    17899                        } else {
    17900                                if (it.isOutputDouble()) {
    17901                                        while (it.hasNext()) {
    17902                                                for (int j = 0; j < is; j++) {
    17903                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17904                                                        byte ox;
    17905                                                        ox = (byte) toLong(Math.tan(ix));
    17906                                                        oai8data[it.oIndex + j] = ox;
    17907                                                }
    17908                                        }
    17909                                } else {
    17910                                        while (it.hasNext()) {
    17911                                                for (int j = 0; j < is; j++) {
    17912                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17913                                                        byte ox;
    17914                                                        ox = (byte) toLong(Math.tan(ix));
    17915                                                        oai8data[it.oIndex + j] = ox;
    17916                                                }
    17917                                        }
    17918                                }
    17919                        }
    17920                        break;
    17921                case Dataset.ARRAYINT16:
    17922                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    17923                        if (is == 1) {
    17924                                if (it.isOutputDouble()) {
    17925                                        while (it.hasNext()) {
    17926                                                final double ix = it.aDouble;
    17927                                                short ox;
    17928                                                ox = (short) toLong(Math.tan(ix));
    17929                                                oai16data[it.oIndex] = ox;
    17930                                        }
    17931                                } else {
    17932                                        while (it.hasNext()) {
    17933                                                final long ix = it.aLong;
    17934                                                short ox;
    17935                                                ox = (short) toLong(Math.tan(ix));
    17936                                                oai16data[it.oIndex] = ox;
    17937                                        }
    17938                                }
    17939                        } else if (as == 1) {
    17940                                if (it.isOutputDouble()) {
    17941                                        while (it.hasNext()) {
    17942                                                final double ix = it.aDouble;
    17943                                                short ox;
    17944                                                ox = (short) toLong(Math.tan(ix));
    17945                                                for (int j = 0; j < is; j++) {
    17946                                                        oai16data[it.oIndex + j] = ox;
    17947                                                }
    17948                                        }
    17949                                } else {
    17950                                        while (it.hasNext()) {
    17951                                                final long ix = it.aLong;
    17952                                                short ox;
    17953                                                ox = (short) toLong(Math.tan(ix));
    17954                                                for (int j = 0; j < is; j++) {
    17955                                                        oai16data[it.oIndex + j] = ox;
    17956                                                }
    17957                                        }
    17958                                }
    17959                        } else {
    17960                                if (it.isOutputDouble()) {
    17961                                        while (it.hasNext()) {
    17962                                                for (int j = 0; j < is; j++) {
    17963                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    17964                                                        short ox;
    17965                                                        ox = (short) toLong(Math.tan(ix));
    17966                                                        oai16data[it.oIndex + j] = ox;
    17967                                                }
    17968                                        }
    17969                                } else {
    17970                                        while (it.hasNext()) {
    17971                                                for (int j = 0; j < is; j++) {
    17972                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    17973                                                        short ox;
    17974                                                        ox = (short) toLong(Math.tan(ix));
    17975                                                        oai16data[it.oIndex + j] = ox;
    17976                                                }
    17977                                        }
    17978                                }
    17979                        }
    17980                        break;
    17981                case Dataset.ARRAYINT64:
    17982                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    17983                        if (is == 1) {
    17984                                if (it.isOutputDouble()) {
    17985                                        while (it.hasNext()) {
    17986                                                final double ix = it.aDouble;
    17987                                                long ox;
    17988                                                ox = toLong(Math.tan(ix));
    17989                                                oai64data[it.oIndex] = ox;
    17990                                        }
    17991                                } else {
    17992                                        while (it.hasNext()) {
    17993                                                final long ix = it.aLong;
    17994                                                long ox;
    17995                                                ox = toLong(Math.tan(ix));
    17996                                                oai64data[it.oIndex] = ox;
    17997                                        }
    17998                                }
    17999                        } else if (as == 1) {
    18000                                if (it.isOutputDouble()) {
    18001                                        while (it.hasNext()) {
    18002                                                final double ix = it.aDouble;
    18003                                                long ox;
    18004                                                ox = toLong(Math.tan(ix));
    18005                                                for (int j = 0; j < is; j++) {
    18006                                                        oai64data[it.oIndex + j] = ox;
    18007                                                }
    18008                                        }
    18009                                } else {
    18010                                        while (it.hasNext()) {
    18011                                                final long ix = it.aLong;
    18012                                                long ox;
    18013                                                ox = toLong(Math.tan(ix));
    18014                                                for (int j = 0; j < is; j++) {
    18015                                                        oai64data[it.oIndex + j] = ox;
    18016                                                }
    18017                                        }
    18018                                }
    18019                        } else {
    18020                                if (it.isOutputDouble()) {
    18021                                        while (it.hasNext()) {
    18022                                                for (int j = 0; j < is; j++) {
    18023                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18024                                                        long ox;
    18025                                                        ox = toLong(Math.tan(ix));
    18026                                                        oai64data[it.oIndex + j] = ox;
    18027                                                }
    18028                                        }
    18029                                } else {
    18030                                        while (it.hasNext()) {
    18031                                                for (int j = 0; j < is; j++) {
    18032                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18033                                                        long ox;
    18034                                                        ox = toLong(Math.tan(ix));
    18035                                                        oai64data[it.oIndex + j] = ox;
    18036                                                }
    18037                                        }
    18038                                }
    18039                        }
    18040                        break;
    18041                case Dataset.ARRAYINT32:
    18042                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    18043                        if (is == 1) {
    18044                                if (it.isOutputDouble()) {
    18045                                        while (it.hasNext()) {
    18046                                                final double ix = it.aDouble;
    18047                                                int ox;
    18048                                                ox = (int) toLong(Math.tan(ix));
    18049                                                oai32data[it.oIndex] = ox;
    18050                                        }
    18051                                } else {
    18052                                        while (it.hasNext()) {
    18053                                                final long ix = it.aLong;
    18054                                                int ox;
    18055                                                ox = (int) toLong(Math.tan(ix));
    18056                                                oai32data[it.oIndex] = ox;
    18057                                        }
    18058                                }
    18059                        } else if (as == 1) {
    18060                                if (it.isOutputDouble()) {
    18061                                        while (it.hasNext()) {
    18062                                                final double ix = it.aDouble;
    18063                                                int ox;
    18064                                                ox = (int) toLong(Math.tan(ix));
    18065                                                for (int j = 0; j < is; j++) {
    18066                                                        oai32data[it.oIndex + j] = ox;
    18067                                                }
    18068                                        }
    18069                                } else {
    18070                                        while (it.hasNext()) {
    18071                                                final long ix = it.aLong;
    18072                                                int ox;
    18073                                                ox = (int) toLong(Math.tan(ix));
    18074                                                for (int j = 0; j < is; j++) {
    18075                                                        oai32data[it.oIndex + j] = ox;
    18076                                                }
    18077                                        }
    18078                                }
    18079                        } else {
    18080                                if (it.isOutputDouble()) {
    18081                                        while (it.hasNext()) {
    18082                                                for (int j = 0; j < is; j++) {
    18083                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18084                                                        int ox;
    18085                                                        ox = (int) toLong(Math.tan(ix));
    18086                                                        oai32data[it.oIndex + j] = ox;
    18087                                                }
    18088                                        }
    18089                                } else {
    18090                                        while (it.hasNext()) {
    18091                                                for (int j = 0; j < is; j++) {
    18092                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18093                                                        int ox;
    18094                                                        ox = (int) toLong(Math.tan(ix));
    18095                                                        oai32data[it.oIndex + j] = ox;
    18096                                                }
    18097                                        }
    18098                                }
    18099                        }
    18100                        break;
    18101                case Dataset.FLOAT32:
    18102                        final float[] of32data = ((FloatDataset) result).getData();
    18103                        if (it.isOutputDouble()) {
    18104                                while (it.hasNext()) {
    18105                                        final double ix = it.aDouble;
    18106                                        float ox;
    18107                                        ox = (float) (Math.tan(ix));
    18108                                        of32data[it.oIndex] = ox;
    18109                                }
    18110                        } else {
    18111                                while (it.hasNext()) {
    18112                                        final long ix = it.aLong;
    18113                                        float ox;
    18114                                        ox = (float) (Math.tan(ix));
    18115                                        of32data[it.oIndex] = ox;
    18116                                }
    18117                        }
    18118                        break;
    18119                case Dataset.FLOAT64:
    18120                        final double[] of64data = ((DoubleDataset) result).getData();
    18121                        if (it.isOutputDouble()) {
    18122                                while (it.hasNext()) {
    18123                                        final double ix = it.aDouble;
    18124                                        double ox;
    18125                                        ox = (Math.tan(ix));
    18126                                        of64data[it.oIndex] = ox;
    18127                                }
    18128                        } else {
    18129                                while (it.hasNext()) {
    18130                                        final long ix = it.aLong;
    18131                                        double ox;
    18132                                        ox = (Math.tan(ix));
    18133                                        of64data[it.oIndex] = ox;
    18134                                }
    18135                        }
    18136                        break;
    18137                case Dataset.ARRAYFLOAT32:
    18138                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    18139                        if (is == 1) {
    18140                                if (it.isOutputDouble()) {
    18141                                        while (it.hasNext()) {
    18142                                                final double ix = it.aDouble;
    18143                                                float ox;
    18144                                                ox = (float) (Math.tan(ix));
    18145                                                oaf32data[it.oIndex] = ox;
    18146                                        }
    18147                                } else {
    18148                                        while (it.hasNext()) {
    18149                                                final long ix = it.aLong;
    18150                                                float ox;
    18151                                                ox = (float) (Math.tan(ix));
    18152                                                oaf32data[it.oIndex] = ox;
    18153                                        }
    18154                                }
    18155                        } else if (as == 1) {
    18156                                if (it.isOutputDouble()) {
    18157                                        while (it.hasNext()) {
    18158                                                final double ix = it.aDouble;
    18159                                                float ox;
    18160                                                ox = (float) (Math.tan(ix));
    18161                                                for (int j = 0; j < is; j++) {
    18162                                                        oaf32data[it.oIndex + j] = ox;
    18163                                                }
    18164                                        }
    18165                                } else {
    18166                                        while (it.hasNext()) {
    18167                                                final long ix = it.aLong;
    18168                                                float ox;
    18169                                                ox = (float) (Math.tan(ix));
    18170                                                for (int j = 0; j < is; j++) {
    18171                                                        oaf32data[it.oIndex + j] = ox;
    18172                                                }
    18173                                        }
    18174                                }
    18175                        } else {
    18176                                if (it.isOutputDouble()) {
    18177                                        while (it.hasNext()) {
    18178                                                for (int j = 0; j < is; j++) {
    18179                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18180                                                        float ox;
    18181                                                        ox = (float) (Math.tan(ix));
    18182                                                        oaf32data[it.oIndex + j] = ox;
    18183                                                }
    18184                                        }
    18185                                } else {
    18186                                        while (it.hasNext()) {
    18187                                                for (int j = 0; j < is; j++) {
    18188                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18189                                                        float ox;
    18190                                                        ox = (float) (Math.tan(ix));
    18191                                                        oaf32data[it.oIndex + j] = ox;
    18192                                                }
    18193                                        }
    18194                                }
    18195                        }
    18196                        break;
    18197                case Dataset.ARRAYFLOAT64:
    18198                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    18199                        if (is == 1) {
    18200                                if (it.isOutputDouble()) {
    18201                                        while (it.hasNext()) {
    18202                                                final double ix = it.aDouble;
    18203                                                double ox;
    18204                                                ox = (Math.tan(ix));
    18205                                                oaf64data[it.oIndex] = ox;
    18206                                        }
    18207                                } else {
    18208                                        while (it.hasNext()) {
    18209                                                final long ix = it.aLong;
    18210                                                double ox;
    18211                                                ox = (Math.tan(ix));
    18212                                                oaf64data[it.oIndex] = ox;
    18213                                        }
    18214                                }
    18215                        } else if (as == 1) {
    18216                                if (it.isOutputDouble()) {
    18217                                        while (it.hasNext()) {
    18218                                                final double ix = it.aDouble;
    18219                                                double ox;
    18220                                                ox = (Math.tan(ix));
    18221                                                for (int j = 0; j < is; j++) {
    18222                                                        oaf64data[it.oIndex + j] = ox;
    18223                                                }
    18224                                        }
    18225                                } else {
    18226                                        while (it.hasNext()) {
    18227                                                final long ix = it.aLong;
    18228                                                double ox;
    18229                                                ox = (Math.tan(ix));
    18230                                                for (int j = 0; j < is; j++) {
    18231                                                        oaf64data[it.oIndex + j] = ox;
    18232                                                }
    18233                                        }
    18234                                }
    18235                        } else {
    18236                                if (it.isOutputDouble()) {
    18237                                        while (it.hasNext()) {
    18238                                                for (int j = 0; j < is; j++) {
    18239                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18240                                                        double ox;
    18241                                                        ox = (Math.tan(ix));
    18242                                                        oaf64data[it.oIndex + j] = ox;
    18243                                                }
    18244                                        }
    18245                                } else {
    18246                                        while (it.hasNext()) {
    18247                                                for (int j = 0; j < is; j++) {
    18248                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18249                                                        double ox;
    18250                                                        ox = (Math.tan(ix));
    18251                                                        oaf64data[it.oIndex + j] = ox;
    18252                                                }
    18253                                        }
    18254                                }
    18255                        }
    18256                        break;
    18257                case Dataset.COMPLEX64:
    18258                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    18259                        if (as == 1) {
    18260                                final double iy = 0;
    18261                                while (it.hasNext()) {
    18262                                        final double ix = it.aDouble;
    18263                                        float x;
    18264                                        float y;
    18265                                        float tf;
    18266                                        float ox;
    18267                                        float oy;
    18268                                        x = (float) (2.*ix);
    18269                                        y = (float) (2.*iy);
    18270                                        tf = (float) (1./(Math.cos(x)+Math.cosh(y)));
    18271                                        ox = (float) (tf*Math.sin(x));
    18272                                        oy = (float) (tf*Math.sinh(y));
    18273                                        oc64data[it.oIndex] = ox;
    18274                                        oc64data[it.oIndex + 1] = oy;
    18275                                }
    18276                        } else {
    18277                                while (it.hasNext()) {
    18278                                        final double ix = it.aDouble;
    18279                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    18280                                        float x;
    18281                                        float y;
    18282                                        float tf;
    18283                                        float ox;
    18284                                        float oy;
    18285                                        x = (float) (2.*ix);
    18286                                        y = (float) (2.*iy);
    18287                                        tf = (float) (1./(Math.cos(x)+Math.cosh(y)));
    18288                                        ox = (float) (tf*Math.sin(x));
    18289                                        oy = (float) (tf*Math.sinh(y));
    18290                                        oc64data[it.oIndex] = ox;
    18291                                        oc64data[it.oIndex + 1] = oy;
    18292                                }
    18293                        }
    18294                        break;
    18295                case Dataset.COMPLEX128:
    18296                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    18297                        if (as == 1) {
    18298                                final double iy = 0;
    18299                                while (it.hasNext()) {
    18300                                        final double ix = it.aDouble;
    18301                                        double x;
    18302                                        double y;
    18303                                        double tf;
    18304                                        double ox;
    18305                                        double oy;
    18306                                        x = (2.*ix);
    18307                                        y = (2.*iy);
    18308                                        tf = (1./(Math.cos(x)+Math.cosh(y)));
    18309                                        ox = (tf*Math.sin(x));
    18310                                        oy = (tf*Math.sinh(y));
    18311                                        oc128data[it.oIndex] = ox;
    18312                                        oc128data[it.oIndex + 1] = oy;
    18313                                }
    18314                        } else {
    18315                                while (it.hasNext()) {
    18316                                        final double ix = it.aDouble;
    18317                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    18318                                        double x;
    18319                                        double y;
    18320                                        double tf;
    18321                                        double ox;
    18322                                        double oy;
    18323                                        x = (2.*ix);
    18324                                        y = (2.*iy);
    18325                                        tf = (1./(Math.cos(x)+Math.cosh(y)));
    18326                                        ox = (tf*Math.sin(x));
    18327                                        oy = (tf*Math.sinh(y));
    18328                                        oc128data[it.oIndex] = ox;
    18329                                        oc128data[it.oIndex + 1] = oy;
    18330                                }
    18331                        }
    18332                        break;
    18333                default:
    18334                        throw new IllegalArgumentException("tan supports integer, compound integer, real, compound real, complex datasets only");
    18335                }
    18336
    18337                addFunctionName(result, "tan");
    18338                return result;
    18339        }
    18340
    18341        /**
    18342         * arcsin - evaluate the inverse sine function on each element of the dataset
    18343         * @param a
    18344         * @return dataset
    18345         */
    18346        public static Dataset arcsin(final Object a) {
    18347                return arcsin(a, null);
    18348        }
    18349
    18350        /**
    18351         * arcsin - evaluate the inverse sine function on each element of the dataset
    18352         * @param a
    18353         * @param o output can be null - in which case, a new dataset is created
    18354         * @return dataset
    18355         */
    18356        public static Dataset arcsin(final Object a, final Dataset o) {
    18357                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    18358                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    18359                final Dataset result = it.getOutput();
    18360                final int is = result.getElementsPerItem();
    18361                final int as = da.getElementsPerItem();
    18362                final int dt = result.getDType();
    18363
    18364                switch(dt) {
    18365                case Dataset.INT8:
    18366                        final byte[] oi8data = ((ByteDataset) result).getData();
    18367                        if (it.isOutputDouble()) {
    18368                                while (it.hasNext()) {
    18369                                        final double ix = it.aDouble;
    18370                                        byte ox;
    18371                                        ox = (byte) toLong(Math.asin(ix));
    18372                                        oi8data[it.oIndex] = ox;
    18373                                }
    18374                        } else {
    18375                                while (it.hasNext()) {
    18376                                        final long ix = it.aLong;
    18377                                        byte ox;
    18378                                        ox = (byte) toLong(Math.asin(ix));
    18379                                        oi8data[it.oIndex] = ox;
    18380                                }
    18381                        }
    18382                        break;
    18383                case Dataset.INT16:
    18384                        final short[] oi16data = ((ShortDataset) result).getData();
    18385                        if (it.isOutputDouble()) {
    18386                                while (it.hasNext()) {
    18387                                        final double ix = it.aDouble;
    18388                                        short ox;
    18389                                        ox = (short) toLong(Math.asin(ix));
    18390                                        oi16data[it.oIndex] = ox;
    18391                                }
    18392                        } else {
    18393                                while (it.hasNext()) {
    18394                                        final long ix = it.aLong;
    18395                                        short ox;
    18396                                        ox = (short) toLong(Math.asin(ix));
    18397                                        oi16data[it.oIndex] = ox;
    18398                                }
    18399                        }
    18400                        break;
    18401                case Dataset.INT64:
    18402                        final long[] oi64data = ((LongDataset) result).getData();
    18403                        if (it.isOutputDouble()) {
    18404                                while (it.hasNext()) {
    18405                                        final double ix = it.aDouble;
    18406                                        long ox;
    18407                                        ox = toLong(Math.asin(ix));
    18408                                        oi64data[it.oIndex] = ox;
    18409                                }
    18410                        } else {
    18411                                while (it.hasNext()) {
    18412                                        final long ix = it.aLong;
    18413                                        long ox;
    18414                                        ox = toLong(Math.asin(ix));
    18415                                        oi64data[it.oIndex] = ox;
    18416                                }
    18417                        }
    18418                        break;
    18419                case Dataset.INT32:
    18420                        final int[] oi32data = ((IntegerDataset) result).getData();
    18421                        if (it.isOutputDouble()) {
    18422                                while (it.hasNext()) {
    18423                                        final double ix = it.aDouble;
    18424                                        int ox;
    18425                                        ox = (int) toLong(Math.asin(ix));
    18426                                        oi32data[it.oIndex] = ox;
    18427                                }
    18428                        } else {
    18429                                while (it.hasNext()) {
    18430                                        final long ix = it.aLong;
    18431                                        int ox;
    18432                                        ox = (int) toLong(Math.asin(ix));
    18433                                        oi32data[it.oIndex] = ox;
    18434                                }
    18435                        }
    18436                        break;
    18437                case Dataset.ARRAYINT8:
    18438                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    18439                        if (is == 1) {
    18440                                if (it.isOutputDouble()) {
    18441                                        while (it.hasNext()) {
    18442                                                final double ix = it.aDouble;
    18443                                                byte ox;
    18444                                                ox = (byte) toLong(Math.asin(ix));
    18445                                                oai8data[it.oIndex] = ox;
    18446                                        }
    18447                                } else {
    18448                                        while (it.hasNext()) {
    18449                                                final long ix = it.aLong;
    18450                                                byte ox;
    18451                                                ox = (byte) toLong(Math.asin(ix));
    18452                                                oai8data[it.oIndex] = ox;
    18453                                        }
    18454                                }
    18455                        } else if (as == 1) {
    18456                                if (it.isOutputDouble()) {
    18457                                        while (it.hasNext()) {
    18458                                                final double ix = it.aDouble;
    18459                                                byte ox;
    18460                                                ox = (byte) toLong(Math.asin(ix));
    18461                                                for (int j = 0; j < is; j++) {
    18462                                                        oai8data[it.oIndex + j] = ox;
    18463                                                }
    18464                                        }
    18465                                } else {
    18466                                        while (it.hasNext()) {
    18467                                                final long ix = it.aLong;
    18468                                                byte ox;
    18469                                                ox = (byte) toLong(Math.asin(ix));
    18470                                                for (int j = 0; j < is; j++) {
    18471                                                        oai8data[it.oIndex + j] = ox;
    18472                                                }
    18473                                        }
    18474                                }
    18475                        } else {
    18476                                if (it.isOutputDouble()) {
    18477                                        while (it.hasNext()) {
    18478                                                for (int j = 0; j < is; j++) {
    18479                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18480                                                        byte ox;
    18481                                                        ox = (byte) toLong(Math.asin(ix));
    18482                                                        oai8data[it.oIndex + j] = ox;
    18483                                                }
    18484                                        }
    18485                                } else {
    18486                                        while (it.hasNext()) {
    18487                                                for (int j = 0; j < is; j++) {
    18488                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18489                                                        byte ox;
    18490                                                        ox = (byte) toLong(Math.asin(ix));
    18491                                                        oai8data[it.oIndex + j] = ox;
    18492                                                }
    18493                                        }
    18494                                }
    18495                        }
    18496                        break;
    18497                case Dataset.ARRAYINT16:
    18498                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    18499                        if (is == 1) {
    18500                                if (it.isOutputDouble()) {
    18501                                        while (it.hasNext()) {
    18502                                                final double ix = it.aDouble;
    18503                                                short ox;
    18504                                                ox = (short) toLong(Math.asin(ix));
    18505                                                oai16data[it.oIndex] = ox;
    18506                                        }
    18507                                } else {
    18508                                        while (it.hasNext()) {
    18509                                                final long ix = it.aLong;
    18510                                                short ox;
    18511                                                ox = (short) toLong(Math.asin(ix));
    18512                                                oai16data[it.oIndex] = ox;
    18513                                        }
    18514                                }
    18515                        } else if (as == 1) {
    18516                                if (it.isOutputDouble()) {
    18517                                        while (it.hasNext()) {
    18518                                                final double ix = it.aDouble;
    18519                                                short ox;
    18520                                                ox = (short) toLong(Math.asin(ix));
    18521                                                for (int j = 0; j < is; j++) {
    18522                                                        oai16data[it.oIndex + j] = ox;
    18523                                                }
    18524                                        }
    18525                                } else {
    18526                                        while (it.hasNext()) {
    18527                                                final long ix = it.aLong;
    18528                                                short ox;
    18529                                                ox = (short) toLong(Math.asin(ix));
    18530                                                for (int j = 0; j < is; j++) {
    18531                                                        oai16data[it.oIndex + j] = ox;
    18532                                                }
    18533                                        }
    18534                                }
    18535                        } else {
    18536                                if (it.isOutputDouble()) {
    18537                                        while (it.hasNext()) {
    18538                                                for (int j = 0; j < is; j++) {
    18539                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18540                                                        short ox;
    18541                                                        ox = (short) toLong(Math.asin(ix));
    18542                                                        oai16data[it.oIndex + j] = ox;
    18543                                                }
    18544                                        }
    18545                                } else {
    18546                                        while (it.hasNext()) {
    18547                                                for (int j = 0; j < is; j++) {
    18548                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18549                                                        short ox;
    18550                                                        ox = (short) toLong(Math.asin(ix));
    18551                                                        oai16data[it.oIndex + j] = ox;
    18552                                                }
    18553                                        }
    18554                                }
    18555                        }
    18556                        break;
    18557                case Dataset.ARRAYINT64:
    18558                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    18559                        if (is == 1) {
    18560                                if (it.isOutputDouble()) {
    18561                                        while (it.hasNext()) {
    18562                                                final double ix = it.aDouble;
    18563                                                long ox;
    18564                                                ox = toLong(Math.asin(ix));
    18565                                                oai64data[it.oIndex] = ox;
    18566                                        }
    18567                                } else {
    18568                                        while (it.hasNext()) {
    18569                                                final long ix = it.aLong;
    18570                                                long ox;
    18571                                                ox = toLong(Math.asin(ix));
    18572                                                oai64data[it.oIndex] = ox;
    18573                                        }
    18574                                }
    18575                        } else if (as == 1) {
    18576                                if (it.isOutputDouble()) {
    18577                                        while (it.hasNext()) {
    18578                                                final double ix = it.aDouble;
    18579                                                long ox;
    18580                                                ox = toLong(Math.asin(ix));
    18581                                                for (int j = 0; j < is; j++) {
    18582                                                        oai64data[it.oIndex + j] = ox;
    18583                                                }
    18584                                        }
    18585                                } else {
    18586                                        while (it.hasNext()) {
    18587                                                final long ix = it.aLong;
    18588                                                long ox;
    18589                                                ox = toLong(Math.asin(ix));
    18590                                                for (int j = 0; j < is; j++) {
    18591                                                        oai64data[it.oIndex + j] = ox;
    18592                                                }
    18593                                        }
    18594                                }
    18595                        } else {
    18596                                if (it.isOutputDouble()) {
    18597                                        while (it.hasNext()) {
    18598                                                for (int j = 0; j < is; j++) {
    18599                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18600                                                        long ox;
    18601                                                        ox = toLong(Math.asin(ix));
    18602                                                        oai64data[it.oIndex + j] = ox;
    18603                                                }
    18604                                        }
    18605                                } else {
    18606                                        while (it.hasNext()) {
    18607                                                for (int j = 0; j < is; j++) {
    18608                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18609                                                        long ox;
    18610                                                        ox = toLong(Math.asin(ix));
    18611                                                        oai64data[it.oIndex + j] = ox;
    18612                                                }
    18613                                        }
    18614                                }
    18615                        }
    18616                        break;
    18617                case Dataset.ARRAYINT32:
    18618                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    18619                        if (is == 1) {
    18620                                if (it.isOutputDouble()) {
    18621                                        while (it.hasNext()) {
    18622                                                final double ix = it.aDouble;
    18623                                                int ox;
    18624                                                ox = (int) toLong(Math.asin(ix));
    18625                                                oai32data[it.oIndex] = ox;
    18626                                        }
    18627                                } else {
    18628                                        while (it.hasNext()) {
    18629                                                final long ix = it.aLong;
    18630                                                int ox;
    18631                                                ox = (int) toLong(Math.asin(ix));
    18632                                                oai32data[it.oIndex] = ox;
    18633                                        }
    18634                                }
    18635                        } else if (as == 1) {
    18636                                if (it.isOutputDouble()) {
    18637                                        while (it.hasNext()) {
    18638                                                final double ix = it.aDouble;
    18639                                                int ox;
    18640                                                ox = (int) toLong(Math.asin(ix));
    18641                                                for (int j = 0; j < is; j++) {
    18642                                                        oai32data[it.oIndex + j] = ox;
    18643                                                }
    18644                                        }
    18645                                } else {
    18646                                        while (it.hasNext()) {
    18647                                                final long ix = it.aLong;
    18648                                                int ox;
    18649                                                ox = (int) toLong(Math.asin(ix));
    18650                                                for (int j = 0; j < is; j++) {
    18651                                                        oai32data[it.oIndex + j] = ox;
    18652                                                }
    18653                                        }
    18654                                }
    18655                        } else {
    18656                                if (it.isOutputDouble()) {
    18657                                        while (it.hasNext()) {
    18658                                                for (int j = 0; j < is; j++) {
    18659                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18660                                                        int ox;
    18661                                                        ox = (int) toLong(Math.asin(ix));
    18662                                                        oai32data[it.oIndex + j] = ox;
    18663                                                }
    18664                                        }
    18665                                } else {
    18666                                        while (it.hasNext()) {
    18667                                                for (int j = 0; j < is; j++) {
    18668                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18669                                                        int ox;
    18670                                                        ox = (int) toLong(Math.asin(ix));
    18671                                                        oai32data[it.oIndex + j] = ox;
    18672                                                }
    18673                                        }
    18674                                }
    18675                        }
    18676                        break;
    18677                case Dataset.FLOAT32:
    18678                        final float[] of32data = ((FloatDataset) result).getData();
    18679                        if (it.isOutputDouble()) {
    18680                                while (it.hasNext()) {
    18681                                        final double ix = it.aDouble;
    18682                                        float ox;
    18683                                        ox = (float) (Math.asin(ix));
    18684                                        of32data[it.oIndex] = ox;
    18685                                }
    18686                        } else {
    18687                                while (it.hasNext()) {
    18688                                        final long ix = it.aLong;
    18689                                        float ox;
    18690                                        ox = (float) (Math.asin(ix));
    18691                                        of32data[it.oIndex] = ox;
    18692                                }
    18693                        }
    18694                        break;
    18695                case Dataset.FLOAT64:
    18696                        final double[] of64data = ((DoubleDataset) result).getData();
    18697                        if (it.isOutputDouble()) {
    18698                                while (it.hasNext()) {
    18699                                        final double ix = it.aDouble;
    18700                                        double ox;
    18701                                        ox = (Math.asin(ix));
    18702                                        of64data[it.oIndex] = ox;
    18703                                }
    18704                        } else {
    18705                                while (it.hasNext()) {
    18706                                        final long ix = it.aLong;
    18707                                        double ox;
    18708                                        ox = (Math.asin(ix));
    18709                                        of64data[it.oIndex] = ox;
    18710                                }
    18711                        }
    18712                        break;
    18713                case Dataset.ARRAYFLOAT32:
    18714                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    18715                        if (is == 1) {
    18716                                if (it.isOutputDouble()) {
    18717                                        while (it.hasNext()) {
    18718                                                final double ix = it.aDouble;
    18719                                                float ox;
    18720                                                ox = (float) (Math.asin(ix));
    18721                                                oaf32data[it.oIndex] = ox;
    18722                                        }
    18723                                } else {
    18724                                        while (it.hasNext()) {
    18725                                                final long ix = it.aLong;
    18726                                                float ox;
    18727                                                ox = (float) (Math.asin(ix));
    18728                                                oaf32data[it.oIndex] = ox;
    18729                                        }
    18730                                }
    18731                        } else if (as == 1) {
    18732                                if (it.isOutputDouble()) {
    18733                                        while (it.hasNext()) {
    18734                                                final double ix = it.aDouble;
    18735                                                float ox;
    18736                                                ox = (float) (Math.asin(ix));
    18737                                                for (int j = 0; j < is; j++) {
    18738                                                        oaf32data[it.oIndex + j] = ox;
    18739                                                }
    18740                                        }
    18741                                } else {
    18742                                        while (it.hasNext()) {
    18743                                                final long ix = it.aLong;
    18744                                                float ox;
    18745                                                ox = (float) (Math.asin(ix));
    18746                                                for (int j = 0; j < is; j++) {
    18747                                                        oaf32data[it.oIndex + j] = ox;
    18748                                                }
    18749                                        }
    18750                                }
    18751                        } else {
    18752                                if (it.isOutputDouble()) {
    18753                                        while (it.hasNext()) {
    18754                                                for (int j = 0; j < is; j++) {
    18755                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18756                                                        float ox;
    18757                                                        ox = (float) (Math.asin(ix));
    18758                                                        oaf32data[it.oIndex + j] = ox;
    18759                                                }
    18760                                        }
    18761                                } else {
    18762                                        while (it.hasNext()) {
    18763                                                for (int j = 0; j < is; j++) {
    18764                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18765                                                        float ox;
    18766                                                        ox = (float) (Math.asin(ix));
    18767                                                        oaf32data[it.oIndex + j] = ox;
    18768                                                }
    18769                                        }
    18770                                }
    18771                        }
    18772                        break;
    18773                case Dataset.ARRAYFLOAT64:
    18774                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    18775                        if (is == 1) {
    18776                                if (it.isOutputDouble()) {
    18777                                        while (it.hasNext()) {
    18778                                                final double ix = it.aDouble;
    18779                                                double ox;
    18780                                                ox = (Math.asin(ix));
    18781                                                oaf64data[it.oIndex] = ox;
    18782                                        }
    18783                                } else {
    18784                                        while (it.hasNext()) {
    18785                                                final long ix = it.aLong;
    18786                                                double ox;
    18787                                                ox = (Math.asin(ix));
    18788                                                oaf64data[it.oIndex] = ox;
    18789                                        }
    18790                                }
    18791                        } else if (as == 1) {
    18792                                if (it.isOutputDouble()) {
    18793                                        while (it.hasNext()) {
    18794                                                final double ix = it.aDouble;
    18795                                                double ox;
    18796                                                ox = (Math.asin(ix));
    18797                                                for (int j = 0; j < is; j++) {
    18798                                                        oaf64data[it.oIndex + j] = ox;
    18799                                                }
    18800                                        }
    18801                                } else {
    18802                                        while (it.hasNext()) {
    18803                                                final long ix = it.aLong;
    18804                                                double ox;
    18805                                                ox = (Math.asin(ix));
    18806                                                for (int j = 0; j < is; j++) {
    18807                                                        oaf64data[it.oIndex + j] = ox;
    18808                                                }
    18809                                        }
    18810                                }
    18811                        } else {
    18812                                if (it.isOutputDouble()) {
    18813                                        while (it.hasNext()) {
    18814                                                for (int j = 0; j < is; j++) {
    18815                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    18816                                                        double ox;
    18817                                                        ox = (Math.asin(ix));
    18818                                                        oaf64data[it.oIndex + j] = ox;
    18819                                                }
    18820                                        }
    18821                                } else {
    18822                                        while (it.hasNext()) {
    18823                                                for (int j = 0; j < is; j++) {
    18824                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    18825                                                        double ox;
    18826                                                        ox = (Math.asin(ix));
    18827                                                        oaf64data[it.oIndex + j] = ox;
    18828                                                }
    18829                                        }
    18830                                }
    18831                        }
    18832                        break;
    18833                case Dataset.COMPLEX64:
    18834                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    18835                        if (as == 1) {
    18836                                final double iy = 0;
    18837                                while (it.hasNext()) {
    18838                                        final double ix = it.aDouble;
    18839                                        Complex tz;
    18840                                        float ox;
    18841                                        float oy;
    18842                                        tz = new Complex(ix, iy).asin();
    18843                                        ox = (float) (tz.getReal());
    18844                                        oy = (float) (tz.getImaginary());
    18845                                        oc64data[it.oIndex] = ox;
    18846                                        oc64data[it.oIndex + 1] = oy;
    18847                                }
    18848                        } else {
    18849                                while (it.hasNext()) {
    18850                                        final double ix = it.aDouble;
    18851                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    18852                                        Complex tz;
    18853                                        float ox;
    18854                                        float oy;
    18855                                        tz = new Complex(ix, iy).asin();
    18856                                        ox = (float) (tz.getReal());
    18857                                        oy = (float) (tz.getImaginary());
    18858                                        oc64data[it.oIndex] = ox;
    18859                                        oc64data[it.oIndex + 1] = oy;
    18860                                }
    18861                        }
    18862                        break;
    18863                case Dataset.COMPLEX128:
    18864                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    18865                        if (as == 1) {
    18866                                final double iy = 0;
    18867                                while (it.hasNext()) {
    18868                                        final double ix = it.aDouble;
    18869                                        Complex tz;
    18870                                        double ox;
    18871                                        double oy;
    18872                                        tz = new Complex(ix, iy).asin();
    18873                                        ox = (tz.getReal());
    18874                                        oy = (tz.getImaginary());
    18875                                        oc128data[it.oIndex] = ox;
    18876                                        oc128data[it.oIndex + 1] = oy;
    18877                                }
    18878                        } else {
    18879                                while (it.hasNext()) {
    18880                                        final double ix = it.aDouble;
    18881                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    18882                                        Complex tz;
    18883                                        double ox;
    18884                                        double oy;
    18885                                        tz = new Complex(ix, iy).asin();
    18886                                        ox = (tz.getReal());
    18887                                        oy = (tz.getImaginary());
    18888                                        oc128data[it.oIndex] = ox;
    18889                                        oc128data[it.oIndex + 1] = oy;
    18890                                }
    18891                        }
    18892                        break;
    18893                default:
    18894                        throw new IllegalArgumentException("arcsin supports integer, compound integer, real, compound real, complex datasets only");
    18895                }
    18896
    18897                addFunctionName(result, "arcsin");
    18898                return result;
    18899        }
    18900
    18901        /**
    18902         * arccos - evaluate the inverse cosine function on each element of the dataset
    18903         * @param a
    18904         * @return dataset
    18905         */
    18906        public static Dataset arccos(final Object a) {
    18907                return arccos(a, null);
    18908        }
    18909
    18910        /**
    18911         * arccos - evaluate the inverse cosine function on each element of the dataset
    18912         * @param a
    18913         * @param o output can be null - in which case, a new dataset is created
    18914         * @return dataset
    18915         */
    18916        public static Dataset arccos(final Object a, final Dataset o) {
    18917                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    18918                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    18919                final Dataset result = it.getOutput();
    18920                final int is = result.getElementsPerItem();
    18921                final int as = da.getElementsPerItem();
    18922                final int dt = result.getDType();
    18923
    18924                switch(dt) {
    18925                case Dataset.INT8:
    18926                        final byte[] oi8data = ((ByteDataset) result).getData();
    18927                        if (it.isOutputDouble()) {
    18928                                while (it.hasNext()) {
    18929                                        final double ix = it.aDouble;
    18930                                        byte ox;
    18931                                        ox = (byte) toLong(Math.acos(ix));
    18932                                        oi8data[it.oIndex] = ox;
    18933                                }
    18934                        } else {
    18935                                while (it.hasNext()) {
    18936                                        final long ix = it.aLong;
    18937                                        byte ox;
    18938                                        ox = (byte) toLong(Math.acos(ix));
    18939                                        oi8data[it.oIndex] = ox;
    18940                                }
    18941                        }
    18942                        break;
    18943                case Dataset.INT16:
    18944                        final short[] oi16data = ((ShortDataset) result).getData();
    18945                        if (it.isOutputDouble()) {
    18946                                while (it.hasNext()) {
    18947                                        final double ix = it.aDouble;
    18948                                        short ox;
    18949                                        ox = (short) toLong(Math.acos(ix));
    18950                                        oi16data[it.oIndex] = ox;
    18951                                }
    18952                        } else {
    18953                                while (it.hasNext()) {
    18954                                        final long ix = it.aLong;
    18955                                        short ox;
    18956                                        ox = (short) toLong(Math.acos(ix));
    18957                                        oi16data[it.oIndex] = ox;
    18958                                }
    18959                        }
    18960                        break;
    18961                case Dataset.INT64:
    18962                        final long[] oi64data = ((LongDataset) result).getData();
    18963                        if (it.isOutputDouble()) {
    18964                                while (it.hasNext()) {
    18965                                        final double ix = it.aDouble;
    18966                                        long ox;
    18967                                        ox = toLong(Math.acos(ix));
    18968                                        oi64data[it.oIndex] = ox;
    18969                                }
    18970                        } else {
    18971                                while (it.hasNext()) {
    18972                                        final long ix = it.aLong;
    18973                                        long ox;
    18974                                        ox = toLong(Math.acos(ix));
    18975                                        oi64data[it.oIndex] = ox;
    18976                                }
    18977                        }
    18978                        break;
    18979                case Dataset.INT32:
    18980                        final int[] oi32data = ((IntegerDataset) result).getData();
    18981                        if (it.isOutputDouble()) {
    18982                                while (it.hasNext()) {
    18983                                        final double ix = it.aDouble;
    18984                                        int ox;
    18985                                        ox = (int) toLong(Math.acos(ix));
    18986                                        oi32data[it.oIndex] = ox;
    18987                                }
    18988                        } else {
    18989                                while (it.hasNext()) {
    18990                                        final long ix = it.aLong;
    18991                                        int ox;
    18992                                        ox = (int) toLong(Math.acos(ix));
    18993                                        oi32data[it.oIndex] = ox;
    18994                                }
    18995                        }
    18996                        break;
    18997                case Dataset.ARRAYINT8:
    18998                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    18999                        if (is == 1) {
    19000                                if (it.isOutputDouble()) {
    19001                                        while (it.hasNext()) {
    19002                                                final double ix = it.aDouble;
    19003                                                byte ox;
    19004                                                ox = (byte) toLong(Math.acos(ix));
    19005                                                oai8data[it.oIndex] = ox;
    19006                                        }
    19007                                } else {
    19008                                        while (it.hasNext()) {
    19009                                                final long ix = it.aLong;
    19010                                                byte ox;
    19011                                                ox = (byte) toLong(Math.acos(ix));
    19012                                                oai8data[it.oIndex] = ox;
    19013                                        }
    19014                                }
    19015                        } else if (as == 1) {
    19016                                if (it.isOutputDouble()) {
    19017                                        while (it.hasNext()) {
    19018                                                final double ix = it.aDouble;
    19019                                                byte ox;
    19020                                                ox = (byte) toLong(Math.acos(ix));
    19021                                                for (int j = 0; j < is; j++) {
    19022                                                        oai8data[it.oIndex + j] = ox;
    19023                                                }
    19024                                        }
    19025                                } else {
    19026                                        while (it.hasNext()) {
    19027                                                final long ix = it.aLong;
    19028                                                byte ox;
    19029                                                ox = (byte) toLong(Math.acos(ix));
    19030                                                for (int j = 0; j < is; j++) {
    19031                                                        oai8data[it.oIndex + j] = ox;
    19032                                                }
    19033                                        }
    19034                                }
    19035                        } else {
    19036                                if (it.isOutputDouble()) {
    19037                                        while (it.hasNext()) {
    19038                                                for (int j = 0; j < is; j++) {
    19039                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19040                                                        byte ox;
    19041                                                        ox = (byte) toLong(Math.acos(ix));
    19042                                                        oai8data[it.oIndex + j] = ox;
    19043                                                }
    19044                                        }
    19045                                } else {
    19046                                        while (it.hasNext()) {
    19047                                                for (int j = 0; j < is; j++) {
    19048                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19049                                                        byte ox;
    19050                                                        ox = (byte) toLong(Math.acos(ix));
    19051                                                        oai8data[it.oIndex + j] = ox;
    19052                                                }
    19053                                        }
    19054                                }
    19055                        }
    19056                        break;
    19057                case Dataset.ARRAYINT16:
    19058                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    19059                        if (is == 1) {
    19060                                if (it.isOutputDouble()) {
    19061                                        while (it.hasNext()) {
    19062                                                final double ix = it.aDouble;
    19063                                                short ox;
    19064                                                ox = (short) toLong(Math.acos(ix));
    19065                                                oai16data[it.oIndex] = ox;
    19066                                        }
    19067                                } else {
    19068                                        while (it.hasNext()) {
    19069                                                final long ix = it.aLong;
    19070                                                short ox;
    19071                                                ox = (short) toLong(Math.acos(ix));
    19072                                                oai16data[it.oIndex] = ox;
    19073                                        }
    19074                                }
    19075                        } else if (as == 1) {
    19076                                if (it.isOutputDouble()) {
    19077                                        while (it.hasNext()) {
    19078                                                final double ix = it.aDouble;
    19079                                                short ox;
    19080                                                ox = (short) toLong(Math.acos(ix));
    19081                                                for (int j = 0; j < is; j++) {
    19082                                                        oai16data[it.oIndex + j] = ox;
    19083                                                }
    19084                                        }
    19085                                } else {
    19086                                        while (it.hasNext()) {
    19087                                                final long ix = it.aLong;
    19088                                                short ox;
    19089                                                ox = (short) toLong(Math.acos(ix));
    19090                                                for (int j = 0; j < is; j++) {
    19091                                                        oai16data[it.oIndex + j] = ox;
    19092                                                }
    19093                                        }
    19094                                }
    19095                        } else {
    19096                                if (it.isOutputDouble()) {
    19097                                        while (it.hasNext()) {
    19098                                                for (int j = 0; j < is; j++) {
    19099                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19100                                                        short ox;
    19101                                                        ox = (short) toLong(Math.acos(ix));
    19102                                                        oai16data[it.oIndex + j] = ox;
    19103                                                }
    19104                                        }
    19105                                } else {
    19106                                        while (it.hasNext()) {
    19107                                                for (int j = 0; j < is; j++) {
    19108                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19109                                                        short ox;
    19110                                                        ox = (short) toLong(Math.acos(ix));
    19111                                                        oai16data[it.oIndex + j] = ox;
    19112                                                }
    19113                                        }
    19114                                }
    19115                        }
    19116                        break;
    19117                case Dataset.ARRAYINT64:
    19118                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    19119                        if (is == 1) {
    19120                                if (it.isOutputDouble()) {
    19121                                        while (it.hasNext()) {
    19122                                                final double ix = it.aDouble;
    19123                                                long ox;
    19124                                                ox = toLong(Math.acos(ix));
    19125                                                oai64data[it.oIndex] = ox;
    19126                                        }
    19127                                } else {
    19128                                        while (it.hasNext()) {
    19129                                                final long ix = it.aLong;
    19130                                                long ox;
    19131                                                ox = toLong(Math.acos(ix));
    19132                                                oai64data[it.oIndex] = ox;
    19133                                        }
    19134                                }
    19135                        } else if (as == 1) {
    19136                                if (it.isOutputDouble()) {
    19137                                        while (it.hasNext()) {
    19138                                                final double ix = it.aDouble;
    19139                                                long ox;
    19140                                                ox = toLong(Math.acos(ix));
    19141                                                for (int j = 0; j < is; j++) {
    19142                                                        oai64data[it.oIndex + j] = ox;
    19143                                                }
    19144                                        }
    19145                                } else {
    19146                                        while (it.hasNext()) {
    19147                                                final long ix = it.aLong;
    19148                                                long ox;
    19149                                                ox = toLong(Math.acos(ix));
    19150                                                for (int j = 0; j < is; j++) {
    19151                                                        oai64data[it.oIndex + j] = ox;
    19152                                                }
    19153                                        }
    19154                                }
    19155                        } else {
    19156                                if (it.isOutputDouble()) {
    19157                                        while (it.hasNext()) {
    19158                                                for (int j = 0; j < is; j++) {
    19159                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19160                                                        long ox;
    19161                                                        ox = toLong(Math.acos(ix));
    19162                                                        oai64data[it.oIndex + j] = ox;
    19163                                                }
    19164                                        }
    19165                                } else {
    19166                                        while (it.hasNext()) {
    19167                                                for (int j = 0; j < is; j++) {
    19168                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19169                                                        long ox;
    19170                                                        ox = toLong(Math.acos(ix));
    19171                                                        oai64data[it.oIndex + j] = ox;
    19172                                                }
    19173                                        }
    19174                                }
    19175                        }
    19176                        break;
    19177                case Dataset.ARRAYINT32:
    19178                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    19179                        if (is == 1) {
    19180                                if (it.isOutputDouble()) {
    19181                                        while (it.hasNext()) {
    19182                                                final double ix = it.aDouble;
    19183                                                int ox;
    19184                                                ox = (int) toLong(Math.acos(ix));
    19185                                                oai32data[it.oIndex] = ox;
    19186                                        }
    19187                                } else {
    19188                                        while (it.hasNext()) {
    19189                                                final long ix = it.aLong;
    19190                                                int ox;
    19191                                                ox = (int) toLong(Math.acos(ix));
    19192                                                oai32data[it.oIndex] = ox;
    19193                                        }
    19194                                }
    19195                        } else if (as == 1) {
    19196                                if (it.isOutputDouble()) {
    19197                                        while (it.hasNext()) {
    19198                                                final double ix = it.aDouble;
    19199                                                int ox;
    19200                                                ox = (int) toLong(Math.acos(ix));
    19201                                                for (int j = 0; j < is; j++) {
    19202                                                        oai32data[it.oIndex + j] = ox;
    19203                                                }
    19204                                        }
    19205                                } else {
    19206                                        while (it.hasNext()) {
    19207                                                final long ix = it.aLong;
    19208                                                int ox;
    19209                                                ox = (int) toLong(Math.acos(ix));
    19210                                                for (int j = 0; j < is; j++) {
    19211                                                        oai32data[it.oIndex + j] = ox;
    19212                                                }
    19213                                        }
    19214                                }
    19215                        } else {
    19216                                if (it.isOutputDouble()) {
    19217                                        while (it.hasNext()) {
    19218                                                for (int j = 0; j < is; j++) {
    19219                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19220                                                        int ox;
    19221                                                        ox = (int) toLong(Math.acos(ix));
    19222                                                        oai32data[it.oIndex + j] = ox;
    19223                                                }
    19224                                        }
    19225                                } else {
    19226                                        while (it.hasNext()) {
    19227                                                for (int j = 0; j < is; j++) {
    19228                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19229                                                        int ox;
    19230                                                        ox = (int) toLong(Math.acos(ix));
    19231                                                        oai32data[it.oIndex + j] = ox;
    19232                                                }
    19233                                        }
    19234                                }
    19235                        }
    19236                        break;
    19237                case Dataset.FLOAT32:
    19238                        final float[] of32data = ((FloatDataset) result).getData();
    19239                        if (it.isOutputDouble()) {
    19240                                while (it.hasNext()) {
    19241                                        final double ix = it.aDouble;
    19242                                        float ox;
    19243                                        ox = (float) (Math.acos(ix));
    19244                                        of32data[it.oIndex] = ox;
    19245                                }
    19246                        } else {
    19247                                while (it.hasNext()) {
    19248                                        final long ix = it.aLong;
    19249                                        float ox;
    19250                                        ox = (float) (Math.acos(ix));
    19251                                        of32data[it.oIndex] = ox;
    19252                                }
    19253                        }
    19254                        break;
    19255                case Dataset.FLOAT64:
    19256                        final double[] of64data = ((DoubleDataset) result).getData();
    19257                        if (it.isOutputDouble()) {
    19258                                while (it.hasNext()) {
    19259                                        final double ix = it.aDouble;
    19260                                        double ox;
    19261                                        ox = (Math.acos(ix));
    19262                                        of64data[it.oIndex] = ox;
    19263                                }
    19264                        } else {
    19265                                while (it.hasNext()) {
    19266                                        final long ix = it.aLong;
    19267                                        double ox;
    19268                                        ox = (Math.acos(ix));
    19269                                        of64data[it.oIndex] = ox;
    19270                                }
    19271                        }
    19272                        break;
    19273                case Dataset.ARRAYFLOAT32:
    19274                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    19275                        if (is == 1) {
    19276                                if (it.isOutputDouble()) {
    19277                                        while (it.hasNext()) {
    19278                                                final double ix = it.aDouble;
    19279                                                float ox;
    19280                                                ox = (float) (Math.acos(ix));
    19281                                                oaf32data[it.oIndex] = ox;
    19282                                        }
    19283                                } else {
    19284                                        while (it.hasNext()) {
    19285                                                final long ix = it.aLong;
    19286                                                float ox;
    19287                                                ox = (float) (Math.acos(ix));
    19288                                                oaf32data[it.oIndex] = ox;
    19289                                        }
    19290                                }
    19291                        } else if (as == 1) {
    19292                                if (it.isOutputDouble()) {
    19293                                        while (it.hasNext()) {
    19294                                                final double ix = it.aDouble;
    19295                                                float ox;
    19296                                                ox = (float) (Math.acos(ix));
    19297                                                for (int j = 0; j < is; j++) {
    19298                                                        oaf32data[it.oIndex + j] = ox;
    19299                                                }
    19300                                        }
    19301                                } else {
    19302                                        while (it.hasNext()) {
    19303                                                final long ix = it.aLong;
    19304                                                float ox;
    19305                                                ox = (float) (Math.acos(ix));
    19306                                                for (int j = 0; j < is; j++) {
    19307                                                        oaf32data[it.oIndex + j] = ox;
    19308                                                }
    19309                                        }
    19310                                }
    19311                        } else {
    19312                                if (it.isOutputDouble()) {
    19313                                        while (it.hasNext()) {
    19314                                                for (int j = 0; j < is; j++) {
    19315                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19316                                                        float ox;
    19317                                                        ox = (float) (Math.acos(ix));
    19318                                                        oaf32data[it.oIndex + j] = ox;
    19319                                                }
    19320                                        }
    19321                                } else {
    19322                                        while (it.hasNext()) {
    19323                                                for (int j = 0; j < is; j++) {
    19324                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19325                                                        float ox;
    19326                                                        ox = (float) (Math.acos(ix));
    19327                                                        oaf32data[it.oIndex + j] = ox;
    19328                                                }
    19329                                        }
    19330                                }
    19331                        }
    19332                        break;
    19333                case Dataset.ARRAYFLOAT64:
    19334                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    19335                        if (is == 1) {
    19336                                if (it.isOutputDouble()) {
    19337                                        while (it.hasNext()) {
    19338                                                final double ix = it.aDouble;
    19339                                                double ox;
    19340                                                ox = (Math.acos(ix));
    19341                                                oaf64data[it.oIndex] = ox;
    19342                                        }
    19343                                } else {
    19344                                        while (it.hasNext()) {
    19345                                                final long ix = it.aLong;
    19346                                                double ox;
    19347                                                ox = (Math.acos(ix));
    19348                                                oaf64data[it.oIndex] = ox;
    19349                                        }
    19350                                }
    19351                        } else if (as == 1) {
    19352                                if (it.isOutputDouble()) {
    19353                                        while (it.hasNext()) {
    19354                                                final double ix = it.aDouble;
    19355                                                double ox;
    19356                                                ox = (Math.acos(ix));
    19357                                                for (int j = 0; j < is; j++) {
    19358                                                        oaf64data[it.oIndex + j] = ox;
    19359                                                }
    19360                                        }
    19361                                } else {
    19362                                        while (it.hasNext()) {
    19363                                                final long ix = it.aLong;
    19364                                                double ox;
    19365                                                ox = (Math.acos(ix));
    19366                                                for (int j = 0; j < is; j++) {
    19367                                                        oaf64data[it.oIndex + j] = ox;
    19368                                                }
    19369                                        }
    19370                                }
    19371                        } else {
    19372                                if (it.isOutputDouble()) {
    19373                                        while (it.hasNext()) {
    19374                                                for (int j = 0; j < is; j++) {
    19375                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19376                                                        double ox;
    19377                                                        ox = (Math.acos(ix));
    19378                                                        oaf64data[it.oIndex + j] = ox;
    19379                                                }
    19380                                        }
    19381                                } else {
    19382                                        while (it.hasNext()) {
    19383                                                for (int j = 0; j < is; j++) {
    19384                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19385                                                        double ox;
    19386                                                        ox = (Math.acos(ix));
    19387                                                        oaf64data[it.oIndex + j] = ox;
    19388                                                }
    19389                                        }
    19390                                }
    19391                        }
    19392                        break;
    19393                case Dataset.COMPLEX64:
    19394                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    19395                        if (as == 1) {
    19396                                final double iy = 0;
    19397                                while (it.hasNext()) {
    19398                                        final double ix = it.aDouble;
    19399                                        Complex tz;
    19400                                        float ox;
    19401                                        float oy;
    19402                                        tz = new Complex(ix, iy).acos();
    19403                                        ox = (float) (tz.getReal());
    19404                                        oy = (float) (tz.getImaginary());
    19405                                        oc64data[it.oIndex] = ox;
    19406                                        oc64data[it.oIndex + 1] = oy;
    19407                                }
    19408                        } else {
    19409                                while (it.hasNext()) {
    19410                                        final double ix = it.aDouble;
    19411                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    19412                                        Complex tz;
    19413                                        float ox;
    19414                                        float oy;
    19415                                        tz = new Complex(ix, iy).acos();
    19416                                        ox = (float) (tz.getReal());
    19417                                        oy = (float) (tz.getImaginary());
    19418                                        oc64data[it.oIndex] = ox;
    19419                                        oc64data[it.oIndex + 1] = oy;
    19420                                }
    19421                        }
    19422                        break;
    19423                case Dataset.COMPLEX128:
    19424                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    19425                        if (as == 1) {
    19426                                final double iy = 0;
    19427                                while (it.hasNext()) {
    19428                                        final double ix = it.aDouble;
    19429                                        Complex tz;
    19430                                        double ox;
    19431                                        double oy;
    19432                                        tz = new Complex(ix, iy).acos();
    19433                                        ox = (tz.getReal());
    19434                                        oy = (tz.getImaginary());
    19435                                        oc128data[it.oIndex] = ox;
    19436                                        oc128data[it.oIndex + 1] = oy;
    19437                                }
    19438                        } else {
    19439                                while (it.hasNext()) {
    19440                                        final double ix = it.aDouble;
    19441                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    19442                                        Complex tz;
    19443                                        double ox;
    19444                                        double oy;
    19445                                        tz = new Complex(ix, iy).acos();
    19446                                        ox = (tz.getReal());
    19447                                        oy = (tz.getImaginary());
    19448                                        oc128data[it.oIndex] = ox;
    19449                                        oc128data[it.oIndex + 1] = oy;
    19450                                }
    19451                        }
    19452                        break;
    19453                default:
    19454                        throw new IllegalArgumentException("arccos supports integer, compound integer, real, compound real, complex datasets only");
    19455                }
    19456
    19457                addFunctionName(result, "arccos");
    19458                return result;
    19459        }
    19460
    19461        /**
    19462         * arctan - evaluate the inverse tangent function on each element of the dataset
    19463         * @param a
    19464         * @return dataset
    19465         */
    19466        public static Dataset arctan(final Object a) {
    19467                return arctan(a, null);
    19468        }
    19469
    19470        /**
    19471         * arctan - evaluate the inverse tangent function on each element of the dataset
    19472         * @param a
    19473         * @param o output can be null - in which case, a new dataset is created
    19474         * @return dataset
    19475         */
    19476        public static Dataset arctan(final Object a, final Dataset o) {
    19477                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    19478                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    19479                final Dataset result = it.getOutput();
    19480                final int is = result.getElementsPerItem();
    19481                final int as = da.getElementsPerItem();
    19482                final int dt = result.getDType();
    19483
    19484                switch(dt) {
    19485                case Dataset.INT8:
    19486                        final byte[] oi8data = ((ByteDataset) result).getData();
    19487                        if (it.isOutputDouble()) {
    19488                                while (it.hasNext()) {
    19489                                        final double ix = it.aDouble;
    19490                                        byte ox;
    19491                                        ox = (byte) toLong(Math.atan(ix));
    19492                                        oi8data[it.oIndex] = ox;
    19493                                }
    19494                        } else {
    19495                                while (it.hasNext()) {
    19496                                        final long ix = it.aLong;
    19497                                        byte ox;
    19498                                        ox = (byte) toLong(Math.atan(ix));
    19499                                        oi8data[it.oIndex] = ox;
    19500                                }
    19501                        }
    19502                        break;
    19503                case Dataset.INT16:
    19504                        final short[] oi16data = ((ShortDataset) result).getData();
    19505                        if (it.isOutputDouble()) {
    19506                                while (it.hasNext()) {
    19507                                        final double ix = it.aDouble;
    19508                                        short ox;
    19509                                        ox = (short) toLong(Math.atan(ix));
    19510                                        oi16data[it.oIndex] = ox;
    19511                                }
    19512                        } else {
    19513                                while (it.hasNext()) {
    19514                                        final long ix = it.aLong;
    19515                                        short ox;
    19516                                        ox = (short) toLong(Math.atan(ix));
    19517                                        oi16data[it.oIndex] = ox;
    19518                                }
    19519                        }
    19520                        break;
    19521                case Dataset.INT64:
    19522                        final long[] oi64data = ((LongDataset) result).getData();
    19523                        if (it.isOutputDouble()) {
    19524                                while (it.hasNext()) {
    19525                                        final double ix = it.aDouble;
    19526                                        long ox;
    19527                                        ox = toLong(Math.atan(ix));
    19528                                        oi64data[it.oIndex] = ox;
    19529                                }
    19530                        } else {
    19531                                while (it.hasNext()) {
    19532                                        final long ix = it.aLong;
    19533                                        long ox;
    19534                                        ox = toLong(Math.atan(ix));
    19535                                        oi64data[it.oIndex] = ox;
    19536                                }
    19537                        }
    19538                        break;
    19539                case Dataset.INT32:
    19540                        final int[] oi32data = ((IntegerDataset) result).getData();
    19541                        if (it.isOutputDouble()) {
    19542                                while (it.hasNext()) {
    19543                                        final double ix = it.aDouble;
    19544                                        int ox;
    19545                                        ox = (int) toLong(Math.atan(ix));
    19546                                        oi32data[it.oIndex] = ox;
    19547                                }
    19548                        } else {
    19549                                while (it.hasNext()) {
    19550                                        final long ix = it.aLong;
    19551                                        int ox;
    19552                                        ox = (int) toLong(Math.atan(ix));
    19553                                        oi32data[it.oIndex] = ox;
    19554                                }
    19555                        }
    19556                        break;
    19557                case Dataset.ARRAYINT8:
    19558                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    19559                        if (is == 1) {
    19560                                if (it.isOutputDouble()) {
    19561                                        while (it.hasNext()) {
    19562                                                final double ix = it.aDouble;
    19563                                                byte ox;
    19564                                                ox = (byte) toLong(Math.atan(ix));
    19565                                                oai8data[it.oIndex] = ox;
    19566                                        }
    19567                                } else {
    19568                                        while (it.hasNext()) {
    19569                                                final long ix = it.aLong;
    19570                                                byte ox;
    19571                                                ox = (byte) toLong(Math.atan(ix));
    19572                                                oai8data[it.oIndex] = ox;
    19573                                        }
    19574                                }
    19575                        } else if (as == 1) {
    19576                                if (it.isOutputDouble()) {
    19577                                        while (it.hasNext()) {
    19578                                                final double ix = it.aDouble;
    19579                                                byte ox;
    19580                                                ox = (byte) toLong(Math.atan(ix));
    19581                                                for (int j = 0; j < is; j++) {
    19582                                                        oai8data[it.oIndex + j] = ox;
    19583                                                }
    19584                                        }
    19585                                } else {
    19586                                        while (it.hasNext()) {
    19587                                                final long ix = it.aLong;
    19588                                                byte ox;
    19589                                                ox = (byte) toLong(Math.atan(ix));
    19590                                                for (int j = 0; j < is; j++) {
    19591                                                        oai8data[it.oIndex + j] = ox;
    19592                                                }
    19593                                        }
    19594                                }
    19595                        } else {
    19596                                if (it.isOutputDouble()) {
    19597                                        while (it.hasNext()) {
    19598                                                for (int j = 0; j < is; j++) {
    19599                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19600                                                        byte ox;
    19601                                                        ox = (byte) toLong(Math.atan(ix));
    19602                                                        oai8data[it.oIndex + j] = ox;
    19603                                                }
    19604                                        }
    19605                                } else {
    19606                                        while (it.hasNext()) {
    19607                                                for (int j = 0; j < is; j++) {
    19608                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19609                                                        byte ox;
    19610                                                        ox = (byte) toLong(Math.atan(ix));
    19611                                                        oai8data[it.oIndex + j] = ox;
    19612                                                }
    19613                                        }
    19614                                }
    19615                        }
    19616                        break;
    19617                case Dataset.ARRAYINT16:
    19618                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    19619                        if (is == 1) {
    19620                                if (it.isOutputDouble()) {
    19621                                        while (it.hasNext()) {
    19622                                                final double ix = it.aDouble;
    19623                                                short ox;
    19624                                                ox = (short) toLong(Math.atan(ix));
    19625                                                oai16data[it.oIndex] = ox;
    19626                                        }
    19627                                } else {
    19628                                        while (it.hasNext()) {
    19629                                                final long ix = it.aLong;
    19630                                                short ox;
    19631                                                ox = (short) toLong(Math.atan(ix));
    19632                                                oai16data[it.oIndex] = ox;
    19633                                        }
    19634                                }
    19635                        } else if (as == 1) {
    19636                                if (it.isOutputDouble()) {
    19637                                        while (it.hasNext()) {
    19638                                                final double ix = it.aDouble;
    19639                                                short ox;
    19640                                                ox = (short) toLong(Math.atan(ix));
    19641                                                for (int j = 0; j < is; j++) {
    19642                                                        oai16data[it.oIndex + j] = ox;
    19643                                                }
    19644                                        }
    19645                                } else {
    19646                                        while (it.hasNext()) {
    19647                                                final long ix = it.aLong;
    19648                                                short ox;
    19649                                                ox = (short) toLong(Math.atan(ix));
    19650                                                for (int j = 0; j < is; j++) {
    19651                                                        oai16data[it.oIndex + j] = ox;
    19652                                                }
    19653                                        }
    19654                                }
    19655                        } else {
    19656                                if (it.isOutputDouble()) {
    19657                                        while (it.hasNext()) {
    19658                                                for (int j = 0; j < is; j++) {
    19659                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19660                                                        short ox;
    19661                                                        ox = (short) toLong(Math.atan(ix));
    19662                                                        oai16data[it.oIndex + j] = ox;
    19663                                                }
    19664                                        }
    19665                                } else {
    19666                                        while (it.hasNext()) {
    19667                                                for (int j = 0; j < is; j++) {
    19668                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19669                                                        short ox;
    19670                                                        ox = (short) toLong(Math.atan(ix));
    19671                                                        oai16data[it.oIndex + j] = ox;
    19672                                                }
    19673                                        }
    19674                                }
    19675                        }
    19676                        break;
    19677                case Dataset.ARRAYINT64:
    19678                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    19679                        if (is == 1) {
    19680                                if (it.isOutputDouble()) {
    19681                                        while (it.hasNext()) {
    19682                                                final double ix = it.aDouble;
    19683                                                long ox;
    19684                                                ox = toLong(Math.atan(ix));
    19685                                                oai64data[it.oIndex] = ox;
    19686                                        }
    19687                                } else {
    19688                                        while (it.hasNext()) {
    19689                                                final long ix = it.aLong;
    19690                                                long ox;
    19691                                                ox = toLong(Math.atan(ix));
    19692                                                oai64data[it.oIndex] = ox;
    19693                                        }
    19694                                }
    19695                        } else if (as == 1) {
    19696                                if (it.isOutputDouble()) {
    19697                                        while (it.hasNext()) {
    19698                                                final double ix = it.aDouble;
    19699                                                long ox;
    19700                                                ox = toLong(Math.atan(ix));
    19701                                                for (int j = 0; j < is; j++) {
    19702                                                        oai64data[it.oIndex + j] = ox;
    19703                                                }
    19704                                        }
    19705                                } else {
    19706                                        while (it.hasNext()) {
    19707                                                final long ix = it.aLong;
    19708                                                long ox;
    19709                                                ox = toLong(Math.atan(ix));
    19710                                                for (int j = 0; j < is; j++) {
    19711                                                        oai64data[it.oIndex + j] = ox;
    19712                                                }
    19713                                        }
    19714                                }
    19715                        } else {
    19716                                if (it.isOutputDouble()) {
    19717                                        while (it.hasNext()) {
    19718                                                for (int j = 0; j < is; j++) {
    19719                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19720                                                        long ox;
    19721                                                        ox = toLong(Math.atan(ix));
    19722                                                        oai64data[it.oIndex + j] = ox;
    19723                                                }
    19724                                        }
    19725                                } else {
    19726                                        while (it.hasNext()) {
    19727                                                for (int j = 0; j < is; j++) {
    19728                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19729                                                        long ox;
    19730                                                        ox = toLong(Math.atan(ix));
    19731                                                        oai64data[it.oIndex + j] = ox;
    19732                                                }
    19733                                        }
    19734                                }
    19735                        }
    19736                        break;
    19737                case Dataset.ARRAYINT32:
    19738                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    19739                        if (is == 1) {
    19740                                if (it.isOutputDouble()) {
    19741                                        while (it.hasNext()) {
    19742                                                final double ix = it.aDouble;
    19743                                                int ox;
    19744                                                ox = (int) toLong(Math.atan(ix));
    19745                                                oai32data[it.oIndex] = ox;
    19746                                        }
    19747                                } else {
    19748                                        while (it.hasNext()) {
    19749                                                final long ix = it.aLong;
    19750                                                int ox;
    19751                                                ox = (int) toLong(Math.atan(ix));
    19752                                                oai32data[it.oIndex] = ox;
    19753                                        }
    19754                                }
    19755                        } else if (as == 1) {
    19756                                if (it.isOutputDouble()) {
    19757                                        while (it.hasNext()) {
    19758                                                final double ix = it.aDouble;
    19759                                                int ox;
    19760                                                ox = (int) toLong(Math.atan(ix));
    19761                                                for (int j = 0; j < is; j++) {
    19762                                                        oai32data[it.oIndex + j] = ox;
    19763                                                }
    19764                                        }
    19765                                } else {
    19766                                        while (it.hasNext()) {
    19767                                                final long ix = it.aLong;
    19768                                                int ox;
    19769                                                ox = (int) toLong(Math.atan(ix));
    19770                                                for (int j = 0; j < is; j++) {
    19771                                                        oai32data[it.oIndex + j] = ox;
    19772                                                }
    19773                                        }
    19774                                }
    19775                        } else {
    19776                                if (it.isOutputDouble()) {
    19777                                        while (it.hasNext()) {
    19778                                                for (int j = 0; j < is; j++) {
    19779                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19780                                                        int ox;
    19781                                                        ox = (int) toLong(Math.atan(ix));
    19782                                                        oai32data[it.oIndex + j] = ox;
    19783                                                }
    19784                                        }
    19785                                } else {
    19786                                        while (it.hasNext()) {
    19787                                                for (int j = 0; j < is; j++) {
    19788                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19789                                                        int ox;
    19790                                                        ox = (int) toLong(Math.atan(ix));
    19791                                                        oai32data[it.oIndex + j] = ox;
    19792                                                }
    19793                                        }
    19794                                }
    19795                        }
    19796                        break;
    19797                case Dataset.FLOAT32:
    19798                        final float[] of32data = ((FloatDataset) result).getData();
    19799                        if (it.isOutputDouble()) {
    19800                                while (it.hasNext()) {
    19801                                        final double ix = it.aDouble;
    19802                                        float ox;
    19803                                        ox = (float) (Math.atan(ix));
    19804                                        of32data[it.oIndex] = ox;
    19805                                }
    19806                        } else {
    19807                                while (it.hasNext()) {
    19808                                        final long ix = it.aLong;
    19809                                        float ox;
    19810                                        ox = (float) (Math.atan(ix));
    19811                                        of32data[it.oIndex] = ox;
    19812                                }
    19813                        }
    19814                        break;
    19815                case Dataset.FLOAT64:
    19816                        final double[] of64data = ((DoubleDataset) result).getData();
    19817                        if (it.isOutputDouble()) {
    19818                                while (it.hasNext()) {
    19819                                        final double ix = it.aDouble;
    19820                                        double ox;
    19821                                        ox = (Math.atan(ix));
    19822                                        of64data[it.oIndex] = ox;
    19823                                }
    19824                        } else {
    19825                                while (it.hasNext()) {
    19826                                        final long ix = it.aLong;
    19827                                        double ox;
    19828                                        ox = (Math.atan(ix));
    19829                                        of64data[it.oIndex] = ox;
    19830                                }
    19831                        }
    19832                        break;
    19833                case Dataset.ARRAYFLOAT32:
    19834                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    19835                        if (is == 1) {
    19836                                if (it.isOutputDouble()) {
    19837                                        while (it.hasNext()) {
    19838                                                final double ix = it.aDouble;
    19839                                                float ox;
    19840                                                ox = (float) (Math.atan(ix));
    19841                                                oaf32data[it.oIndex] = ox;
    19842                                        }
    19843                                } else {
    19844                                        while (it.hasNext()) {
    19845                                                final long ix = it.aLong;
    19846                                                float ox;
    19847                                                ox = (float) (Math.atan(ix));
    19848                                                oaf32data[it.oIndex] = ox;
    19849                                        }
    19850                                }
    19851                        } else if (as == 1) {
    19852                                if (it.isOutputDouble()) {
    19853                                        while (it.hasNext()) {
    19854                                                final double ix = it.aDouble;
    19855                                                float ox;
    19856                                                ox = (float) (Math.atan(ix));
    19857                                                for (int j = 0; j < is; j++) {
    19858                                                        oaf32data[it.oIndex + j] = ox;
    19859                                                }
    19860                                        }
    19861                                } else {
    19862                                        while (it.hasNext()) {
    19863                                                final long ix = it.aLong;
    19864                                                float ox;
    19865                                                ox = (float) (Math.atan(ix));
    19866                                                for (int j = 0; j < is; j++) {
    19867                                                        oaf32data[it.oIndex + j] = ox;
    19868                                                }
    19869                                        }
    19870                                }
    19871                        } else {
    19872                                if (it.isOutputDouble()) {
    19873                                        while (it.hasNext()) {
    19874                                                for (int j = 0; j < is; j++) {
    19875                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19876                                                        float ox;
    19877                                                        ox = (float) (Math.atan(ix));
    19878                                                        oaf32data[it.oIndex + j] = ox;
    19879                                                }
    19880                                        }
    19881                                } else {
    19882                                        while (it.hasNext()) {
    19883                                                for (int j = 0; j < is; j++) {
    19884                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19885                                                        float ox;
    19886                                                        ox = (float) (Math.atan(ix));
    19887                                                        oaf32data[it.oIndex + j] = ox;
    19888                                                }
    19889                                        }
    19890                                }
    19891                        }
    19892                        break;
    19893                case Dataset.ARRAYFLOAT64:
    19894                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    19895                        if (is == 1) {
    19896                                if (it.isOutputDouble()) {
    19897                                        while (it.hasNext()) {
    19898                                                final double ix = it.aDouble;
    19899                                                double ox;
    19900                                                ox = (Math.atan(ix));
    19901                                                oaf64data[it.oIndex] = ox;
    19902                                        }
    19903                                } else {
    19904                                        while (it.hasNext()) {
    19905                                                final long ix = it.aLong;
    19906                                                double ox;
    19907                                                ox = (Math.atan(ix));
    19908                                                oaf64data[it.oIndex] = ox;
    19909                                        }
    19910                                }
    19911                        } else if (as == 1) {
    19912                                if (it.isOutputDouble()) {
    19913                                        while (it.hasNext()) {
    19914                                                final double ix = it.aDouble;
    19915                                                double ox;
    19916                                                ox = (Math.atan(ix));
    19917                                                for (int j = 0; j < is; j++) {
    19918                                                        oaf64data[it.oIndex + j] = ox;
    19919                                                }
    19920                                        }
    19921                                } else {
    19922                                        while (it.hasNext()) {
    19923                                                final long ix = it.aLong;
    19924                                                double ox;
    19925                                                ox = (Math.atan(ix));
    19926                                                for (int j = 0; j < is; j++) {
    19927                                                        oaf64data[it.oIndex + j] = ox;
    19928                                                }
    19929                                        }
    19930                                }
    19931                        } else {
    19932                                if (it.isOutputDouble()) {
    19933                                        while (it.hasNext()) {
    19934                                                for (int j = 0; j < is; j++) {
    19935                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    19936                                                        double ox;
    19937                                                        ox = (Math.atan(ix));
    19938                                                        oaf64data[it.oIndex + j] = ox;
    19939                                                }
    19940                                        }
    19941                                } else {
    19942                                        while (it.hasNext()) {
    19943                                                for (int j = 0; j < is; j++) {
    19944                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    19945                                                        double ox;
    19946                                                        ox = (Math.atan(ix));
    19947                                                        oaf64data[it.oIndex + j] = ox;
    19948                                                }
    19949                                        }
    19950                                }
    19951                        }
    19952                        break;
    19953                case Dataset.COMPLEX64:
    19954                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    19955                        if (as == 1) {
    19956                                final double iy = 0;
    19957                                while (it.hasNext()) {
    19958                                        final double ix = it.aDouble;
    19959                                        Complex tz;
    19960                                        float ox;
    19961                                        float oy;
    19962                                        tz = new Complex(ix, iy).atan();
    19963                                        ox = (float) (tz.getReal());
    19964                                        oy = (float) (tz.getImaginary());
    19965                                        oc64data[it.oIndex] = ox;
    19966                                        oc64data[it.oIndex + 1] = oy;
    19967                                }
    19968                        } else {
    19969                                while (it.hasNext()) {
    19970                                        final double ix = it.aDouble;
    19971                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    19972                                        Complex tz;
    19973                                        float ox;
    19974                                        float oy;
    19975                                        tz = new Complex(ix, iy).atan();
    19976                                        ox = (float) (tz.getReal());
    19977                                        oy = (float) (tz.getImaginary());
    19978                                        oc64data[it.oIndex] = ox;
    19979                                        oc64data[it.oIndex + 1] = oy;
    19980                                }
    19981                        }
    19982                        break;
    19983                case Dataset.COMPLEX128:
    19984                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    19985                        if (as == 1) {
    19986                                final double iy = 0;
    19987                                while (it.hasNext()) {
    19988                                        final double ix = it.aDouble;
    19989                                        Complex tz;
    19990                                        double ox;
    19991                                        double oy;
    19992                                        tz = new Complex(ix, iy).atan();
    19993                                        ox = (tz.getReal());
    19994                                        oy = (tz.getImaginary());
    19995                                        oc128data[it.oIndex] = ox;
    19996                                        oc128data[it.oIndex + 1] = oy;
    19997                                }
    19998                        } else {
    19999                                while (it.hasNext()) {
    20000                                        final double ix = it.aDouble;
    20001                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    20002                                        Complex tz;
    20003                                        double ox;
    20004                                        double oy;
    20005                                        tz = new Complex(ix, iy).atan();
    20006                                        ox = (tz.getReal());
    20007                                        oy = (tz.getImaginary());
    20008                                        oc128data[it.oIndex] = ox;
    20009                                        oc128data[it.oIndex + 1] = oy;
    20010                                }
    20011                        }
    20012                        break;
    20013                default:
    20014                        throw new IllegalArgumentException("arctan supports integer, compound integer, real, compound real, complex datasets only");
    20015                }
    20016
    20017                addFunctionName(result, "arctan");
    20018                return result;
    20019        }
    20020
    20021        /**
    20022         * sinh - evaluate the hyperbolic sine function on each element of the dataset
    20023         * @param a
    20024         * @return dataset
    20025         */
    20026        public static Dataset sinh(final Object a) {
    20027                return sinh(a, null);
    20028        }
    20029
    20030        /**
    20031         * sinh - evaluate the hyperbolic sine function on each element of the dataset
    20032         * @param a
    20033         * @param o output can be null - in which case, a new dataset is created
    20034         * @return dataset
    20035         */
    20036        public static Dataset sinh(final Object a, final Dataset o) {
    20037                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    20038                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    20039                final Dataset result = it.getOutput();
    20040                final int is = result.getElementsPerItem();
    20041                final int as = da.getElementsPerItem();
    20042                final int dt = result.getDType();
    20043
    20044                switch(dt) {
    20045                case Dataset.INT8:
    20046                        final byte[] oi8data = ((ByteDataset) result).getData();
    20047                        if (it.isOutputDouble()) {
    20048                                while (it.hasNext()) {
    20049                                        final double ix = it.aDouble;
    20050                                        byte ox;
    20051                                        ox = (byte) toLong(Math.sinh(ix));
    20052                                        oi8data[it.oIndex] = ox;
    20053                                }
    20054                        } else {
    20055                                while (it.hasNext()) {
    20056                                        final long ix = it.aLong;
    20057                                        byte ox;
    20058                                        ox = (byte) toLong(Math.sinh(ix));
    20059                                        oi8data[it.oIndex] = ox;
    20060                                }
    20061                        }
    20062                        break;
    20063                case Dataset.INT16:
    20064                        final short[] oi16data = ((ShortDataset) result).getData();
    20065                        if (it.isOutputDouble()) {
    20066                                while (it.hasNext()) {
    20067                                        final double ix = it.aDouble;
    20068                                        short ox;
    20069                                        ox = (short) toLong(Math.sinh(ix));
    20070                                        oi16data[it.oIndex] = ox;
    20071                                }
    20072                        } else {
    20073                                while (it.hasNext()) {
    20074                                        final long ix = it.aLong;
    20075                                        short ox;
    20076                                        ox = (short) toLong(Math.sinh(ix));
    20077                                        oi16data[it.oIndex] = ox;
    20078                                }
    20079                        }
    20080                        break;
    20081                case Dataset.INT64:
    20082                        final long[] oi64data = ((LongDataset) result).getData();
    20083                        if (it.isOutputDouble()) {
    20084                                while (it.hasNext()) {
    20085                                        final double ix = it.aDouble;
    20086                                        long ox;
    20087                                        ox = toLong(Math.sinh(ix));
    20088                                        oi64data[it.oIndex] = ox;
    20089                                }
    20090                        } else {
    20091                                while (it.hasNext()) {
    20092                                        final long ix = it.aLong;
    20093                                        long ox;
    20094                                        ox = toLong(Math.sinh(ix));
    20095                                        oi64data[it.oIndex] = ox;
    20096                                }
    20097                        }
    20098                        break;
    20099                case Dataset.INT32:
    20100                        final int[] oi32data = ((IntegerDataset) result).getData();
    20101                        if (it.isOutputDouble()) {
    20102                                while (it.hasNext()) {
    20103                                        final double ix = it.aDouble;
    20104                                        int ox;
    20105                                        ox = (int) toLong(Math.sinh(ix));
    20106                                        oi32data[it.oIndex] = ox;
    20107                                }
    20108                        } else {
    20109                                while (it.hasNext()) {
    20110                                        final long ix = it.aLong;
    20111                                        int ox;
    20112                                        ox = (int) toLong(Math.sinh(ix));
    20113                                        oi32data[it.oIndex] = ox;
    20114                                }
    20115                        }
    20116                        break;
    20117                case Dataset.ARRAYINT8:
    20118                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    20119                        if (is == 1) {
    20120                                if (it.isOutputDouble()) {
    20121                                        while (it.hasNext()) {
    20122                                                final double ix = it.aDouble;
    20123                                                byte ox;
    20124                                                ox = (byte) toLong(Math.sinh(ix));
    20125                                                oai8data[it.oIndex] = ox;
    20126                                        }
    20127                                } else {
    20128                                        while (it.hasNext()) {
    20129                                                final long ix = it.aLong;
    20130                                                byte ox;
    20131                                                ox = (byte) toLong(Math.sinh(ix));
    20132                                                oai8data[it.oIndex] = ox;
    20133                                        }
    20134                                }
    20135                        } else if (as == 1) {
    20136                                if (it.isOutputDouble()) {
    20137                                        while (it.hasNext()) {
    20138                                                final double ix = it.aDouble;
    20139                                                byte ox;
    20140                                                ox = (byte) toLong(Math.sinh(ix));
    20141                                                for (int j = 0; j < is; j++) {
    20142                                                        oai8data[it.oIndex + j] = ox;
    20143                                                }
    20144                                        }
    20145                                } else {
    20146                                        while (it.hasNext()) {
    20147                                                final long ix = it.aLong;
    20148                                                byte ox;
    20149                                                ox = (byte) toLong(Math.sinh(ix));
    20150                                                for (int j = 0; j < is; j++) {
    20151                                                        oai8data[it.oIndex + j] = ox;
    20152                                                }
    20153                                        }
    20154                                }
    20155                        } else {
    20156                                if (it.isOutputDouble()) {
    20157                                        while (it.hasNext()) {
    20158                                                for (int j = 0; j < is; j++) {
    20159                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20160                                                        byte ox;
    20161                                                        ox = (byte) toLong(Math.sinh(ix));
    20162                                                        oai8data[it.oIndex + j] = ox;
    20163                                                }
    20164                                        }
    20165                                } else {
    20166                                        while (it.hasNext()) {
    20167                                                for (int j = 0; j < is; j++) {
    20168                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20169                                                        byte ox;
    20170                                                        ox = (byte) toLong(Math.sinh(ix));
    20171                                                        oai8data[it.oIndex + j] = ox;
    20172                                                }
    20173                                        }
    20174                                }
    20175                        }
    20176                        break;
    20177                case Dataset.ARRAYINT16:
    20178                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    20179                        if (is == 1) {
    20180                                if (it.isOutputDouble()) {
    20181                                        while (it.hasNext()) {
    20182                                                final double ix = it.aDouble;
    20183                                                short ox;
    20184                                                ox = (short) toLong(Math.sinh(ix));
    20185                                                oai16data[it.oIndex] = ox;
    20186                                        }
    20187                                } else {
    20188                                        while (it.hasNext()) {
    20189                                                final long ix = it.aLong;
    20190                                                short ox;
    20191                                                ox = (short) toLong(Math.sinh(ix));
    20192                                                oai16data[it.oIndex] = ox;
    20193                                        }
    20194                                }
    20195                        } else if (as == 1) {
    20196                                if (it.isOutputDouble()) {
    20197                                        while (it.hasNext()) {
    20198                                                final double ix = it.aDouble;
    20199                                                short ox;
    20200                                                ox = (short) toLong(Math.sinh(ix));
    20201                                                for (int j = 0; j < is; j++) {
    20202                                                        oai16data[it.oIndex + j] = ox;
    20203                                                }
    20204                                        }
    20205                                } else {
    20206                                        while (it.hasNext()) {
    20207                                                final long ix = it.aLong;
    20208                                                short ox;
    20209                                                ox = (short) toLong(Math.sinh(ix));
    20210                                                for (int j = 0; j < is; j++) {
    20211                                                        oai16data[it.oIndex + j] = ox;
    20212                                                }
    20213                                        }
    20214                                }
    20215                        } else {
    20216                                if (it.isOutputDouble()) {
    20217                                        while (it.hasNext()) {
    20218                                                for (int j = 0; j < is; j++) {
    20219                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20220                                                        short ox;
    20221                                                        ox = (short) toLong(Math.sinh(ix));
    20222                                                        oai16data[it.oIndex + j] = ox;
    20223                                                }
    20224                                        }
    20225                                } else {
    20226                                        while (it.hasNext()) {
    20227                                                for (int j = 0; j < is; j++) {
    20228                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20229                                                        short ox;
    20230                                                        ox = (short) toLong(Math.sinh(ix));
    20231                                                        oai16data[it.oIndex + j] = ox;
    20232                                                }
    20233                                        }
    20234                                }
    20235                        }
    20236                        break;
    20237                case Dataset.ARRAYINT64:
    20238                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    20239                        if (is == 1) {
    20240                                if (it.isOutputDouble()) {
    20241                                        while (it.hasNext()) {
    20242                                                final double ix = it.aDouble;
    20243                                                long ox;
    20244                                                ox = toLong(Math.sinh(ix));
    20245                                                oai64data[it.oIndex] = ox;
    20246                                        }
    20247                                } else {
    20248                                        while (it.hasNext()) {
    20249                                                final long ix = it.aLong;
    20250                                                long ox;
    20251                                                ox = toLong(Math.sinh(ix));
    20252                                                oai64data[it.oIndex] = ox;
    20253                                        }
    20254                                }
    20255                        } else if (as == 1) {
    20256                                if (it.isOutputDouble()) {
    20257                                        while (it.hasNext()) {
    20258                                                final double ix = it.aDouble;
    20259                                                long ox;
    20260                                                ox = toLong(Math.sinh(ix));
    20261                                                for (int j = 0; j < is; j++) {
    20262                                                        oai64data[it.oIndex + j] = ox;
    20263                                                }
    20264                                        }
    20265                                } else {
    20266                                        while (it.hasNext()) {
    20267                                                final long ix = it.aLong;
    20268                                                long ox;
    20269                                                ox = toLong(Math.sinh(ix));
    20270                                                for (int j = 0; j < is; j++) {
    20271                                                        oai64data[it.oIndex + j] = ox;
    20272                                                }
    20273                                        }
    20274                                }
    20275                        } else {
    20276                                if (it.isOutputDouble()) {
    20277                                        while (it.hasNext()) {
    20278                                                for (int j = 0; j < is; j++) {
    20279                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20280                                                        long ox;
    20281                                                        ox = toLong(Math.sinh(ix));
    20282                                                        oai64data[it.oIndex + j] = ox;
    20283                                                }
    20284                                        }
    20285                                } else {
    20286                                        while (it.hasNext()) {
    20287                                                for (int j = 0; j < is; j++) {
    20288                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20289                                                        long ox;
    20290                                                        ox = toLong(Math.sinh(ix));
    20291                                                        oai64data[it.oIndex + j] = ox;
    20292                                                }
    20293                                        }
    20294                                }
    20295                        }
    20296                        break;
    20297                case Dataset.ARRAYINT32:
    20298                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    20299                        if (is == 1) {
    20300                                if (it.isOutputDouble()) {
    20301                                        while (it.hasNext()) {
    20302                                                final double ix = it.aDouble;
    20303                                                int ox;
    20304                                                ox = (int) toLong(Math.sinh(ix));
    20305                                                oai32data[it.oIndex] = ox;
    20306                                        }
    20307                                } else {
    20308                                        while (it.hasNext()) {
    20309                                                final long ix = it.aLong;
    20310                                                int ox;
    20311                                                ox = (int) toLong(Math.sinh(ix));
    20312                                                oai32data[it.oIndex] = ox;
    20313                                        }
    20314                                }
    20315                        } else if (as == 1) {
    20316                                if (it.isOutputDouble()) {
    20317                                        while (it.hasNext()) {
    20318                                                final double ix = it.aDouble;
    20319                                                int ox;
    20320                                                ox = (int) toLong(Math.sinh(ix));
    20321                                                for (int j = 0; j < is; j++) {
    20322                                                        oai32data[it.oIndex + j] = ox;
    20323                                                }
    20324                                        }
    20325                                } else {
    20326                                        while (it.hasNext()) {
    20327                                                final long ix = it.aLong;
    20328                                                int ox;
    20329                                                ox = (int) toLong(Math.sinh(ix));
    20330                                                for (int j = 0; j < is; j++) {
    20331                                                        oai32data[it.oIndex + j] = ox;
    20332                                                }
    20333                                        }
    20334                                }
    20335                        } else {
    20336                                if (it.isOutputDouble()) {
    20337                                        while (it.hasNext()) {
    20338                                                for (int j = 0; j < is; j++) {
    20339                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20340                                                        int ox;
    20341                                                        ox = (int) toLong(Math.sinh(ix));
    20342                                                        oai32data[it.oIndex + j] = ox;
    20343                                                }
    20344                                        }
    20345                                } else {
    20346                                        while (it.hasNext()) {
    20347                                                for (int j = 0; j < is; j++) {
    20348                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20349                                                        int ox;
    20350                                                        ox = (int) toLong(Math.sinh(ix));
    20351                                                        oai32data[it.oIndex + j] = ox;
    20352                                                }
    20353                                        }
    20354                                }
    20355                        }
    20356                        break;
    20357                case Dataset.FLOAT32:
    20358                        final float[] of32data = ((FloatDataset) result).getData();
    20359                        if (it.isOutputDouble()) {
    20360                                while (it.hasNext()) {
    20361                                        final double ix = it.aDouble;
    20362                                        float ox;
    20363                                        ox = (float) (Math.sinh(ix));
    20364                                        of32data[it.oIndex] = ox;
    20365                                }
    20366                        } else {
    20367                                while (it.hasNext()) {
    20368                                        final long ix = it.aLong;
    20369                                        float ox;
    20370                                        ox = (float) (Math.sinh(ix));
    20371                                        of32data[it.oIndex] = ox;
    20372                                }
    20373                        }
    20374                        break;
    20375                case Dataset.FLOAT64:
    20376                        final double[] of64data = ((DoubleDataset) result).getData();
    20377                        if (it.isOutputDouble()) {
    20378                                while (it.hasNext()) {
    20379                                        final double ix = it.aDouble;
    20380                                        double ox;
    20381                                        ox = (Math.sinh(ix));
    20382                                        of64data[it.oIndex] = ox;
    20383                                }
    20384                        } else {
    20385                                while (it.hasNext()) {
    20386                                        final long ix = it.aLong;
    20387                                        double ox;
    20388                                        ox = (Math.sinh(ix));
    20389                                        of64data[it.oIndex] = ox;
    20390                                }
    20391                        }
    20392                        break;
    20393                case Dataset.ARRAYFLOAT32:
    20394                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    20395                        if (is == 1) {
    20396                                if (it.isOutputDouble()) {
    20397                                        while (it.hasNext()) {
    20398                                                final double ix = it.aDouble;
    20399                                                float ox;
    20400                                                ox = (float) (Math.sinh(ix));
    20401                                                oaf32data[it.oIndex] = ox;
    20402                                        }
    20403                                } else {
    20404                                        while (it.hasNext()) {
    20405                                                final long ix = it.aLong;
    20406                                                float ox;
    20407                                                ox = (float) (Math.sinh(ix));
    20408                                                oaf32data[it.oIndex] = ox;
    20409                                        }
    20410                                }
    20411                        } else if (as == 1) {
    20412                                if (it.isOutputDouble()) {
    20413                                        while (it.hasNext()) {
    20414                                                final double ix = it.aDouble;
    20415                                                float ox;
    20416                                                ox = (float) (Math.sinh(ix));
    20417                                                for (int j = 0; j < is; j++) {
    20418                                                        oaf32data[it.oIndex + j] = ox;
    20419                                                }
    20420                                        }
    20421                                } else {
    20422                                        while (it.hasNext()) {
    20423                                                final long ix = it.aLong;
    20424                                                float ox;
    20425                                                ox = (float) (Math.sinh(ix));
    20426                                                for (int j = 0; j < is; j++) {
    20427                                                        oaf32data[it.oIndex + j] = ox;
    20428                                                }
    20429                                        }
    20430                                }
    20431                        } else {
    20432                                if (it.isOutputDouble()) {
    20433                                        while (it.hasNext()) {
    20434                                                for (int j = 0; j < is; j++) {
    20435                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20436                                                        float ox;
    20437                                                        ox = (float) (Math.sinh(ix));
    20438                                                        oaf32data[it.oIndex + j] = ox;
    20439                                                }
    20440                                        }
    20441                                } else {
    20442                                        while (it.hasNext()) {
    20443                                                for (int j = 0; j < is; j++) {
    20444                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20445                                                        float ox;
    20446                                                        ox = (float) (Math.sinh(ix));
    20447                                                        oaf32data[it.oIndex + j] = ox;
    20448                                                }
    20449                                        }
    20450                                }
    20451                        }
    20452                        break;
    20453                case Dataset.ARRAYFLOAT64:
    20454                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    20455                        if (is == 1) {
    20456                                if (it.isOutputDouble()) {
    20457                                        while (it.hasNext()) {
    20458                                                final double ix = it.aDouble;
    20459                                                double ox;
    20460                                                ox = (Math.sinh(ix));
    20461                                                oaf64data[it.oIndex] = ox;
    20462                                        }
    20463                                } else {
    20464                                        while (it.hasNext()) {
    20465                                                final long ix = it.aLong;
    20466                                                double ox;
    20467                                                ox = (Math.sinh(ix));
    20468                                                oaf64data[it.oIndex] = ox;
    20469                                        }
    20470                                }
    20471                        } else if (as == 1) {
    20472                                if (it.isOutputDouble()) {
    20473                                        while (it.hasNext()) {
    20474                                                final double ix = it.aDouble;
    20475                                                double ox;
    20476                                                ox = (Math.sinh(ix));
    20477                                                for (int j = 0; j < is; j++) {
    20478                                                        oaf64data[it.oIndex + j] = ox;
    20479                                                }
    20480                                        }
    20481                                } else {
    20482                                        while (it.hasNext()) {
    20483                                                final long ix = it.aLong;
    20484                                                double ox;
    20485                                                ox = (Math.sinh(ix));
    20486                                                for (int j = 0; j < is; j++) {
    20487                                                        oaf64data[it.oIndex + j] = ox;
    20488                                                }
    20489                                        }
    20490                                }
    20491                        } else {
    20492                                if (it.isOutputDouble()) {
    20493                                        while (it.hasNext()) {
    20494                                                for (int j = 0; j < is; j++) {
    20495                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20496                                                        double ox;
    20497                                                        ox = (Math.sinh(ix));
    20498                                                        oaf64data[it.oIndex + j] = ox;
    20499                                                }
    20500                                        }
    20501                                } else {
    20502                                        while (it.hasNext()) {
    20503                                                for (int j = 0; j < is; j++) {
    20504                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20505                                                        double ox;
    20506                                                        ox = (Math.sinh(ix));
    20507                                                        oaf64data[it.oIndex + j] = ox;
    20508                                                }
    20509                                        }
    20510                                }
    20511                        }
    20512                        break;
    20513                case Dataset.COMPLEX64:
    20514                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    20515                        if (as == 1) {
    20516                                final double iy = 0;
    20517                                while (it.hasNext()) {
    20518                                        final double ix = it.aDouble;
    20519                                        float ox;
    20520                                        float oy;
    20521                                        ox = (float) (Math.sinh(ix)*Math.cos(iy));
    20522                                        oy = (float) (Math.cosh(ix)*Math.sin(iy));
    20523                                        oc64data[it.oIndex] = ox;
    20524                                        oc64data[it.oIndex + 1] = oy;
    20525                                }
    20526                        } else {
    20527                                while (it.hasNext()) {
    20528                                        final double ix = it.aDouble;
    20529                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    20530                                        float ox;
    20531                                        float oy;
    20532                                        ox = (float) (Math.sinh(ix)*Math.cos(iy));
    20533                                        oy = (float) (Math.cosh(ix)*Math.sin(iy));
    20534                                        oc64data[it.oIndex] = ox;
    20535                                        oc64data[it.oIndex + 1] = oy;
    20536                                }
    20537                        }
    20538                        break;
    20539                case Dataset.COMPLEX128:
    20540                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    20541                        if (as == 1) {
    20542                                final double iy = 0;
    20543                                while (it.hasNext()) {
    20544                                        final double ix = it.aDouble;
    20545                                        double ox;
    20546                                        double oy;
    20547                                        ox = (Math.sinh(ix)*Math.cos(iy));
    20548                                        oy = (Math.cosh(ix)*Math.sin(iy));
    20549                                        oc128data[it.oIndex] = ox;
    20550                                        oc128data[it.oIndex + 1] = oy;
    20551                                }
    20552                        } else {
    20553                                while (it.hasNext()) {
    20554                                        final double ix = it.aDouble;
    20555                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    20556                                        double ox;
    20557                                        double oy;
    20558                                        ox = (Math.sinh(ix)*Math.cos(iy));
    20559                                        oy = (Math.cosh(ix)*Math.sin(iy));
    20560                                        oc128data[it.oIndex] = ox;
    20561                                        oc128data[it.oIndex + 1] = oy;
    20562                                }
    20563                        }
    20564                        break;
    20565                default:
    20566                        throw new IllegalArgumentException("sinh supports integer, compound integer, real, compound real, complex datasets only");
    20567                }
    20568
    20569                addFunctionName(result, "sinh");
    20570                return result;
    20571        }
    20572
    20573        /**
    20574         * cosh - evaluate the hyperbolic cosine function on each element of the dataset
    20575         * @param a
    20576         * @return dataset
    20577         */
    20578        public static Dataset cosh(final Object a) {
    20579                return cosh(a, null);
    20580        }
    20581
    20582        /**
    20583         * cosh - evaluate the hyperbolic cosine function on each element of the dataset
    20584         * @param a
    20585         * @param o output can be null - in which case, a new dataset is created
    20586         * @return dataset
    20587         */
    20588        public static Dataset cosh(final Object a, final Dataset o) {
    20589                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    20590                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    20591                final Dataset result = it.getOutput();
    20592                final int is = result.getElementsPerItem();
    20593                final int as = da.getElementsPerItem();
    20594                final int dt = result.getDType();
    20595
    20596                switch(dt) {
    20597                case Dataset.INT8:
    20598                        final byte[] oi8data = ((ByteDataset) result).getData();
    20599                        if (it.isOutputDouble()) {
    20600                                while (it.hasNext()) {
    20601                                        final double ix = it.aDouble;
    20602                                        byte ox;
    20603                                        ox = (byte) toLong(Math.cosh(ix));
    20604                                        oi8data[it.oIndex] = ox;
    20605                                }
    20606                        } else {
    20607                                while (it.hasNext()) {
    20608                                        final long ix = it.aLong;
    20609                                        byte ox;
    20610                                        ox = (byte) toLong(Math.cosh(ix));
    20611                                        oi8data[it.oIndex] = ox;
    20612                                }
    20613                        }
    20614                        break;
    20615                case Dataset.INT16:
    20616                        final short[] oi16data = ((ShortDataset) result).getData();
    20617                        if (it.isOutputDouble()) {
    20618                                while (it.hasNext()) {
    20619                                        final double ix = it.aDouble;
    20620                                        short ox;
    20621                                        ox = (short) toLong(Math.cosh(ix));
    20622                                        oi16data[it.oIndex] = ox;
    20623                                }
    20624                        } else {
    20625                                while (it.hasNext()) {
    20626                                        final long ix = it.aLong;
    20627                                        short ox;
    20628                                        ox = (short) toLong(Math.cosh(ix));
    20629                                        oi16data[it.oIndex] = ox;
    20630                                }
    20631                        }
    20632                        break;
    20633                case Dataset.INT64:
    20634                        final long[] oi64data = ((LongDataset) result).getData();
    20635                        if (it.isOutputDouble()) {
    20636                                while (it.hasNext()) {
    20637                                        final double ix = it.aDouble;
    20638                                        long ox;
    20639                                        ox = toLong(Math.cosh(ix));
    20640                                        oi64data[it.oIndex] = ox;
    20641                                }
    20642                        } else {
    20643                                while (it.hasNext()) {
    20644                                        final long ix = it.aLong;
    20645                                        long ox;
    20646                                        ox = toLong(Math.cosh(ix));
    20647                                        oi64data[it.oIndex] = ox;
    20648                                }
    20649                        }
    20650                        break;
    20651                case Dataset.INT32:
    20652                        final int[] oi32data = ((IntegerDataset) result).getData();
    20653                        if (it.isOutputDouble()) {
    20654                                while (it.hasNext()) {
    20655                                        final double ix = it.aDouble;
    20656                                        int ox;
    20657                                        ox = (int) toLong(Math.cosh(ix));
    20658                                        oi32data[it.oIndex] = ox;
    20659                                }
    20660                        } else {
    20661                                while (it.hasNext()) {
    20662                                        final long ix = it.aLong;
    20663                                        int ox;
    20664                                        ox = (int) toLong(Math.cosh(ix));
    20665                                        oi32data[it.oIndex] = ox;
    20666                                }
    20667                        }
    20668                        break;
    20669                case Dataset.ARRAYINT8:
    20670                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    20671                        if (is == 1) {
    20672                                if (it.isOutputDouble()) {
    20673                                        while (it.hasNext()) {
    20674                                                final double ix = it.aDouble;
    20675                                                byte ox;
    20676                                                ox = (byte) toLong(Math.cosh(ix));
    20677                                                oai8data[it.oIndex] = ox;
    20678                                        }
    20679                                } else {
    20680                                        while (it.hasNext()) {
    20681                                                final long ix = it.aLong;
    20682                                                byte ox;
    20683                                                ox = (byte) toLong(Math.cosh(ix));
    20684                                                oai8data[it.oIndex] = ox;
    20685                                        }
    20686                                }
    20687                        } else if (as == 1) {
    20688                                if (it.isOutputDouble()) {
    20689                                        while (it.hasNext()) {
    20690                                                final double ix = it.aDouble;
    20691                                                byte ox;
    20692                                                ox = (byte) toLong(Math.cosh(ix));
    20693                                                for (int j = 0; j < is; j++) {
    20694                                                        oai8data[it.oIndex + j] = ox;
    20695                                                }
    20696                                        }
    20697                                } else {
    20698                                        while (it.hasNext()) {
    20699                                                final long ix = it.aLong;
    20700                                                byte ox;
    20701                                                ox = (byte) toLong(Math.cosh(ix));
    20702                                                for (int j = 0; j < is; j++) {
    20703                                                        oai8data[it.oIndex + j] = ox;
    20704                                                }
    20705                                        }
    20706                                }
    20707                        } else {
    20708                                if (it.isOutputDouble()) {
    20709                                        while (it.hasNext()) {
    20710                                                for (int j = 0; j < is; j++) {
    20711                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20712                                                        byte ox;
    20713                                                        ox = (byte) toLong(Math.cosh(ix));
    20714                                                        oai8data[it.oIndex + j] = ox;
    20715                                                }
    20716                                        }
    20717                                } else {
    20718                                        while (it.hasNext()) {
    20719                                                for (int j = 0; j < is; j++) {
    20720                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20721                                                        byte ox;
    20722                                                        ox = (byte) toLong(Math.cosh(ix));
    20723                                                        oai8data[it.oIndex + j] = ox;
    20724                                                }
    20725                                        }
    20726                                }
    20727                        }
    20728                        break;
    20729                case Dataset.ARRAYINT16:
    20730                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    20731                        if (is == 1) {
    20732                                if (it.isOutputDouble()) {
    20733                                        while (it.hasNext()) {
    20734                                                final double ix = it.aDouble;
    20735                                                short ox;
    20736                                                ox = (short) toLong(Math.cosh(ix));
    20737                                                oai16data[it.oIndex] = ox;
    20738                                        }
    20739                                } else {
    20740                                        while (it.hasNext()) {
    20741                                                final long ix = it.aLong;
    20742                                                short ox;
    20743                                                ox = (short) toLong(Math.cosh(ix));
    20744                                                oai16data[it.oIndex] = ox;
    20745                                        }
    20746                                }
    20747                        } else if (as == 1) {
    20748                                if (it.isOutputDouble()) {
    20749                                        while (it.hasNext()) {
    20750                                                final double ix = it.aDouble;
    20751                                                short ox;
    20752                                                ox = (short) toLong(Math.cosh(ix));
    20753                                                for (int j = 0; j < is; j++) {
    20754                                                        oai16data[it.oIndex + j] = ox;
    20755                                                }
    20756                                        }
    20757                                } else {
    20758                                        while (it.hasNext()) {
    20759                                                final long ix = it.aLong;
    20760                                                short ox;
    20761                                                ox = (short) toLong(Math.cosh(ix));
    20762                                                for (int j = 0; j < is; j++) {
    20763                                                        oai16data[it.oIndex + j] = ox;
    20764                                                }
    20765                                        }
    20766                                }
    20767                        } else {
    20768                                if (it.isOutputDouble()) {
    20769                                        while (it.hasNext()) {
    20770                                                for (int j = 0; j < is; j++) {
    20771                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20772                                                        short ox;
    20773                                                        ox = (short) toLong(Math.cosh(ix));
    20774                                                        oai16data[it.oIndex + j] = ox;
    20775                                                }
    20776                                        }
    20777                                } else {
    20778                                        while (it.hasNext()) {
    20779                                                for (int j = 0; j < is; j++) {
    20780                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20781                                                        short ox;
    20782                                                        ox = (short) toLong(Math.cosh(ix));
    20783                                                        oai16data[it.oIndex + j] = ox;
    20784                                                }
    20785                                        }
    20786                                }
    20787                        }
    20788                        break;
    20789                case Dataset.ARRAYINT64:
    20790                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    20791                        if (is == 1) {
    20792                                if (it.isOutputDouble()) {
    20793                                        while (it.hasNext()) {
    20794                                                final double ix = it.aDouble;
    20795                                                long ox;
    20796                                                ox = toLong(Math.cosh(ix));
    20797                                                oai64data[it.oIndex] = ox;
    20798                                        }
    20799                                } else {
    20800                                        while (it.hasNext()) {
    20801                                                final long ix = it.aLong;
    20802                                                long ox;
    20803                                                ox = toLong(Math.cosh(ix));
    20804                                                oai64data[it.oIndex] = ox;
    20805                                        }
    20806                                }
    20807                        } else if (as == 1) {
    20808                                if (it.isOutputDouble()) {
    20809                                        while (it.hasNext()) {
    20810                                                final double ix = it.aDouble;
    20811                                                long ox;
    20812                                                ox = toLong(Math.cosh(ix));
    20813                                                for (int j = 0; j < is; j++) {
    20814                                                        oai64data[it.oIndex + j] = ox;
    20815                                                }
    20816                                        }
    20817                                } else {
    20818                                        while (it.hasNext()) {
    20819                                                final long ix = it.aLong;
    20820                                                long ox;
    20821                                                ox = toLong(Math.cosh(ix));
    20822                                                for (int j = 0; j < is; j++) {
    20823                                                        oai64data[it.oIndex + j] = ox;
    20824                                                }
    20825                                        }
    20826                                }
    20827                        } else {
    20828                                if (it.isOutputDouble()) {
    20829                                        while (it.hasNext()) {
    20830                                                for (int j = 0; j < is; j++) {
    20831                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20832                                                        long ox;
    20833                                                        ox = toLong(Math.cosh(ix));
    20834                                                        oai64data[it.oIndex + j] = ox;
    20835                                                }
    20836                                        }
    20837                                } else {
    20838                                        while (it.hasNext()) {
    20839                                                for (int j = 0; j < is; j++) {
    20840                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20841                                                        long ox;
    20842                                                        ox = toLong(Math.cosh(ix));
    20843                                                        oai64data[it.oIndex + j] = ox;
    20844                                                }
    20845                                        }
    20846                                }
    20847                        }
    20848                        break;
    20849                case Dataset.ARRAYINT32:
    20850                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    20851                        if (is == 1) {
    20852                                if (it.isOutputDouble()) {
    20853                                        while (it.hasNext()) {
    20854                                                final double ix = it.aDouble;
    20855                                                int ox;
    20856                                                ox = (int) toLong(Math.cosh(ix));
    20857                                                oai32data[it.oIndex] = ox;
    20858                                        }
    20859                                } else {
    20860                                        while (it.hasNext()) {
    20861                                                final long ix = it.aLong;
    20862                                                int ox;
    20863                                                ox = (int) toLong(Math.cosh(ix));
    20864                                                oai32data[it.oIndex] = ox;
    20865                                        }
    20866                                }
    20867                        } else if (as == 1) {
    20868                                if (it.isOutputDouble()) {
    20869                                        while (it.hasNext()) {
    20870                                                final double ix = it.aDouble;
    20871                                                int ox;
    20872                                                ox = (int) toLong(Math.cosh(ix));
    20873                                                for (int j = 0; j < is; j++) {
    20874                                                        oai32data[it.oIndex + j] = ox;
    20875                                                }
    20876                                        }
    20877                                } else {
    20878                                        while (it.hasNext()) {
    20879                                                final long ix = it.aLong;
    20880                                                int ox;
    20881                                                ox = (int) toLong(Math.cosh(ix));
    20882                                                for (int j = 0; j < is; j++) {
    20883                                                        oai32data[it.oIndex + j] = ox;
    20884                                                }
    20885                                        }
    20886                                }
    20887                        } else {
    20888                                if (it.isOutputDouble()) {
    20889                                        while (it.hasNext()) {
    20890                                                for (int j = 0; j < is; j++) {
    20891                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20892                                                        int ox;
    20893                                                        ox = (int) toLong(Math.cosh(ix));
    20894                                                        oai32data[it.oIndex + j] = ox;
    20895                                                }
    20896                                        }
    20897                                } else {
    20898                                        while (it.hasNext()) {
    20899                                                for (int j = 0; j < is; j++) {
    20900                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20901                                                        int ox;
    20902                                                        ox = (int) toLong(Math.cosh(ix));
    20903                                                        oai32data[it.oIndex + j] = ox;
    20904                                                }
    20905                                        }
    20906                                }
    20907                        }
    20908                        break;
    20909                case Dataset.FLOAT32:
    20910                        final float[] of32data = ((FloatDataset) result).getData();
    20911                        if (it.isOutputDouble()) {
    20912                                while (it.hasNext()) {
    20913                                        final double ix = it.aDouble;
    20914                                        float ox;
    20915                                        ox = (float) (Math.cosh(ix));
    20916                                        of32data[it.oIndex] = ox;
    20917                                }
    20918                        } else {
    20919                                while (it.hasNext()) {
    20920                                        final long ix = it.aLong;
    20921                                        float ox;
    20922                                        ox = (float) (Math.cosh(ix));
    20923                                        of32data[it.oIndex] = ox;
    20924                                }
    20925                        }
    20926                        break;
    20927                case Dataset.FLOAT64:
    20928                        final double[] of64data = ((DoubleDataset) result).getData();
    20929                        if (it.isOutputDouble()) {
    20930                                while (it.hasNext()) {
    20931                                        final double ix = it.aDouble;
    20932                                        double ox;
    20933                                        ox = (Math.cosh(ix));
    20934                                        of64data[it.oIndex] = ox;
    20935                                }
    20936                        } else {
    20937                                while (it.hasNext()) {
    20938                                        final long ix = it.aLong;
    20939                                        double ox;
    20940                                        ox = (Math.cosh(ix));
    20941                                        of64data[it.oIndex] = ox;
    20942                                }
    20943                        }
    20944                        break;
    20945                case Dataset.ARRAYFLOAT32:
    20946                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    20947                        if (is == 1) {
    20948                                if (it.isOutputDouble()) {
    20949                                        while (it.hasNext()) {
    20950                                                final double ix = it.aDouble;
    20951                                                float ox;
    20952                                                ox = (float) (Math.cosh(ix));
    20953                                                oaf32data[it.oIndex] = ox;
    20954                                        }
    20955                                } else {
    20956                                        while (it.hasNext()) {
    20957                                                final long ix = it.aLong;
    20958                                                float ox;
    20959                                                ox = (float) (Math.cosh(ix));
    20960                                                oaf32data[it.oIndex] = ox;
    20961                                        }
    20962                                }
    20963                        } else if (as == 1) {
    20964                                if (it.isOutputDouble()) {
    20965                                        while (it.hasNext()) {
    20966                                                final double ix = it.aDouble;
    20967                                                float ox;
    20968                                                ox = (float) (Math.cosh(ix));
    20969                                                for (int j = 0; j < is; j++) {
    20970                                                        oaf32data[it.oIndex + j] = ox;
    20971                                                }
    20972                                        }
    20973                                } else {
    20974                                        while (it.hasNext()) {
    20975                                                final long ix = it.aLong;
    20976                                                float ox;
    20977                                                ox = (float) (Math.cosh(ix));
    20978                                                for (int j = 0; j < is; j++) {
    20979                                                        oaf32data[it.oIndex + j] = ox;
    20980                                                }
    20981                                        }
    20982                                }
    20983                        } else {
    20984                                if (it.isOutputDouble()) {
    20985                                        while (it.hasNext()) {
    20986                                                for (int j = 0; j < is; j++) {
    20987                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    20988                                                        float ox;
    20989                                                        ox = (float) (Math.cosh(ix));
    20990                                                        oaf32data[it.oIndex + j] = ox;
    20991                                                }
    20992                                        }
    20993                                } else {
    20994                                        while (it.hasNext()) {
    20995                                                for (int j = 0; j < is; j++) {
    20996                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    20997                                                        float ox;
    20998                                                        ox = (float) (Math.cosh(ix));
    20999                                                        oaf32data[it.oIndex + j] = ox;
    21000                                                }
    21001                                        }
    21002                                }
    21003                        }
    21004                        break;
    21005                case Dataset.ARRAYFLOAT64:
    21006                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    21007                        if (is == 1) {
    21008                                if (it.isOutputDouble()) {
    21009                                        while (it.hasNext()) {
    21010                                                final double ix = it.aDouble;
    21011                                                double ox;
    21012                                                ox = (Math.cosh(ix));
    21013                                                oaf64data[it.oIndex] = ox;
    21014                                        }
    21015                                } else {
    21016                                        while (it.hasNext()) {
    21017                                                final long ix = it.aLong;
    21018                                                double ox;
    21019                                                ox = (Math.cosh(ix));
    21020                                                oaf64data[it.oIndex] = ox;
    21021                                        }
    21022                                }
    21023                        } else if (as == 1) {
    21024                                if (it.isOutputDouble()) {
    21025                                        while (it.hasNext()) {
    21026                                                final double ix = it.aDouble;
    21027                                                double ox;
    21028                                                ox = (Math.cosh(ix));
    21029                                                for (int j = 0; j < is; j++) {
    21030                                                        oaf64data[it.oIndex + j] = ox;
    21031                                                }
    21032                                        }
    21033                                } else {
    21034                                        while (it.hasNext()) {
    21035                                                final long ix = it.aLong;
    21036                                                double ox;
    21037                                                ox = (Math.cosh(ix));
    21038                                                for (int j = 0; j < is; j++) {
    21039                                                        oaf64data[it.oIndex + j] = ox;
    21040                                                }
    21041                                        }
    21042                                }
    21043                        } else {
    21044                                if (it.isOutputDouble()) {
    21045                                        while (it.hasNext()) {
    21046                                                for (int j = 0; j < is; j++) {
    21047                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21048                                                        double ox;
    21049                                                        ox = (Math.cosh(ix));
    21050                                                        oaf64data[it.oIndex + j] = ox;
    21051                                                }
    21052                                        }
    21053                                } else {
    21054                                        while (it.hasNext()) {
    21055                                                for (int j = 0; j < is; j++) {
    21056                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21057                                                        double ox;
    21058                                                        ox = (Math.cosh(ix));
    21059                                                        oaf64data[it.oIndex + j] = ox;
    21060                                                }
    21061                                        }
    21062                                }
    21063                        }
    21064                        break;
    21065                case Dataset.COMPLEX64:
    21066                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    21067                        if (as == 1) {
    21068                                final double iy = 0;
    21069                                while (it.hasNext()) {
    21070                                        final double ix = it.aDouble;
    21071                                        float ox;
    21072                                        float oy;
    21073                                        ox = (float) (Math.cosh(ix)*Math.cos(iy));
    21074                                        oy = (float) (Math.sinh(ix)*Math.sin(iy));
    21075                                        oc64data[it.oIndex] = ox;
    21076                                        oc64data[it.oIndex + 1] = oy;
    21077                                }
    21078                        } else {
    21079                                while (it.hasNext()) {
    21080                                        final double ix = it.aDouble;
    21081                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    21082                                        float ox;
    21083                                        float oy;
    21084                                        ox = (float) (Math.cosh(ix)*Math.cos(iy));
    21085                                        oy = (float) (Math.sinh(ix)*Math.sin(iy));
    21086                                        oc64data[it.oIndex] = ox;
    21087                                        oc64data[it.oIndex + 1] = oy;
    21088                                }
    21089                        }
    21090                        break;
    21091                case Dataset.COMPLEX128:
    21092                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    21093                        if (as == 1) {
    21094                                final double iy = 0;
    21095                                while (it.hasNext()) {
    21096                                        final double ix = it.aDouble;
    21097                                        double ox;
    21098                                        double oy;
    21099                                        ox = (Math.cosh(ix)*Math.cos(iy));
    21100                                        oy = (Math.sinh(ix)*Math.sin(iy));
    21101                                        oc128data[it.oIndex] = ox;
    21102                                        oc128data[it.oIndex + 1] = oy;
    21103                                }
    21104                        } else {
    21105                                while (it.hasNext()) {
    21106                                        final double ix = it.aDouble;
    21107                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    21108                                        double ox;
    21109                                        double oy;
    21110                                        ox = (Math.cosh(ix)*Math.cos(iy));
    21111                                        oy = (Math.sinh(ix)*Math.sin(iy));
    21112                                        oc128data[it.oIndex] = ox;
    21113                                        oc128data[it.oIndex + 1] = oy;
    21114                                }
    21115                        }
    21116                        break;
    21117                default:
    21118                        throw new IllegalArgumentException("cosh supports integer, compound integer, real, compound real, complex datasets only");
    21119                }
    21120
    21121                addFunctionName(result, "cosh");
    21122                return result;
    21123        }
    21124
    21125        /**
    21126         * tanh - evaluate the tangent hyperbolic function on each element of the dataset
    21127         * @param a
    21128         * @return dataset
    21129         */
    21130        public static Dataset tanh(final Object a) {
    21131                return tanh(a, null);
    21132        }
    21133
    21134        /**
    21135         * tanh - evaluate the tangent hyperbolic function on each element of the dataset
    21136         * @param a
    21137         * @param o output can be null - in which case, a new dataset is created
    21138         * @return dataset
    21139         */
    21140        public static Dataset tanh(final Object a, final Dataset o) {
    21141                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    21142                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    21143                final Dataset result = it.getOutput();
    21144                final int is = result.getElementsPerItem();
    21145                final int as = da.getElementsPerItem();
    21146                final int dt = result.getDType();
    21147
    21148                switch(dt) {
    21149                case Dataset.INT8:
    21150                        final byte[] oi8data = ((ByteDataset) result).getData();
    21151                        if (it.isOutputDouble()) {
    21152                                while (it.hasNext()) {
    21153                                        final double ix = it.aDouble;
    21154                                        byte ox;
    21155                                        ox = (byte) toLong(Math.tanh(ix));
    21156                                        oi8data[it.oIndex] = ox;
    21157                                }
    21158                        } else {
    21159                                while (it.hasNext()) {
    21160                                        final long ix = it.aLong;
    21161                                        byte ox;
    21162                                        ox = (byte) toLong(Math.tanh(ix));
    21163                                        oi8data[it.oIndex] = ox;
    21164                                }
    21165                        }
    21166                        break;
    21167                case Dataset.INT16:
    21168                        final short[] oi16data = ((ShortDataset) result).getData();
    21169                        if (it.isOutputDouble()) {
    21170                                while (it.hasNext()) {
    21171                                        final double ix = it.aDouble;
    21172                                        short ox;
    21173                                        ox = (short) toLong(Math.tanh(ix));
    21174                                        oi16data[it.oIndex] = ox;
    21175                                }
    21176                        } else {
    21177                                while (it.hasNext()) {
    21178                                        final long ix = it.aLong;
    21179                                        short ox;
    21180                                        ox = (short) toLong(Math.tanh(ix));
    21181                                        oi16data[it.oIndex] = ox;
    21182                                }
    21183                        }
    21184                        break;
    21185                case Dataset.INT64:
    21186                        final long[] oi64data = ((LongDataset) result).getData();
    21187                        if (it.isOutputDouble()) {
    21188                                while (it.hasNext()) {
    21189                                        final double ix = it.aDouble;
    21190                                        long ox;
    21191                                        ox = toLong(Math.tanh(ix));
    21192                                        oi64data[it.oIndex] = ox;
    21193                                }
    21194                        } else {
    21195                                while (it.hasNext()) {
    21196                                        final long ix = it.aLong;
    21197                                        long ox;
    21198                                        ox = toLong(Math.tanh(ix));
    21199                                        oi64data[it.oIndex] = ox;
    21200                                }
    21201                        }
    21202                        break;
    21203                case Dataset.INT32:
    21204                        final int[] oi32data = ((IntegerDataset) result).getData();
    21205                        if (it.isOutputDouble()) {
    21206                                while (it.hasNext()) {
    21207                                        final double ix = it.aDouble;
    21208                                        int ox;
    21209                                        ox = (int) toLong(Math.tanh(ix));
    21210                                        oi32data[it.oIndex] = ox;
    21211                                }
    21212                        } else {
    21213                                while (it.hasNext()) {
    21214                                        final long ix = it.aLong;
    21215                                        int ox;
    21216                                        ox = (int) toLong(Math.tanh(ix));
    21217                                        oi32data[it.oIndex] = ox;
    21218                                }
    21219                        }
    21220                        break;
    21221                case Dataset.ARRAYINT8:
    21222                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    21223                        if (is == 1) {
    21224                                if (it.isOutputDouble()) {
    21225                                        while (it.hasNext()) {
    21226                                                final double ix = it.aDouble;
    21227                                                byte ox;
    21228                                                ox = (byte) toLong(Math.tanh(ix));
    21229                                                oai8data[it.oIndex] = ox;
    21230                                        }
    21231                                } else {
    21232                                        while (it.hasNext()) {
    21233                                                final long ix = it.aLong;
    21234                                                byte ox;
    21235                                                ox = (byte) toLong(Math.tanh(ix));
    21236                                                oai8data[it.oIndex] = ox;
    21237                                        }
    21238                                }
    21239                        } else if (as == 1) {
    21240                                if (it.isOutputDouble()) {
    21241                                        while (it.hasNext()) {
    21242                                                final double ix = it.aDouble;
    21243                                                byte ox;
    21244                                                ox = (byte) toLong(Math.tanh(ix));
    21245                                                for (int j = 0; j < is; j++) {
    21246                                                        oai8data[it.oIndex + j] = ox;
    21247                                                }
    21248                                        }
    21249                                } else {
    21250                                        while (it.hasNext()) {
    21251                                                final long ix = it.aLong;
    21252                                                byte ox;
    21253                                                ox = (byte) toLong(Math.tanh(ix));
    21254                                                for (int j = 0; j < is; j++) {
    21255                                                        oai8data[it.oIndex + j] = ox;
    21256                                                }
    21257                                        }
    21258                                }
    21259                        } else {
    21260                                if (it.isOutputDouble()) {
    21261                                        while (it.hasNext()) {
    21262                                                for (int j = 0; j < is; j++) {
    21263                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21264                                                        byte ox;
    21265                                                        ox = (byte) toLong(Math.tanh(ix));
    21266                                                        oai8data[it.oIndex + j] = ox;
    21267                                                }
    21268                                        }
    21269                                } else {
    21270                                        while (it.hasNext()) {
    21271                                                for (int j = 0; j < is; j++) {
    21272                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21273                                                        byte ox;
    21274                                                        ox = (byte) toLong(Math.tanh(ix));
    21275                                                        oai8data[it.oIndex + j] = ox;
    21276                                                }
    21277                                        }
    21278                                }
    21279                        }
    21280                        break;
    21281                case Dataset.ARRAYINT16:
    21282                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    21283                        if (is == 1) {
    21284                                if (it.isOutputDouble()) {
    21285                                        while (it.hasNext()) {
    21286                                                final double ix = it.aDouble;
    21287                                                short ox;
    21288                                                ox = (short) toLong(Math.tanh(ix));
    21289                                                oai16data[it.oIndex] = ox;
    21290                                        }
    21291                                } else {
    21292                                        while (it.hasNext()) {
    21293                                                final long ix = it.aLong;
    21294                                                short ox;
    21295                                                ox = (short) toLong(Math.tanh(ix));
    21296                                                oai16data[it.oIndex] = ox;
    21297                                        }
    21298                                }
    21299                        } else if (as == 1) {
    21300                                if (it.isOutputDouble()) {
    21301                                        while (it.hasNext()) {
    21302                                                final double ix = it.aDouble;
    21303                                                short ox;
    21304                                                ox = (short) toLong(Math.tanh(ix));
    21305                                                for (int j = 0; j < is; j++) {
    21306                                                        oai16data[it.oIndex + j] = ox;
    21307                                                }
    21308                                        }
    21309                                } else {
    21310                                        while (it.hasNext()) {
    21311                                                final long ix = it.aLong;
    21312                                                short ox;
    21313                                                ox = (short) toLong(Math.tanh(ix));
    21314                                                for (int j = 0; j < is; j++) {
    21315                                                        oai16data[it.oIndex + j] = ox;
    21316                                                }
    21317                                        }
    21318                                }
    21319                        } else {
    21320                                if (it.isOutputDouble()) {
    21321                                        while (it.hasNext()) {
    21322                                                for (int j = 0; j < is; j++) {
    21323                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21324                                                        short ox;
    21325                                                        ox = (short) toLong(Math.tanh(ix));
    21326                                                        oai16data[it.oIndex + j] = ox;
    21327                                                }
    21328                                        }
    21329                                } else {
    21330                                        while (it.hasNext()) {
    21331                                                for (int j = 0; j < is; j++) {
    21332                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21333                                                        short ox;
    21334                                                        ox = (short) toLong(Math.tanh(ix));
    21335                                                        oai16data[it.oIndex + j] = ox;
    21336                                                }
    21337                                        }
    21338                                }
    21339                        }
    21340                        break;
    21341                case Dataset.ARRAYINT64:
    21342                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    21343                        if (is == 1) {
    21344                                if (it.isOutputDouble()) {
    21345                                        while (it.hasNext()) {
    21346                                                final double ix = it.aDouble;
    21347                                                long ox;
    21348                                                ox = toLong(Math.tanh(ix));
    21349                                                oai64data[it.oIndex] = ox;
    21350                                        }
    21351                                } else {
    21352                                        while (it.hasNext()) {
    21353                                                final long ix = it.aLong;
    21354                                                long ox;
    21355                                                ox = toLong(Math.tanh(ix));
    21356                                                oai64data[it.oIndex] = ox;
    21357                                        }
    21358                                }
    21359                        } else if (as == 1) {
    21360                                if (it.isOutputDouble()) {
    21361                                        while (it.hasNext()) {
    21362                                                final double ix = it.aDouble;
    21363                                                long ox;
    21364                                                ox = toLong(Math.tanh(ix));
    21365                                                for (int j = 0; j < is; j++) {
    21366                                                        oai64data[it.oIndex + j] = ox;
    21367                                                }
    21368                                        }
    21369                                } else {
    21370                                        while (it.hasNext()) {
    21371                                                final long ix = it.aLong;
    21372                                                long ox;
    21373                                                ox = toLong(Math.tanh(ix));
    21374                                                for (int j = 0; j < is; j++) {
    21375                                                        oai64data[it.oIndex + j] = ox;
    21376                                                }
    21377                                        }
    21378                                }
    21379                        } else {
    21380                                if (it.isOutputDouble()) {
    21381                                        while (it.hasNext()) {
    21382                                                for (int j = 0; j < is; j++) {
    21383                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21384                                                        long ox;
    21385                                                        ox = toLong(Math.tanh(ix));
    21386                                                        oai64data[it.oIndex + j] = ox;
    21387                                                }
    21388                                        }
    21389                                } else {
    21390                                        while (it.hasNext()) {
    21391                                                for (int j = 0; j < is; j++) {
    21392                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21393                                                        long ox;
    21394                                                        ox = toLong(Math.tanh(ix));
    21395                                                        oai64data[it.oIndex + j] = ox;
    21396                                                }
    21397                                        }
    21398                                }
    21399                        }
    21400                        break;
    21401                case Dataset.ARRAYINT32:
    21402                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    21403                        if (is == 1) {
    21404                                if (it.isOutputDouble()) {
    21405                                        while (it.hasNext()) {
    21406                                                final double ix = it.aDouble;
    21407                                                int ox;
    21408                                                ox = (int) toLong(Math.tanh(ix));
    21409                                                oai32data[it.oIndex] = ox;
    21410                                        }
    21411                                } else {
    21412                                        while (it.hasNext()) {
    21413                                                final long ix = it.aLong;
    21414                                                int ox;
    21415                                                ox = (int) toLong(Math.tanh(ix));
    21416                                                oai32data[it.oIndex] = ox;
    21417                                        }
    21418                                }
    21419                        } else if (as == 1) {
    21420                                if (it.isOutputDouble()) {
    21421                                        while (it.hasNext()) {
    21422                                                final double ix = it.aDouble;
    21423                                                int ox;
    21424                                                ox = (int) toLong(Math.tanh(ix));
    21425                                                for (int j = 0; j < is; j++) {
    21426                                                        oai32data[it.oIndex + j] = ox;
    21427                                                }
    21428                                        }
    21429                                } else {
    21430                                        while (it.hasNext()) {
    21431                                                final long ix = it.aLong;
    21432                                                int ox;
    21433                                                ox = (int) toLong(Math.tanh(ix));
    21434                                                for (int j = 0; j < is; j++) {
    21435                                                        oai32data[it.oIndex + j] = ox;
    21436                                                }
    21437                                        }
    21438                                }
    21439                        } else {
    21440                                if (it.isOutputDouble()) {
    21441                                        while (it.hasNext()) {
    21442                                                for (int j = 0; j < is; j++) {
    21443                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21444                                                        int ox;
    21445                                                        ox = (int) toLong(Math.tanh(ix));
    21446                                                        oai32data[it.oIndex + j] = ox;
    21447                                                }
    21448                                        }
    21449                                } else {
    21450                                        while (it.hasNext()) {
    21451                                                for (int j = 0; j < is; j++) {
    21452                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21453                                                        int ox;
    21454                                                        ox = (int) toLong(Math.tanh(ix));
    21455                                                        oai32data[it.oIndex + j] = ox;
    21456                                                }
    21457                                        }
    21458                                }
    21459                        }
    21460                        break;
    21461                case Dataset.FLOAT32:
    21462                        final float[] of32data = ((FloatDataset) result).getData();
    21463                        if (it.isOutputDouble()) {
    21464                                while (it.hasNext()) {
    21465                                        final double ix = it.aDouble;
    21466                                        float ox;
    21467                                        ox = (float) (Math.tanh(ix));
    21468                                        of32data[it.oIndex] = ox;
    21469                                }
    21470                        } else {
    21471                                while (it.hasNext()) {
    21472                                        final long ix = it.aLong;
    21473                                        float ox;
    21474                                        ox = (float) (Math.tanh(ix));
    21475                                        of32data[it.oIndex] = ox;
    21476                                }
    21477                        }
    21478                        break;
    21479                case Dataset.FLOAT64:
    21480                        final double[] of64data = ((DoubleDataset) result).getData();
    21481                        if (it.isOutputDouble()) {
    21482                                while (it.hasNext()) {
    21483                                        final double ix = it.aDouble;
    21484                                        double ox;
    21485                                        ox = (Math.tanh(ix));
    21486                                        of64data[it.oIndex] = ox;
    21487                                }
    21488                        } else {
    21489                                while (it.hasNext()) {
    21490                                        final long ix = it.aLong;
    21491                                        double ox;
    21492                                        ox = (Math.tanh(ix));
    21493                                        of64data[it.oIndex] = ox;
    21494                                }
    21495                        }
    21496                        break;
    21497                case Dataset.ARRAYFLOAT32:
    21498                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    21499                        if (is == 1) {
    21500                                if (it.isOutputDouble()) {
    21501                                        while (it.hasNext()) {
    21502                                                final double ix = it.aDouble;
    21503                                                float ox;
    21504                                                ox = (float) (Math.tanh(ix));
    21505                                                oaf32data[it.oIndex] = ox;
    21506                                        }
    21507                                } else {
    21508                                        while (it.hasNext()) {
    21509                                                final long ix = it.aLong;
    21510                                                float ox;
    21511                                                ox = (float) (Math.tanh(ix));
    21512                                                oaf32data[it.oIndex] = ox;
    21513                                        }
    21514                                }
    21515                        } else if (as == 1) {
    21516                                if (it.isOutputDouble()) {
    21517                                        while (it.hasNext()) {
    21518                                                final double ix = it.aDouble;
    21519                                                float ox;
    21520                                                ox = (float) (Math.tanh(ix));
    21521                                                for (int j = 0; j < is; j++) {
    21522                                                        oaf32data[it.oIndex + j] = ox;
    21523                                                }
    21524                                        }
    21525                                } else {
    21526                                        while (it.hasNext()) {
    21527                                                final long ix = it.aLong;
    21528                                                float ox;
    21529                                                ox = (float) (Math.tanh(ix));
    21530                                                for (int j = 0; j < is; j++) {
    21531                                                        oaf32data[it.oIndex + j] = ox;
    21532                                                }
    21533                                        }
    21534                                }
    21535                        } else {
    21536                                if (it.isOutputDouble()) {
    21537                                        while (it.hasNext()) {
    21538                                                for (int j = 0; j < is; j++) {
    21539                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21540                                                        float ox;
    21541                                                        ox = (float) (Math.tanh(ix));
    21542                                                        oaf32data[it.oIndex + j] = ox;
    21543                                                }
    21544                                        }
    21545                                } else {
    21546                                        while (it.hasNext()) {
    21547                                                for (int j = 0; j < is; j++) {
    21548                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21549                                                        float ox;
    21550                                                        ox = (float) (Math.tanh(ix));
    21551                                                        oaf32data[it.oIndex + j] = ox;
    21552                                                }
    21553                                        }
    21554                                }
    21555                        }
    21556                        break;
    21557                case Dataset.ARRAYFLOAT64:
    21558                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    21559                        if (is == 1) {
    21560                                if (it.isOutputDouble()) {
    21561                                        while (it.hasNext()) {
    21562                                                final double ix = it.aDouble;
    21563                                                double ox;
    21564                                                ox = (Math.tanh(ix));
    21565                                                oaf64data[it.oIndex] = ox;
    21566                                        }
    21567                                } else {
    21568                                        while (it.hasNext()) {
    21569                                                final long ix = it.aLong;
    21570                                                double ox;
    21571                                                ox = (Math.tanh(ix));
    21572                                                oaf64data[it.oIndex] = ox;
    21573                                        }
    21574                                }
    21575                        } else if (as == 1) {
    21576                                if (it.isOutputDouble()) {
    21577                                        while (it.hasNext()) {
    21578                                                final double ix = it.aDouble;
    21579                                                double ox;
    21580                                                ox = (Math.tanh(ix));
    21581                                                for (int j = 0; j < is; j++) {
    21582                                                        oaf64data[it.oIndex + j] = ox;
    21583                                                }
    21584                                        }
    21585                                } else {
    21586                                        while (it.hasNext()) {
    21587                                                final long ix = it.aLong;
    21588                                                double ox;
    21589                                                ox = (Math.tanh(ix));
    21590                                                for (int j = 0; j < is; j++) {
    21591                                                        oaf64data[it.oIndex + j] = ox;
    21592                                                }
    21593                                        }
    21594                                }
    21595                        } else {
    21596                                if (it.isOutputDouble()) {
    21597                                        while (it.hasNext()) {
    21598                                                for (int j = 0; j < is; j++) {
    21599                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21600                                                        double ox;
    21601                                                        ox = (Math.tanh(ix));
    21602                                                        oaf64data[it.oIndex + j] = ox;
    21603                                                }
    21604                                        }
    21605                                } else {
    21606                                        while (it.hasNext()) {
    21607                                                for (int j = 0; j < is; j++) {
    21608                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21609                                                        double ox;
    21610                                                        ox = (Math.tanh(ix));
    21611                                                        oaf64data[it.oIndex + j] = ox;
    21612                                                }
    21613                                        }
    21614                                }
    21615                        }
    21616                        break;
    21617                case Dataset.COMPLEX64:
    21618                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    21619                        if (as == 1) {
    21620                                final double iy = 0;
    21621                                while (it.hasNext()) {
    21622                                        final double ix = it.aDouble;
    21623                                        float tx;
    21624                                        float ty;
    21625                                        float tf;
    21626                                        float ox;
    21627                                        float oy;
    21628                                        tx = (float) (2.*ix);
    21629                                        ty = (float) (2.*iy);
    21630                                        tf = (float) (1./(Math.cos(tx)+Math.cosh(ty)));
    21631                                        ox = (float) (tf*Math.sinh(tx));
    21632                                        oy = (float) (tf*Math.sin(ty));
    21633                                        oc64data[it.oIndex] = ox;
    21634                                        oc64data[it.oIndex + 1] = oy;
    21635                                }
    21636                        } else {
    21637                                while (it.hasNext()) {
    21638                                        final double ix = it.aDouble;
    21639                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    21640                                        float tx;
    21641                                        float ty;
    21642                                        float tf;
    21643                                        float ox;
    21644                                        float oy;
    21645                                        tx = (float) (2.*ix);
    21646                                        ty = (float) (2.*iy);
    21647                                        tf = (float) (1./(Math.cos(tx)+Math.cosh(ty)));
    21648                                        ox = (float) (tf*Math.sinh(tx));
    21649                                        oy = (float) (tf*Math.sin(ty));
    21650                                        oc64data[it.oIndex] = ox;
    21651                                        oc64data[it.oIndex + 1] = oy;
    21652                                }
    21653                        }
    21654                        break;
    21655                case Dataset.COMPLEX128:
    21656                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    21657                        if (as == 1) {
    21658                                final double iy = 0;
    21659                                while (it.hasNext()) {
    21660                                        final double ix = it.aDouble;
    21661                                        double tx;
    21662                                        double ty;
    21663                                        double tf;
    21664                                        double ox;
    21665                                        double oy;
    21666                                        tx = (2.*ix);
    21667                                        ty = (2.*iy);
    21668                                        tf = (1./(Math.cos(tx)+Math.cosh(ty)));
    21669                                        ox = (tf*Math.sinh(tx));
    21670                                        oy = (tf*Math.sin(ty));
    21671                                        oc128data[it.oIndex] = ox;
    21672                                        oc128data[it.oIndex + 1] = oy;
    21673                                }
    21674                        } else {
    21675                                while (it.hasNext()) {
    21676                                        final double ix = it.aDouble;
    21677                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    21678                                        double tx;
    21679                                        double ty;
    21680                                        double tf;
    21681                                        double ox;
    21682                                        double oy;
    21683                                        tx = (2.*ix);
    21684                                        ty = (2.*iy);
    21685                                        tf = (1./(Math.cos(tx)+Math.cosh(ty)));
    21686                                        ox = (tf*Math.sinh(tx));
    21687                                        oy = (tf*Math.sin(ty));
    21688                                        oc128data[it.oIndex] = ox;
    21689                                        oc128data[it.oIndex + 1] = oy;
    21690                                }
    21691                        }
    21692                        break;
    21693                default:
    21694                        throw new IllegalArgumentException("tanh supports integer, compound integer, real, compound real, complex datasets only");
    21695                }
    21696
    21697                addFunctionName(result, "tanh");
    21698                return result;
    21699        }
    21700
    21701        /**
    21702         * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
    21703         * @param a
    21704         * @return dataset
    21705         */
    21706        public static Dataset arcsinh(final Object a) {
    21707                return arcsinh(a, null);
    21708        }
    21709
    21710        /**
    21711         * arcsinh - evaluate the inverse hyperbolic sine function on each element of the dataset
    21712         * @param a
    21713         * @param o output can be null - in which case, a new dataset is created
    21714         * @return dataset
    21715         */
    21716        public static Dataset arcsinh(final Object a, final Dataset o) {
    21717                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    21718                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    21719                final Dataset result = it.getOutput();
    21720                final int is = result.getElementsPerItem();
    21721                final int as = da.getElementsPerItem();
    21722                final int dt = result.getDType();
    21723
    21724                switch(dt) {
    21725                case Dataset.INT8:
    21726                        final byte[] oi8data = ((ByteDataset) result).getData();
    21727                        if (it.isOutputDouble()) {
    21728                                while (it.hasNext()) {
    21729                                        final double ix = it.aDouble;
    21730                                        byte ox;
    21731                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21732                                        oi8data[it.oIndex] = ox;
    21733                                }
    21734                        } else {
    21735                                while (it.hasNext()) {
    21736                                        final long ix = it.aLong;
    21737                                        byte ox;
    21738                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21739                                        oi8data[it.oIndex] = ox;
    21740                                }
    21741                        }
    21742                        break;
    21743                case Dataset.INT16:
    21744                        final short[] oi16data = ((ShortDataset) result).getData();
    21745                        if (it.isOutputDouble()) {
    21746                                while (it.hasNext()) {
    21747                                        final double ix = it.aDouble;
    21748                                        short ox;
    21749                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21750                                        oi16data[it.oIndex] = ox;
    21751                                }
    21752                        } else {
    21753                                while (it.hasNext()) {
    21754                                        final long ix = it.aLong;
    21755                                        short ox;
    21756                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21757                                        oi16data[it.oIndex] = ox;
    21758                                }
    21759                        }
    21760                        break;
    21761                case Dataset.INT64:
    21762                        final long[] oi64data = ((LongDataset) result).getData();
    21763                        if (it.isOutputDouble()) {
    21764                                while (it.hasNext()) {
    21765                                        final double ix = it.aDouble;
    21766                                        long ox;
    21767                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21768                                        oi64data[it.oIndex] = ox;
    21769                                }
    21770                        } else {
    21771                                while (it.hasNext()) {
    21772                                        final long ix = it.aLong;
    21773                                        long ox;
    21774                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21775                                        oi64data[it.oIndex] = ox;
    21776                                }
    21777                        }
    21778                        break;
    21779                case Dataset.INT32:
    21780                        final int[] oi32data = ((IntegerDataset) result).getData();
    21781                        if (it.isOutputDouble()) {
    21782                                while (it.hasNext()) {
    21783                                        final double ix = it.aDouble;
    21784                                        int ox;
    21785                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21786                                        oi32data[it.oIndex] = ox;
    21787                                }
    21788                        } else {
    21789                                while (it.hasNext()) {
    21790                                        final long ix = it.aLong;
    21791                                        int ox;
    21792                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21793                                        oi32data[it.oIndex] = ox;
    21794                                }
    21795                        }
    21796                        break;
    21797                case Dataset.ARRAYINT8:
    21798                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    21799                        if (is == 1) {
    21800                                if (it.isOutputDouble()) {
    21801                                        while (it.hasNext()) {
    21802                                                final double ix = it.aDouble;
    21803                                                byte ox;
    21804                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21805                                                oai8data[it.oIndex] = ox;
    21806                                        }
    21807                                } else {
    21808                                        while (it.hasNext()) {
    21809                                                final long ix = it.aLong;
    21810                                                byte ox;
    21811                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21812                                                oai8data[it.oIndex] = ox;
    21813                                        }
    21814                                }
    21815                        } else if (as == 1) {
    21816                                if (it.isOutputDouble()) {
    21817                                        while (it.hasNext()) {
    21818                                                final double ix = it.aDouble;
    21819                                                byte ox;
    21820                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21821                                                for (int j = 0; j < is; j++) {
    21822                                                        oai8data[it.oIndex + j] = ox;
    21823                                                }
    21824                                        }
    21825                                } else {
    21826                                        while (it.hasNext()) {
    21827                                                final long ix = it.aLong;
    21828                                                byte ox;
    21829                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21830                                                for (int j = 0; j < is; j++) {
    21831                                                        oai8data[it.oIndex + j] = ox;
    21832                                                }
    21833                                        }
    21834                                }
    21835                        } else {
    21836                                if (it.isOutputDouble()) {
    21837                                        while (it.hasNext()) {
    21838                                                for (int j = 0; j < is; j++) {
    21839                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21840                                                        byte ox;
    21841                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21842                                                        oai8data[it.oIndex + j] = ox;
    21843                                                }
    21844                                        }
    21845                                } else {
    21846                                        while (it.hasNext()) {
    21847                                                for (int j = 0; j < is; j++) {
    21848                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21849                                                        byte ox;
    21850                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21851                                                        oai8data[it.oIndex + j] = ox;
    21852                                                }
    21853                                        }
    21854                                }
    21855                        }
    21856                        break;
    21857                case Dataset.ARRAYINT16:
    21858                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    21859                        if (is == 1) {
    21860                                if (it.isOutputDouble()) {
    21861                                        while (it.hasNext()) {
    21862                                                final double ix = it.aDouble;
    21863                                                short ox;
    21864                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21865                                                oai16data[it.oIndex] = ox;
    21866                                        }
    21867                                } else {
    21868                                        while (it.hasNext()) {
    21869                                                final long ix = it.aLong;
    21870                                                short ox;
    21871                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21872                                                oai16data[it.oIndex] = ox;
    21873                                        }
    21874                                }
    21875                        } else if (as == 1) {
    21876                                if (it.isOutputDouble()) {
    21877                                        while (it.hasNext()) {
    21878                                                final double ix = it.aDouble;
    21879                                                short ox;
    21880                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21881                                                for (int j = 0; j < is; j++) {
    21882                                                        oai16data[it.oIndex + j] = ox;
    21883                                                }
    21884                                        }
    21885                                } else {
    21886                                        while (it.hasNext()) {
    21887                                                final long ix = it.aLong;
    21888                                                short ox;
    21889                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21890                                                for (int j = 0; j < is; j++) {
    21891                                                        oai16data[it.oIndex + j] = ox;
    21892                                                }
    21893                                        }
    21894                                }
    21895                        } else {
    21896                                if (it.isOutputDouble()) {
    21897                                        while (it.hasNext()) {
    21898                                                for (int j = 0; j < is; j++) {
    21899                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21900                                                        short ox;
    21901                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21902                                                        oai16data[it.oIndex + j] = ox;
    21903                                                }
    21904                                        }
    21905                                } else {
    21906                                        while (it.hasNext()) {
    21907                                                for (int j = 0; j < is; j++) {
    21908                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21909                                                        short ox;
    21910                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21911                                                        oai16data[it.oIndex + j] = ox;
    21912                                                }
    21913                                        }
    21914                                }
    21915                        }
    21916                        break;
    21917                case Dataset.ARRAYINT64:
    21918                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    21919                        if (is == 1) {
    21920                                if (it.isOutputDouble()) {
    21921                                        while (it.hasNext()) {
    21922                                                final double ix = it.aDouble;
    21923                                                long ox;
    21924                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21925                                                oai64data[it.oIndex] = ox;
    21926                                        }
    21927                                } else {
    21928                                        while (it.hasNext()) {
    21929                                                final long ix = it.aLong;
    21930                                                long ox;
    21931                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21932                                                oai64data[it.oIndex] = ox;
    21933                                        }
    21934                                }
    21935                        } else if (as == 1) {
    21936                                if (it.isOutputDouble()) {
    21937                                        while (it.hasNext()) {
    21938                                                final double ix = it.aDouble;
    21939                                                long ox;
    21940                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21941                                                for (int j = 0; j < is; j++) {
    21942                                                        oai64data[it.oIndex + j] = ox;
    21943                                                }
    21944                                        }
    21945                                } else {
    21946                                        while (it.hasNext()) {
    21947                                                final long ix = it.aLong;
    21948                                                long ox;
    21949                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21950                                                for (int j = 0; j < is; j++) {
    21951                                                        oai64data[it.oIndex + j] = ox;
    21952                                                }
    21953                                        }
    21954                                }
    21955                        } else {
    21956                                if (it.isOutputDouble()) {
    21957                                        while (it.hasNext()) {
    21958                                                for (int j = 0; j < is; j++) {
    21959                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    21960                                                        long ox;
    21961                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21962                                                        oai64data[it.oIndex + j] = ox;
    21963                                                }
    21964                                        }
    21965                                } else {
    21966                                        while (it.hasNext()) {
    21967                                                for (int j = 0; j < is; j++) {
    21968                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    21969                                                        long ox;
    21970                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21971                                                        oai64data[it.oIndex + j] = ox;
    21972                                                }
    21973                                        }
    21974                                }
    21975                        }
    21976                        break;
    21977                case Dataset.ARRAYINT32:
    21978                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    21979                        if (is == 1) {
    21980                                if (it.isOutputDouble()) {
    21981                                        while (it.hasNext()) {
    21982                                                final double ix = it.aDouble;
    21983                                                int ox;
    21984                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21985                                                oai32data[it.oIndex] = ox;
    21986                                        }
    21987                                } else {
    21988                                        while (it.hasNext()) {
    21989                                                final long ix = it.aLong;
    21990                                                int ox;
    21991                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    21992                                                oai32data[it.oIndex] = ox;
    21993                                        }
    21994                                }
    21995                        } else if (as == 1) {
    21996                                if (it.isOutputDouble()) {
    21997                                        while (it.hasNext()) {
    21998                                                final double ix = it.aDouble;
    21999                                                int ox;
    22000                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    22001                                                for (int j = 0; j < is; j++) {
    22002                                                        oai32data[it.oIndex + j] = ox;
    22003                                                }
    22004                                        }
    22005                                } else {
    22006                                        while (it.hasNext()) {
    22007                                                final long ix = it.aLong;
    22008                                                int ox;
    22009                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    22010                                                for (int j = 0; j < is; j++) {
    22011                                                        oai32data[it.oIndex + j] = ox;
    22012                                                }
    22013                                        }
    22014                                }
    22015                        } else {
    22016                                if (it.isOutputDouble()) {
    22017                                        while (it.hasNext()) {
    22018                                                for (int j = 0; j < is; j++) {
    22019                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22020                                                        int ox;
    22021                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    22022                                                        oai32data[it.oIndex + j] = ox;
    22023                                                }
    22024                                        }
    22025                                } else {
    22026                                        while (it.hasNext()) {
    22027                                                for (int j = 0; j < is; j++) {
    22028                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22029                                                        int ox;
    22030                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix + 1)));
    22031                                                        oai32data[it.oIndex + j] = ox;
    22032                                                }
    22033                                        }
    22034                                }
    22035                        }
    22036                        break;
    22037                case Dataset.FLOAT32:
    22038                        final float[] of32data = ((FloatDataset) result).getData();
    22039                        if (it.isOutputDouble()) {
    22040                                while (it.hasNext()) {
    22041                                        final double ix = it.aDouble;
    22042                                        float ox;
    22043                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22044                                        of32data[it.oIndex] = ox;
    22045                                }
    22046                        } else {
    22047                                while (it.hasNext()) {
    22048                                        final long ix = it.aLong;
    22049                                        float ox;
    22050                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22051                                        of32data[it.oIndex] = ox;
    22052                                }
    22053                        }
    22054                        break;
    22055                case Dataset.FLOAT64:
    22056                        final double[] of64data = ((DoubleDataset) result).getData();
    22057                        if (it.isOutputDouble()) {
    22058                                while (it.hasNext()) {
    22059                                        final double ix = it.aDouble;
    22060                                        double ox;
    22061                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22062                                        of64data[it.oIndex] = ox;
    22063                                }
    22064                        } else {
    22065                                while (it.hasNext()) {
    22066                                        final long ix = it.aLong;
    22067                                        double ox;
    22068                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22069                                        of64data[it.oIndex] = ox;
    22070                                }
    22071                        }
    22072                        break;
    22073                case Dataset.ARRAYFLOAT32:
    22074                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    22075                        if (is == 1) {
    22076                                if (it.isOutputDouble()) {
    22077                                        while (it.hasNext()) {
    22078                                                final double ix = it.aDouble;
    22079                                                float ox;
    22080                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22081                                                oaf32data[it.oIndex] = ox;
    22082                                        }
    22083                                } else {
    22084                                        while (it.hasNext()) {
    22085                                                final long ix = it.aLong;
    22086                                                float ox;
    22087                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22088                                                oaf32data[it.oIndex] = ox;
    22089                                        }
    22090                                }
    22091                        } else if (as == 1) {
    22092                                if (it.isOutputDouble()) {
    22093                                        while (it.hasNext()) {
    22094                                                final double ix = it.aDouble;
    22095                                                float ox;
    22096                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22097                                                for (int j = 0; j < is; j++) {
    22098                                                        oaf32data[it.oIndex + j] = ox;
    22099                                                }
    22100                                        }
    22101                                } else {
    22102                                        while (it.hasNext()) {
    22103                                                final long ix = it.aLong;
    22104                                                float ox;
    22105                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22106                                                for (int j = 0; j < is; j++) {
    22107                                                        oaf32data[it.oIndex + j] = ox;
    22108                                                }
    22109                                        }
    22110                                }
    22111                        } else {
    22112                                if (it.isOutputDouble()) {
    22113                                        while (it.hasNext()) {
    22114                                                for (int j = 0; j < is; j++) {
    22115                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22116                                                        float ox;
    22117                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22118                                                        oaf32data[it.oIndex + j] = ox;
    22119                                                }
    22120                                        }
    22121                                } else {
    22122                                        while (it.hasNext()) {
    22123                                                for (int j = 0; j < is; j++) {
    22124                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22125                                                        float ox;
    22126                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22127                                                        oaf32data[it.oIndex + j] = ox;
    22128                                                }
    22129                                        }
    22130                                }
    22131                        }
    22132                        break;
    22133                case Dataset.ARRAYFLOAT64:
    22134                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    22135                        if (is == 1) {
    22136                                if (it.isOutputDouble()) {
    22137                                        while (it.hasNext()) {
    22138                                                final double ix = it.aDouble;
    22139                                                double ox;
    22140                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22141                                                oaf64data[it.oIndex] = ox;
    22142                                        }
    22143                                } else {
    22144                                        while (it.hasNext()) {
    22145                                                final long ix = it.aLong;
    22146                                                double ox;
    22147                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22148                                                oaf64data[it.oIndex] = ox;
    22149                                        }
    22150                                }
    22151                        } else if (as == 1) {
    22152                                if (it.isOutputDouble()) {
    22153                                        while (it.hasNext()) {
    22154                                                final double ix = it.aDouble;
    22155                                                double ox;
    22156                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22157                                                for (int j = 0; j < is; j++) {
    22158                                                        oaf64data[it.oIndex + j] = ox;
    22159                                                }
    22160                                        }
    22161                                } else {
    22162                                        while (it.hasNext()) {
    22163                                                final long ix = it.aLong;
    22164                                                double ox;
    22165                                                ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22166                                                for (int j = 0; j < is; j++) {
    22167                                                        oaf64data[it.oIndex + j] = ox;
    22168                                                }
    22169                                        }
    22170                                }
    22171                        } else {
    22172                                if (it.isOutputDouble()) {
    22173                                        while (it.hasNext()) {
    22174                                                for (int j = 0; j < is; j++) {
    22175                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22176                                                        double ox;
    22177                                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22178                                                        oaf64data[it.oIndex + j] = ox;
    22179                                                }
    22180                                        }
    22181                                } else {
    22182                                        while (it.hasNext()) {
    22183                                                for (int j = 0; j < is; j++) {
    22184                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22185                                                        double ox;
    22186                                                        ox = (Math.log(ix + Math.sqrt(ix*ix + 1)));
    22187                                                        oaf64data[it.oIndex + j] = ox;
    22188                                                }
    22189                                        }
    22190                                }
    22191                        }
    22192                        break;
    22193                case Dataset.COMPLEX64:
    22194                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    22195                        if (as == 1) {
    22196                                final double iy = 0;
    22197                                while (it.hasNext()) {
    22198                                        final double ix = it.aDouble;
    22199                                        Complex tz;
    22200                                        float ox;
    22201                                        float oy;
    22202                                        tz = new Complex(-iy, ix).asin();
    22203                                        ox = (float) (tz.getImaginary());
    22204                                        oy = (float) (-tz.getReal());
    22205                                        oc64data[it.oIndex] = ox;
    22206                                        oc64data[it.oIndex + 1] = oy;
    22207                                }
    22208                        } else {
    22209                                while (it.hasNext()) {
    22210                                        final double ix = it.aDouble;
    22211                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    22212                                        Complex tz;
    22213                                        float ox;
    22214                                        float oy;
    22215                                        tz = new Complex(-iy, ix).asin();
    22216                                        ox = (float) (tz.getImaginary());
    22217                                        oy = (float) (-tz.getReal());
    22218                                        oc64data[it.oIndex] = ox;
    22219                                        oc64data[it.oIndex + 1] = oy;
    22220                                }
    22221                        }
    22222                        break;
    22223                case Dataset.COMPLEX128:
    22224                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    22225                        if (as == 1) {
    22226                                final double iy = 0;
    22227                                while (it.hasNext()) {
    22228                                        final double ix = it.aDouble;
    22229                                        Complex tz;
    22230                                        double ox;
    22231                                        double oy;
    22232                                        tz = new Complex(-iy, ix).asin();
    22233                                        ox = (tz.getImaginary());
    22234                                        oy = (-tz.getReal());
    22235                                        oc128data[it.oIndex] = ox;
    22236                                        oc128data[it.oIndex + 1] = oy;
    22237                                }
    22238                        } else {
    22239                                while (it.hasNext()) {
    22240                                        final double ix = it.aDouble;
    22241                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    22242                                        Complex tz;
    22243                                        double ox;
    22244                                        double oy;
    22245                                        tz = new Complex(-iy, ix).asin();
    22246                                        ox = (tz.getImaginary());
    22247                                        oy = (-tz.getReal());
    22248                                        oc128data[it.oIndex] = ox;
    22249                                        oc128data[it.oIndex + 1] = oy;
    22250                                }
    22251                        }
    22252                        break;
    22253                default:
    22254                        throw new IllegalArgumentException("arcsinh supports integer, compound integer, real, compound real, complex datasets only");
    22255                }
    22256
    22257                addFunctionName(result, "arcsinh");
    22258                return result;
    22259        }
    22260
    22261        /**
    22262         * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
    22263         * @param a
    22264         * @return dataset
    22265         */
    22266        public static Dataset arccosh(final Object a) {
    22267                return arccosh(a, null);
    22268        }
    22269
    22270        /**
    22271         * arccosh - evaluate the inverse hyperbolic cosine function on each element of the dataset
    22272         * @param a
    22273         * @param o output can be null - in which case, a new dataset is created
    22274         * @return dataset
    22275         */
    22276        public static Dataset arccosh(final Object a, final Dataset o) {
    22277                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    22278                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    22279                final Dataset result = it.getOutput();
    22280                final int is = result.getElementsPerItem();
    22281                final int as = da.getElementsPerItem();
    22282                final int dt = result.getDType();
    22283
    22284                switch(dt) {
    22285                case Dataset.INT8:
    22286                        final byte[] oi8data = ((ByteDataset) result).getData();
    22287                        if (it.isOutputDouble()) {
    22288                                while (it.hasNext()) {
    22289                                        final double ix = it.aDouble;
    22290                                        byte ox;
    22291                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22292                                        oi8data[it.oIndex] = ox;
    22293                                }
    22294                        } else {
    22295                                while (it.hasNext()) {
    22296                                        final long ix = it.aLong;
    22297                                        byte ox;
    22298                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22299                                        oi8data[it.oIndex] = ox;
    22300                                }
    22301                        }
    22302                        break;
    22303                case Dataset.INT16:
    22304                        final short[] oi16data = ((ShortDataset) result).getData();
    22305                        if (it.isOutputDouble()) {
    22306                                while (it.hasNext()) {
    22307                                        final double ix = it.aDouble;
    22308                                        short ox;
    22309                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22310                                        oi16data[it.oIndex] = ox;
    22311                                }
    22312                        } else {
    22313                                while (it.hasNext()) {
    22314                                        final long ix = it.aLong;
    22315                                        short ox;
    22316                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22317                                        oi16data[it.oIndex] = ox;
    22318                                }
    22319                        }
    22320                        break;
    22321                case Dataset.INT64:
    22322                        final long[] oi64data = ((LongDataset) result).getData();
    22323                        if (it.isOutputDouble()) {
    22324                                while (it.hasNext()) {
    22325                                        final double ix = it.aDouble;
    22326                                        long ox;
    22327                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22328                                        oi64data[it.oIndex] = ox;
    22329                                }
    22330                        } else {
    22331                                while (it.hasNext()) {
    22332                                        final long ix = it.aLong;
    22333                                        long ox;
    22334                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22335                                        oi64data[it.oIndex] = ox;
    22336                                }
    22337                        }
    22338                        break;
    22339                case Dataset.INT32:
    22340                        final int[] oi32data = ((IntegerDataset) result).getData();
    22341                        if (it.isOutputDouble()) {
    22342                                while (it.hasNext()) {
    22343                                        final double ix = it.aDouble;
    22344                                        int ox;
    22345                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22346                                        oi32data[it.oIndex] = ox;
    22347                                }
    22348                        } else {
    22349                                while (it.hasNext()) {
    22350                                        final long ix = it.aLong;
    22351                                        int ox;
    22352                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22353                                        oi32data[it.oIndex] = ox;
    22354                                }
    22355                        }
    22356                        break;
    22357                case Dataset.ARRAYINT8:
    22358                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    22359                        if (is == 1) {
    22360                                if (it.isOutputDouble()) {
    22361                                        while (it.hasNext()) {
    22362                                                final double ix = it.aDouble;
    22363                                                byte ox;
    22364                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22365                                                oai8data[it.oIndex] = ox;
    22366                                        }
    22367                                } else {
    22368                                        while (it.hasNext()) {
    22369                                                final long ix = it.aLong;
    22370                                                byte ox;
    22371                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22372                                                oai8data[it.oIndex] = ox;
    22373                                        }
    22374                                }
    22375                        } else if (as == 1) {
    22376                                if (it.isOutputDouble()) {
    22377                                        while (it.hasNext()) {
    22378                                                final double ix = it.aDouble;
    22379                                                byte ox;
    22380                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22381                                                for (int j = 0; j < is; j++) {
    22382                                                        oai8data[it.oIndex + j] = ox;
    22383                                                }
    22384                                        }
    22385                                } else {
    22386                                        while (it.hasNext()) {
    22387                                                final long ix = it.aLong;
    22388                                                byte ox;
    22389                                                ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22390                                                for (int j = 0; j < is; j++) {
    22391                                                        oai8data[it.oIndex + j] = ox;
    22392                                                }
    22393                                        }
    22394                                }
    22395                        } else {
    22396                                if (it.isOutputDouble()) {
    22397                                        while (it.hasNext()) {
    22398                                                for (int j = 0; j < is; j++) {
    22399                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22400                                                        byte ox;
    22401                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22402                                                        oai8data[it.oIndex + j] = ox;
    22403                                                }
    22404                                        }
    22405                                } else {
    22406                                        while (it.hasNext()) {
    22407                                                for (int j = 0; j < is; j++) {
    22408                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22409                                                        byte ox;
    22410                                                        ox = (byte) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22411                                                        oai8data[it.oIndex + j] = ox;
    22412                                                }
    22413                                        }
    22414                                }
    22415                        }
    22416                        break;
    22417                case Dataset.ARRAYINT16:
    22418                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    22419                        if (is == 1) {
    22420                                if (it.isOutputDouble()) {
    22421                                        while (it.hasNext()) {
    22422                                                final double ix = it.aDouble;
    22423                                                short ox;
    22424                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22425                                                oai16data[it.oIndex] = ox;
    22426                                        }
    22427                                } else {
    22428                                        while (it.hasNext()) {
    22429                                                final long ix = it.aLong;
    22430                                                short ox;
    22431                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22432                                                oai16data[it.oIndex] = ox;
    22433                                        }
    22434                                }
    22435                        } else if (as == 1) {
    22436                                if (it.isOutputDouble()) {
    22437                                        while (it.hasNext()) {
    22438                                                final double ix = it.aDouble;
    22439                                                short ox;
    22440                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22441                                                for (int j = 0; j < is; j++) {
    22442                                                        oai16data[it.oIndex + j] = ox;
    22443                                                }
    22444                                        }
    22445                                } else {
    22446                                        while (it.hasNext()) {
    22447                                                final long ix = it.aLong;
    22448                                                short ox;
    22449                                                ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22450                                                for (int j = 0; j < is; j++) {
    22451                                                        oai16data[it.oIndex + j] = ox;
    22452                                                }
    22453                                        }
    22454                                }
    22455                        } else {
    22456                                if (it.isOutputDouble()) {
    22457                                        while (it.hasNext()) {
    22458                                                for (int j = 0; j < is; j++) {
    22459                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22460                                                        short ox;
    22461                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22462                                                        oai16data[it.oIndex + j] = ox;
    22463                                                }
    22464                                        }
    22465                                } else {
    22466                                        while (it.hasNext()) {
    22467                                                for (int j = 0; j < is; j++) {
    22468                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22469                                                        short ox;
    22470                                                        ox = (short) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22471                                                        oai16data[it.oIndex + j] = ox;
    22472                                                }
    22473                                        }
    22474                                }
    22475                        }
    22476                        break;
    22477                case Dataset.ARRAYINT64:
    22478                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    22479                        if (is == 1) {
    22480                                if (it.isOutputDouble()) {
    22481                                        while (it.hasNext()) {
    22482                                                final double ix = it.aDouble;
    22483                                                long ox;
    22484                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22485                                                oai64data[it.oIndex] = ox;
    22486                                        }
    22487                                } else {
    22488                                        while (it.hasNext()) {
    22489                                                final long ix = it.aLong;
    22490                                                long ox;
    22491                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22492                                                oai64data[it.oIndex] = ox;
    22493                                        }
    22494                                }
    22495                        } else if (as == 1) {
    22496                                if (it.isOutputDouble()) {
    22497                                        while (it.hasNext()) {
    22498                                                final double ix = it.aDouble;
    22499                                                long ox;
    22500                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22501                                                for (int j = 0; j < is; j++) {
    22502                                                        oai64data[it.oIndex + j] = ox;
    22503                                                }
    22504                                        }
    22505                                } else {
    22506                                        while (it.hasNext()) {
    22507                                                final long ix = it.aLong;
    22508                                                long ox;
    22509                                                ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22510                                                for (int j = 0; j < is; j++) {
    22511                                                        oai64data[it.oIndex + j] = ox;
    22512                                                }
    22513                                        }
    22514                                }
    22515                        } else {
    22516                                if (it.isOutputDouble()) {
    22517                                        while (it.hasNext()) {
    22518                                                for (int j = 0; j < is; j++) {
    22519                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22520                                                        long ox;
    22521                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22522                                                        oai64data[it.oIndex + j] = ox;
    22523                                                }
    22524                                        }
    22525                                } else {
    22526                                        while (it.hasNext()) {
    22527                                                for (int j = 0; j < is; j++) {
    22528                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22529                                                        long ox;
    22530                                                        ox = toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22531                                                        oai64data[it.oIndex + j] = ox;
    22532                                                }
    22533                                        }
    22534                                }
    22535                        }
    22536                        break;
    22537                case Dataset.ARRAYINT32:
    22538                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    22539                        if (is == 1) {
    22540                                if (it.isOutputDouble()) {
    22541                                        while (it.hasNext()) {
    22542                                                final double ix = it.aDouble;
    22543                                                int ox;
    22544                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22545                                                oai32data[it.oIndex] = ox;
    22546                                        }
    22547                                } else {
    22548                                        while (it.hasNext()) {
    22549                                                final long ix = it.aLong;
    22550                                                int ox;
    22551                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22552                                                oai32data[it.oIndex] = ox;
    22553                                        }
    22554                                }
    22555                        } else if (as == 1) {
    22556                                if (it.isOutputDouble()) {
    22557                                        while (it.hasNext()) {
    22558                                                final double ix = it.aDouble;
    22559                                                int ox;
    22560                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22561                                                for (int j = 0; j < is; j++) {
    22562                                                        oai32data[it.oIndex + j] = ox;
    22563                                                }
    22564                                        }
    22565                                } else {
    22566                                        while (it.hasNext()) {
    22567                                                final long ix = it.aLong;
    22568                                                int ox;
    22569                                                ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22570                                                for (int j = 0; j < is; j++) {
    22571                                                        oai32data[it.oIndex + j] = ox;
    22572                                                }
    22573                                        }
    22574                                }
    22575                        } else {
    22576                                if (it.isOutputDouble()) {
    22577                                        while (it.hasNext()) {
    22578                                                for (int j = 0; j < is; j++) {
    22579                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22580                                                        int ox;
    22581                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22582                                                        oai32data[it.oIndex + j] = ox;
    22583                                                }
    22584                                        }
    22585                                } else {
    22586                                        while (it.hasNext()) {
    22587                                                for (int j = 0; j < is; j++) {
    22588                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22589                                                        int ox;
    22590                                                        ox = (int) toLong(Math.log(ix + Math.sqrt(ix*ix - 1)));
    22591                                                        oai32data[it.oIndex + j] = ox;
    22592                                                }
    22593                                        }
    22594                                }
    22595                        }
    22596                        break;
    22597                case Dataset.FLOAT32:
    22598                        final float[] of32data = ((FloatDataset) result).getData();
    22599                        if (it.isOutputDouble()) {
    22600                                while (it.hasNext()) {
    22601                                        final double ix = it.aDouble;
    22602                                        float ox;
    22603                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22604                                        of32data[it.oIndex] = ox;
    22605                                }
    22606                        } else {
    22607                                while (it.hasNext()) {
    22608                                        final long ix = it.aLong;
    22609                                        float ox;
    22610                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22611                                        of32data[it.oIndex] = ox;
    22612                                }
    22613                        }
    22614                        break;
    22615                case Dataset.FLOAT64:
    22616                        final double[] of64data = ((DoubleDataset) result).getData();
    22617                        if (it.isOutputDouble()) {
    22618                                while (it.hasNext()) {
    22619                                        final double ix = it.aDouble;
    22620                                        double ox;
    22621                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22622                                        of64data[it.oIndex] = ox;
    22623                                }
    22624                        } else {
    22625                                while (it.hasNext()) {
    22626                                        final long ix = it.aLong;
    22627                                        double ox;
    22628                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22629                                        of64data[it.oIndex] = ox;
    22630                                }
    22631                        }
    22632                        break;
    22633                case Dataset.ARRAYFLOAT32:
    22634                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    22635                        if (is == 1) {
    22636                                if (it.isOutputDouble()) {
    22637                                        while (it.hasNext()) {
    22638                                                final double ix = it.aDouble;
    22639                                                float ox;
    22640                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22641                                                oaf32data[it.oIndex] = ox;
    22642                                        }
    22643                                } else {
    22644                                        while (it.hasNext()) {
    22645                                                final long ix = it.aLong;
    22646                                                float ox;
    22647                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22648                                                oaf32data[it.oIndex] = ox;
    22649                                        }
    22650                                }
    22651                        } else if (as == 1) {
    22652                                if (it.isOutputDouble()) {
    22653                                        while (it.hasNext()) {
    22654                                                final double ix = it.aDouble;
    22655                                                float ox;
    22656                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22657                                                for (int j = 0; j < is; j++) {
    22658                                                        oaf32data[it.oIndex + j] = ox;
    22659                                                }
    22660                                        }
    22661                                } else {
    22662                                        while (it.hasNext()) {
    22663                                                final long ix = it.aLong;
    22664                                                float ox;
    22665                                                ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22666                                                for (int j = 0; j < is; j++) {
    22667                                                        oaf32data[it.oIndex + j] = ox;
    22668                                                }
    22669                                        }
    22670                                }
    22671                        } else {
    22672                                if (it.isOutputDouble()) {
    22673                                        while (it.hasNext()) {
    22674                                                for (int j = 0; j < is; j++) {
    22675                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22676                                                        float ox;
    22677                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22678                                                        oaf32data[it.oIndex + j] = ox;
    22679                                                }
    22680                                        }
    22681                                } else {
    22682                                        while (it.hasNext()) {
    22683                                                for (int j = 0; j < is; j++) {
    22684                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22685                                                        float ox;
    22686                                                        ox = (float) (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22687                                                        oaf32data[it.oIndex + j] = ox;
    22688                                                }
    22689                                        }
    22690                                }
    22691                        }
    22692                        break;
    22693                case Dataset.ARRAYFLOAT64:
    22694                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    22695                        if (is == 1) {
    22696                                if (it.isOutputDouble()) {
    22697                                        while (it.hasNext()) {
    22698                                                final double ix = it.aDouble;
    22699                                                double ox;
    22700                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22701                                                oaf64data[it.oIndex] = ox;
    22702                                        }
    22703                                } else {
    22704                                        while (it.hasNext()) {
    22705                                                final long ix = it.aLong;
    22706                                                double ox;
    22707                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22708                                                oaf64data[it.oIndex] = ox;
    22709                                        }
    22710                                }
    22711                        } else if (as == 1) {
    22712                                if (it.isOutputDouble()) {
    22713                                        while (it.hasNext()) {
    22714                                                final double ix = it.aDouble;
    22715                                                double ox;
    22716                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22717                                                for (int j = 0; j < is; j++) {
    22718                                                        oaf64data[it.oIndex + j] = ox;
    22719                                                }
    22720                                        }
    22721                                } else {
    22722                                        while (it.hasNext()) {
    22723                                                final long ix = it.aLong;
    22724                                                double ox;
    22725                                                ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22726                                                for (int j = 0; j < is; j++) {
    22727                                                        oaf64data[it.oIndex + j] = ox;
    22728                                                }
    22729                                        }
    22730                                }
    22731                        } else {
    22732                                if (it.isOutputDouble()) {
    22733                                        while (it.hasNext()) {
    22734                                                for (int j = 0; j < is; j++) {
    22735                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22736                                                        double ox;
    22737                                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22738                                                        oaf64data[it.oIndex + j] = ox;
    22739                                                }
    22740                                        }
    22741                                } else {
    22742                                        while (it.hasNext()) {
    22743                                                for (int j = 0; j < is; j++) {
    22744                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22745                                                        double ox;
    22746                                                        ox = (Math.log(ix + Math.sqrt(ix*ix - 1)));
    22747                                                        oaf64data[it.oIndex + j] = ox;
    22748                                                }
    22749                                        }
    22750                                }
    22751                        }
    22752                        break;
    22753                case Dataset.COMPLEX64:
    22754                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    22755                        if (as == 1) {
    22756                                final double iy = 0;
    22757                                while (it.hasNext()) {
    22758                                        final double ix = it.aDouble;
    22759                                        Complex tz;
    22760                                        float ox;
    22761                                        float oy;
    22762                                        tz = new Complex(-iy, ix).acos();
    22763                                        ox = (float) (tz.getImaginary());
    22764                                        oy = (float) (-tz.getReal());
    22765                                        oc64data[it.oIndex] = ox;
    22766                                        oc64data[it.oIndex + 1] = oy;
    22767                                }
    22768                        } else {
    22769                                while (it.hasNext()) {
    22770                                        final double ix = it.aDouble;
    22771                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    22772                                        Complex tz;
    22773                                        float ox;
    22774                                        float oy;
    22775                                        tz = new Complex(-iy, ix).acos();
    22776                                        ox = (float) (tz.getImaginary());
    22777                                        oy = (float) (-tz.getReal());
    22778                                        oc64data[it.oIndex] = ox;
    22779                                        oc64data[it.oIndex + 1] = oy;
    22780                                }
    22781                        }
    22782                        break;
    22783                case Dataset.COMPLEX128:
    22784                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    22785                        if (as == 1) {
    22786                                final double iy = 0;
    22787                                while (it.hasNext()) {
    22788                                        final double ix = it.aDouble;
    22789                                        Complex tz;
    22790                                        double ox;
    22791                                        double oy;
    22792                                        tz = new Complex(-iy, ix).acos();
    22793                                        ox = (tz.getImaginary());
    22794                                        oy = (-tz.getReal());
    22795                                        oc128data[it.oIndex] = ox;
    22796                                        oc128data[it.oIndex + 1] = oy;
    22797                                }
    22798                        } else {
    22799                                while (it.hasNext()) {
    22800                                        final double ix = it.aDouble;
    22801                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    22802                                        Complex tz;
    22803                                        double ox;
    22804                                        double oy;
    22805                                        tz = new Complex(-iy, ix).acos();
    22806                                        ox = (tz.getImaginary());
    22807                                        oy = (-tz.getReal());
    22808                                        oc128data[it.oIndex] = ox;
    22809                                        oc128data[it.oIndex + 1] = oy;
    22810                                }
    22811                        }
    22812                        break;
    22813                default:
    22814                        throw new IllegalArgumentException("arccosh supports integer, compound integer, real, compound real, complex datasets only");
    22815                }
    22816
    22817                addFunctionName(result, "arccosh");
    22818                return result;
    22819        }
    22820
    22821        /**
    22822         * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
    22823         * @param a
    22824         * @return dataset
    22825         */
    22826        public static Dataset arctanh(final Object a) {
    22827                return arctanh(a, null);
    22828        }
    22829
    22830        /**
    22831         * arctanh - evaluate the inverse hyperbolic tangent function on each element of the dataset
    22832         * @param a
    22833         * @param o output can be null - in which case, a new dataset is created
    22834         * @return dataset
    22835         */
    22836        public static Dataset arctanh(final Object a, final Dataset o) {
    22837                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    22838                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    22839                final Dataset result = it.getOutput();
    22840                final int is = result.getElementsPerItem();
    22841                final int as = da.getElementsPerItem();
    22842                final int dt = result.getDType();
    22843
    22844                switch(dt) {
    22845                case Dataset.INT8:
    22846                        final byte[] oi8data = ((ByteDataset) result).getData();
    22847                        if (it.isOutputDouble()) {
    22848                                while (it.hasNext()) {
    22849                                        final double ix = it.aDouble;
    22850                                        byte ox;
    22851                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22852                                        oi8data[it.oIndex] = ox;
    22853                                }
    22854                        } else {
    22855                                while (it.hasNext()) {
    22856                                        final long ix = it.aLong;
    22857                                        byte ox;
    22858                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22859                                        oi8data[it.oIndex] = ox;
    22860                                }
    22861                        }
    22862                        break;
    22863                case Dataset.INT16:
    22864                        final short[] oi16data = ((ShortDataset) result).getData();
    22865                        if (it.isOutputDouble()) {
    22866                                while (it.hasNext()) {
    22867                                        final double ix = it.aDouble;
    22868                                        short ox;
    22869                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22870                                        oi16data[it.oIndex] = ox;
    22871                                }
    22872                        } else {
    22873                                while (it.hasNext()) {
    22874                                        final long ix = it.aLong;
    22875                                        short ox;
    22876                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22877                                        oi16data[it.oIndex] = ox;
    22878                                }
    22879                        }
    22880                        break;
    22881                case Dataset.INT64:
    22882                        final long[] oi64data = ((LongDataset) result).getData();
    22883                        if (it.isOutputDouble()) {
    22884                                while (it.hasNext()) {
    22885                                        final double ix = it.aDouble;
    22886                                        long ox;
    22887                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22888                                        oi64data[it.oIndex] = ox;
    22889                                }
    22890                        } else {
    22891                                while (it.hasNext()) {
    22892                                        final long ix = it.aLong;
    22893                                        long ox;
    22894                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22895                                        oi64data[it.oIndex] = ox;
    22896                                }
    22897                        }
    22898                        break;
    22899                case Dataset.INT32:
    22900                        final int[] oi32data = ((IntegerDataset) result).getData();
    22901                        if (it.isOutputDouble()) {
    22902                                while (it.hasNext()) {
    22903                                        final double ix = it.aDouble;
    22904                                        int ox;
    22905                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22906                                        oi32data[it.oIndex] = ox;
    22907                                }
    22908                        } else {
    22909                                while (it.hasNext()) {
    22910                                        final long ix = it.aLong;
    22911                                        int ox;
    22912                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22913                                        oi32data[it.oIndex] = ox;
    22914                                }
    22915                        }
    22916                        break;
    22917                case Dataset.ARRAYINT8:
    22918                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    22919                        if (is == 1) {
    22920                                if (it.isOutputDouble()) {
    22921                                        while (it.hasNext()) {
    22922                                                final double ix = it.aDouble;
    22923                                                byte ox;
    22924                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22925                                                oai8data[it.oIndex] = ox;
    22926                                        }
    22927                                } else {
    22928                                        while (it.hasNext()) {
    22929                                                final long ix = it.aLong;
    22930                                                byte ox;
    22931                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22932                                                oai8data[it.oIndex] = ox;
    22933                                        }
    22934                                }
    22935                        } else if (as == 1) {
    22936                                if (it.isOutputDouble()) {
    22937                                        while (it.hasNext()) {
    22938                                                final double ix = it.aDouble;
    22939                                                byte ox;
    22940                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22941                                                for (int j = 0; j < is; j++) {
    22942                                                        oai8data[it.oIndex + j] = ox;
    22943                                                }
    22944                                        }
    22945                                } else {
    22946                                        while (it.hasNext()) {
    22947                                                final long ix = it.aLong;
    22948                                                byte ox;
    22949                                                ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22950                                                for (int j = 0; j < is; j++) {
    22951                                                        oai8data[it.oIndex + j] = ox;
    22952                                                }
    22953                                        }
    22954                                }
    22955                        } else {
    22956                                if (it.isOutputDouble()) {
    22957                                        while (it.hasNext()) {
    22958                                                for (int j = 0; j < is; j++) {
    22959                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    22960                                                        byte ox;
    22961                                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22962                                                        oai8data[it.oIndex + j] = ox;
    22963                                                }
    22964                                        }
    22965                                } else {
    22966                                        while (it.hasNext()) {
    22967                                                for (int j = 0; j < is; j++) {
    22968                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    22969                                                        byte ox;
    22970                                                        ox = (byte) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22971                                                        oai8data[it.oIndex + j] = ox;
    22972                                                }
    22973                                        }
    22974                                }
    22975                        }
    22976                        break;
    22977                case Dataset.ARRAYINT16:
    22978                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    22979                        if (is == 1) {
    22980                                if (it.isOutputDouble()) {
    22981                                        while (it.hasNext()) {
    22982                                                final double ix = it.aDouble;
    22983                                                short ox;
    22984                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22985                                                oai16data[it.oIndex] = ox;
    22986                                        }
    22987                                } else {
    22988                                        while (it.hasNext()) {
    22989                                                final long ix = it.aLong;
    22990                                                short ox;
    22991                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    22992                                                oai16data[it.oIndex] = ox;
    22993                                        }
    22994                                }
    22995                        } else if (as == 1) {
    22996                                if (it.isOutputDouble()) {
    22997                                        while (it.hasNext()) {
    22998                                                final double ix = it.aDouble;
    22999                                                short ox;
    23000                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23001                                                for (int j = 0; j < is; j++) {
    23002                                                        oai16data[it.oIndex + j] = ox;
    23003                                                }
    23004                                        }
    23005                                } else {
    23006                                        while (it.hasNext()) {
    23007                                                final long ix = it.aLong;
    23008                                                short ox;
    23009                                                ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23010                                                for (int j = 0; j < is; j++) {
    23011                                                        oai16data[it.oIndex + j] = ox;
    23012                                                }
    23013                                        }
    23014                                }
    23015                        } else {
    23016                                if (it.isOutputDouble()) {
    23017                                        while (it.hasNext()) {
    23018                                                for (int j = 0; j < is; j++) {
    23019                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23020                                                        short ox;
    23021                                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23022                                                        oai16data[it.oIndex + j] = ox;
    23023                                                }
    23024                                        }
    23025                                } else {
    23026                                        while (it.hasNext()) {
    23027                                                for (int j = 0; j < is; j++) {
    23028                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23029                                                        short ox;
    23030                                                        ox = (short) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23031                                                        oai16data[it.oIndex + j] = ox;
    23032                                                }
    23033                                        }
    23034                                }
    23035                        }
    23036                        break;
    23037                case Dataset.ARRAYINT64:
    23038                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    23039                        if (is == 1) {
    23040                                if (it.isOutputDouble()) {
    23041                                        while (it.hasNext()) {
    23042                                                final double ix = it.aDouble;
    23043                                                long ox;
    23044                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23045                                                oai64data[it.oIndex] = ox;
    23046                                        }
    23047                                } else {
    23048                                        while (it.hasNext()) {
    23049                                                final long ix = it.aLong;
    23050                                                long ox;
    23051                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23052                                                oai64data[it.oIndex] = ox;
    23053                                        }
    23054                                }
    23055                        } else if (as == 1) {
    23056                                if (it.isOutputDouble()) {
    23057                                        while (it.hasNext()) {
    23058                                                final double ix = it.aDouble;
    23059                                                long ox;
    23060                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23061                                                for (int j = 0; j < is; j++) {
    23062                                                        oai64data[it.oIndex + j] = ox;
    23063                                                }
    23064                                        }
    23065                                } else {
    23066                                        while (it.hasNext()) {
    23067                                                final long ix = it.aLong;
    23068                                                long ox;
    23069                                                ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23070                                                for (int j = 0; j < is; j++) {
    23071                                                        oai64data[it.oIndex + j] = ox;
    23072                                                }
    23073                                        }
    23074                                }
    23075                        } else {
    23076                                if (it.isOutputDouble()) {
    23077                                        while (it.hasNext()) {
    23078                                                for (int j = 0; j < is; j++) {
    23079                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23080                                                        long ox;
    23081                                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23082                                                        oai64data[it.oIndex + j] = ox;
    23083                                                }
    23084                                        }
    23085                                } else {
    23086                                        while (it.hasNext()) {
    23087                                                for (int j = 0; j < is; j++) {
    23088                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23089                                                        long ox;
    23090                                                        ox = toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23091                                                        oai64data[it.oIndex + j] = ox;
    23092                                                }
    23093                                        }
    23094                                }
    23095                        }
    23096                        break;
    23097                case Dataset.ARRAYINT32:
    23098                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    23099                        if (is == 1) {
    23100                                if (it.isOutputDouble()) {
    23101                                        while (it.hasNext()) {
    23102                                                final double ix = it.aDouble;
    23103                                                int ox;
    23104                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23105                                                oai32data[it.oIndex] = ox;
    23106                                        }
    23107                                } else {
    23108                                        while (it.hasNext()) {
    23109                                                final long ix = it.aLong;
    23110                                                int ox;
    23111                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23112                                                oai32data[it.oIndex] = ox;
    23113                                        }
    23114                                }
    23115                        } else if (as == 1) {
    23116                                if (it.isOutputDouble()) {
    23117                                        while (it.hasNext()) {
    23118                                                final double ix = it.aDouble;
    23119                                                int ox;
    23120                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23121                                                for (int j = 0; j < is; j++) {
    23122                                                        oai32data[it.oIndex + j] = ox;
    23123                                                }
    23124                                        }
    23125                                } else {
    23126                                        while (it.hasNext()) {
    23127                                                final long ix = it.aLong;
    23128                                                int ox;
    23129                                                ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23130                                                for (int j = 0; j < is; j++) {
    23131                                                        oai32data[it.oIndex + j] = ox;
    23132                                                }
    23133                                        }
    23134                                }
    23135                        } else {
    23136                                if (it.isOutputDouble()) {
    23137                                        while (it.hasNext()) {
    23138                                                for (int j = 0; j < is; j++) {
    23139                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23140                                                        int ox;
    23141                                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23142                                                        oai32data[it.oIndex + j] = ox;
    23143                                                }
    23144                                        }
    23145                                } else {
    23146                                        while (it.hasNext()) {
    23147                                                for (int j = 0; j < is; j++) {
    23148                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23149                                                        int ox;
    23150                                                        ox = (int) toLong(0.5*Math.log((1 + ix)/(1 - ix)));
    23151                                                        oai32data[it.oIndex + j] = ox;
    23152                                                }
    23153                                        }
    23154                                }
    23155                        }
    23156                        break;
    23157                case Dataset.FLOAT32:
    23158                        final float[] of32data = ((FloatDataset) result).getData();
    23159                        if (it.isOutputDouble()) {
    23160                                while (it.hasNext()) {
    23161                                        final double ix = it.aDouble;
    23162                                        float ox;
    23163                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23164                                        of32data[it.oIndex] = ox;
    23165                                }
    23166                        } else {
    23167                                while (it.hasNext()) {
    23168                                        final long ix = it.aLong;
    23169                                        float ox;
    23170                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23171                                        of32data[it.oIndex] = ox;
    23172                                }
    23173                        }
    23174                        break;
    23175                case Dataset.FLOAT64:
    23176                        final double[] of64data = ((DoubleDataset) result).getData();
    23177                        if (it.isOutputDouble()) {
    23178                                while (it.hasNext()) {
    23179                                        final double ix = it.aDouble;
    23180                                        double ox;
    23181                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23182                                        of64data[it.oIndex] = ox;
    23183                                }
    23184                        } else {
    23185                                while (it.hasNext()) {
    23186                                        final long ix = it.aLong;
    23187                                        double ox;
    23188                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23189                                        of64data[it.oIndex] = ox;
    23190                                }
    23191                        }
    23192                        break;
    23193                case Dataset.ARRAYFLOAT32:
    23194                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    23195                        if (is == 1) {
    23196                                if (it.isOutputDouble()) {
    23197                                        while (it.hasNext()) {
    23198                                                final double ix = it.aDouble;
    23199                                                float ox;
    23200                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23201                                                oaf32data[it.oIndex] = ox;
    23202                                        }
    23203                                } else {
    23204                                        while (it.hasNext()) {
    23205                                                final long ix = it.aLong;
    23206                                                float ox;
    23207                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23208                                                oaf32data[it.oIndex] = ox;
    23209                                        }
    23210                                }
    23211                        } else if (as == 1) {
    23212                                if (it.isOutputDouble()) {
    23213                                        while (it.hasNext()) {
    23214                                                final double ix = it.aDouble;
    23215                                                float ox;
    23216                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23217                                                for (int j = 0; j < is; j++) {
    23218                                                        oaf32data[it.oIndex + j] = ox;
    23219                                                }
    23220                                        }
    23221                                } else {
    23222                                        while (it.hasNext()) {
    23223                                                final long ix = it.aLong;
    23224                                                float ox;
    23225                                                ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23226                                                for (int j = 0; j < is; j++) {
    23227                                                        oaf32data[it.oIndex + j] = ox;
    23228                                                }
    23229                                        }
    23230                                }
    23231                        } else {
    23232                                if (it.isOutputDouble()) {
    23233                                        while (it.hasNext()) {
    23234                                                for (int j = 0; j < is; j++) {
    23235                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23236                                                        float ox;
    23237                                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23238                                                        oaf32data[it.oIndex + j] = ox;
    23239                                                }
    23240                                        }
    23241                                } else {
    23242                                        while (it.hasNext()) {
    23243                                                for (int j = 0; j < is; j++) {
    23244                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23245                                                        float ox;
    23246                                                        ox = (float) (0.5*Math.log((1 + ix)/(1 - ix)));
    23247                                                        oaf32data[it.oIndex + j] = ox;
    23248                                                }
    23249                                        }
    23250                                }
    23251                        }
    23252                        break;
    23253                case Dataset.ARRAYFLOAT64:
    23254                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    23255                        if (is == 1) {
    23256                                if (it.isOutputDouble()) {
    23257                                        while (it.hasNext()) {
    23258                                                final double ix = it.aDouble;
    23259                                                double ox;
    23260                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23261                                                oaf64data[it.oIndex] = ox;
    23262                                        }
    23263                                } else {
    23264                                        while (it.hasNext()) {
    23265                                                final long ix = it.aLong;
    23266                                                double ox;
    23267                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23268                                                oaf64data[it.oIndex] = ox;
    23269                                        }
    23270                                }
    23271                        } else if (as == 1) {
    23272                                if (it.isOutputDouble()) {
    23273                                        while (it.hasNext()) {
    23274                                                final double ix = it.aDouble;
    23275                                                double ox;
    23276                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23277                                                for (int j = 0; j < is; j++) {
    23278                                                        oaf64data[it.oIndex + j] = ox;
    23279                                                }
    23280                                        }
    23281                                } else {
    23282                                        while (it.hasNext()) {
    23283                                                final long ix = it.aLong;
    23284                                                double ox;
    23285                                                ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23286                                                for (int j = 0; j < is; j++) {
    23287                                                        oaf64data[it.oIndex + j] = ox;
    23288                                                }
    23289                                        }
    23290                                }
    23291                        } else {
    23292                                if (it.isOutputDouble()) {
    23293                                        while (it.hasNext()) {
    23294                                                for (int j = 0; j < is; j++) {
    23295                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23296                                                        double ox;
    23297                                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23298                                                        oaf64data[it.oIndex + j] = ox;
    23299                                                }
    23300                                        }
    23301                                } else {
    23302                                        while (it.hasNext()) {
    23303                                                for (int j = 0; j < is; j++) {
    23304                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23305                                                        double ox;
    23306                                                        ox = (0.5*Math.log((1 + ix)/(1 - ix)));
    23307                                                        oaf64data[it.oIndex + j] = ox;
    23308                                                }
    23309                                        }
    23310                                }
    23311                        }
    23312                        break;
    23313                case Dataset.COMPLEX64:
    23314                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    23315                        if (as == 1) {
    23316                                final double iy = 0;
    23317                                while (it.hasNext()) {
    23318                                        final double ix = it.aDouble;
    23319                                        Complex tz;
    23320                                        float ox;
    23321                                        float oy;
    23322                                        tz = new Complex(-iy, ix).atan();
    23323                                        ox = (float) (tz.getImaginary());
    23324                                        oy = (float) (-tz.getReal());
    23325                                        oc64data[it.oIndex] = ox;
    23326                                        oc64data[it.oIndex + 1] = oy;
    23327                                }
    23328                        } else {
    23329                                while (it.hasNext()) {
    23330                                        final double ix = it.aDouble;
    23331                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    23332                                        Complex tz;
    23333                                        float ox;
    23334                                        float oy;
    23335                                        tz = new Complex(-iy, ix).atan();
    23336                                        ox = (float) (tz.getImaginary());
    23337                                        oy = (float) (-tz.getReal());
    23338                                        oc64data[it.oIndex] = ox;
    23339                                        oc64data[it.oIndex + 1] = oy;
    23340                                }
    23341                        }
    23342                        break;
    23343                case Dataset.COMPLEX128:
    23344                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    23345                        if (as == 1) {
    23346                                final double iy = 0;
    23347                                while (it.hasNext()) {
    23348                                        final double ix = it.aDouble;
    23349                                        Complex tz;
    23350                                        double ox;
    23351                                        double oy;
    23352                                        tz = new Complex(-iy, ix).atan();
    23353                                        ox = (tz.getImaginary());
    23354                                        oy = (-tz.getReal());
    23355                                        oc128data[it.oIndex] = ox;
    23356                                        oc128data[it.oIndex + 1] = oy;
    23357                                }
    23358                        } else {
    23359                                while (it.hasNext()) {
    23360                                        final double ix = it.aDouble;
    23361                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    23362                                        Complex tz;
    23363                                        double ox;
    23364                                        double oy;
    23365                                        tz = new Complex(-iy, ix).atan();
    23366                                        ox = (tz.getImaginary());
    23367                                        oy = (-tz.getReal());
    23368                                        oc128data[it.oIndex] = ox;
    23369                                        oc128data[it.oIndex + 1] = oy;
    23370                                }
    23371                        }
    23372                        break;
    23373                default:
    23374                        throw new IllegalArgumentException("arctanh supports integer, compound integer, real, compound real, complex datasets only");
    23375                }
    23376
    23377                addFunctionName(result, "arctanh");
    23378                return result;
    23379        }
    23380
    23381        /**
    23382         * log - evaluate the logarithm function on each element of the dataset
    23383         * @param a
    23384         * @return dataset
    23385         */
    23386        public static Dataset log(final Object a) {
    23387                return log(a, null);
    23388        }
    23389
    23390        /**
    23391         * log - evaluate the logarithm function on each element of the dataset
    23392         * @param a
    23393         * @param o output can be null - in which case, a new dataset is created
    23394         * @return dataset
    23395         */
    23396        public static Dataset log(final Object a, final Dataset o) {
    23397                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    23398                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    23399                final Dataset result = it.getOutput();
    23400                final int is = result.getElementsPerItem();
    23401                final int as = da.getElementsPerItem();
    23402                final int dt = result.getDType();
    23403
    23404                switch(dt) {
    23405                case Dataset.INT8:
    23406                        final byte[] oi8data = ((ByteDataset) result).getData();
    23407                        if (it.isOutputDouble()) {
    23408                                while (it.hasNext()) {
    23409                                        final double ix = it.aDouble;
    23410                                        byte ox;
    23411                                        ox = (byte) toLong(Math.log(ix));
    23412                                        oi8data[it.oIndex] = ox;
    23413                                }
    23414                        } else {
    23415                                while (it.hasNext()) {
    23416                                        final long ix = it.aLong;
    23417                                        byte ox;
    23418                                        ox = (byte) toLong(Math.log(ix));
    23419                                        oi8data[it.oIndex] = ox;
    23420                                }
    23421                        }
    23422                        break;
    23423                case Dataset.INT16:
    23424                        final short[] oi16data = ((ShortDataset) result).getData();
    23425                        if (it.isOutputDouble()) {
    23426                                while (it.hasNext()) {
    23427                                        final double ix = it.aDouble;
    23428                                        short ox;
    23429                                        ox = (short) toLong(Math.log(ix));
    23430                                        oi16data[it.oIndex] = ox;
    23431                                }
    23432                        } else {
    23433                                while (it.hasNext()) {
    23434                                        final long ix = it.aLong;
    23435                                        short ox;
    23436                                        ox = (short) toLong(Math.log(ix));
    23437                                        oi16data[it.oIndex] = ox;
    23438                                }
    23439                        }
    23440                        break;
    23441                case Dataset.INT64:
    23442                        final long[] oi64data = ((LongDataset) result).getData();
    23443                        if (it.isOutputDouble()) {
    23444                                while (it.hasNext()) {
    23445                                        final double ix = it.aDouble;
    23446                                        long ox;
    23447                                        ox = toLong(Math.log(ix));
    23448                                        oi64data[it.oIndex] = ox;
    23449                                }
    23450                        } else {
    23451                                while (it.hasNext()) {
    23452                                        final long ix = it.aLong;
    23453                                        long ox;
    23454                                        ox = toLong(Math.log(ix));
    23455                                        oi64data[it.oIndex] = ox;
    23456                                }
    23457                        }
    23458                        break;
    23459                case Dataset.INT32:
    23460                        final int[] oi32data = ((IntegerDataset) result).getData();
    23461                        if (it.isOutputDouble()) {
    23462                                while (it.hasNext()) {
    23463                                        final double ix = it.aDouble;
    23464                                        int ox;
    23465                                        ox = (int) toLong(Math.log(ix));
    23466                                        oi32data[it.oIndex] = ox;
    23467                                }
    23468                        } else {
    23469                                while (it.hasNext()) {
    23470                                        final long ix = it.aLong;
    23471                                        int ox;
    23472                                        ox = (int) toLong(Math.log(ix));
    23473                                        oi32data[it.oIndex] = ox;
    23474                                }
    23475                        }
    23476                        break;
    23477                case Dataset.ARRAYINT8:
    23478                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    23479                        if (is == 1) {
    23480                                if (it.isOutputDouble()) {
    23481                                        while (it.hasNext()) {
    23482                                                final double ix = it.aDouble;
    23483                                                byte ox;
    23484                                                ox = (byte) toLong(Math.log(ix));
    23485                                                oai8data[it.oIndex] = ox;
    23486                                        }
    23487                                } else {
    23488                                        while (it.hasNext()) {
    23489                                                final long ix = it.aLong;
    23490                                                byte ox;
    23491                                                ox = (byte) toLong(Math.log(ix));
    23492                                                oai8data[it.oIndex] = ox;
    23493                                        }
    23494                                }
    23495                        } else if (as == 1) {
    23496                                if (it.isOutputDouble()) {
    23497                                        while (it.hasNext()) {
    23498                                                final double ix = it.aDouble;
    23499                                                byte ox;
    23500                                                ox = (byte) toLong(Math.log(ix));
    23501                                                for (int j = 0; j < is; j++) {
    23502                                                        oai8data[it.oIndex + j] = ox;
    23503                                                }
    23504                                        }
    23505                                } else {
    23506                                        while (it.hasNext()) {
    23507                                                final long ix = it.aLong;
    23508                                                byte ox;
    23509                                                ox = (byte) toLong(Math.log(ix));
    23510                                                for (int j = 0; j < is; j++) {
    23511                                                        oai8data[it.oIndex + j] = ox;
    23512                                                }
    23513                                        }
    23514                                }
    23515                        } else {
    23516                                if (it.isOutputDouble()) {
    23517                                        while (it.hasNext()) {
    23518                                                for (int j = 0; j < is; j++) {
    23519                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23520                                                        byte ox;
    23521                                                        ox = (byte) toLong(Math.log(ix));
    23522                                                        oai8data[it.oIndex + j] = ox;
    23523                                                }
    23524                                        }
    23525                                } else {
    23526                                        while (it.hasNext()) {
    23527                                                for (int j = 0; j < is; j++) {
    23528                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23529                                                        byte ox;
    23530                                                        ox = (byte) toLong(Math.log(ix));
    23531                                                        oai8data[it.oIndex + j] = ox;
    23532                                                }
    23533                                        }
    23534                                }
    23535                        }
    23536                        break;
    23537                case Dataset.ARRAYINT16:
    23538                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    23539                        if (is == 1) {
    23540                                if (it.isOutputDouble()) {
    23541                                        while (it.hasNext()) {
    23542                                                final double ix = it.aDouble;
    23543                                                short ox;
    23544                                                ox = (short) toLong(Math.log(ix));
    23545                                                oai16data[it.oIndex] = ox;
    23546                                        }
    23547                                } else {
    23548                                        while (it.hasNext()) {
    23549                                                final long ix = it.aLong;
    23550                                                short ox;
    23551                                                ox = (short) toLong(Math.log(ix));
    23552                                                oai16data[it.oIndex] = ox;
    23553                                        }
    23554                                }
    23555                        } else if (as == 1) {
    23556                                if (it.isOutputDouble()) {
    23557                                        while (it.hasNext()) {
    23558                                                final double ix = it.aDouble;
    23559                                                short ox;
    23560                                                ox = (short) toLong(Math.log(ix));
    23561                                                for (int j = 0; j < is; j++) {
    23562                                                        oai16data[it.oIndex + j] = ox;
    23563                                                }
    23564                                        }
    23565                                } else {
    23566                                        while (it.hasNext()) {
    23567                                                final long ix = it.aLong;
    23568                                                short ox;
    23569                                                ox = (short) toLong(Math.log(ix));
    23570                                                for (int j = 0; j < is; j++) {
    23571                                                        oai16data[it.oIndex + j] = ox;
    23572                                                }
    23573                                        }
    23574                                }
    23575                        } else {
    23576                                if (it.isOutputDouble()) {
    23577                                        while (it.hasNext()) {
    23578                                                for (int j = 0; j < is; j++) {
    23579                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23580                                                        short ox;
    23581                                                        ox = (short) toLong(Math.log(ix));
    23582                                                        oai16data[it.oIndex + j] = ox;
    23583                                                }
    23584                                        }
    23585                                } else {
    23586                                        while (it.hasNext()) {
    23587                                                for (int j = 0; j < is; j++) {
    23588                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23589                                                        short ox;
    23590                                                        ox = (short) toLong(Math.log(ix));
    23591                                                        oai16data[it.oIndex + j] = ox;
    23592                                                }
    23593                                        }
    23594                                }
    23595                        }
    23596                        break;
    23597                case Dataset.ARRAYINT64:
    23598                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    23599                        if (is == 1) {
    23600                                if (it.isOutputDouble()) {
    23601                                        while (it.hasNext()) {
    23602                                                final double ix = it.aDouble;
    23603                                                long ox;
    23604                                                ox = toLong(Math.log(ix));
    23605                                                oai64data[it.oIndex] = ox;
    23606                                        }
    23607                                } else {
    23608                                        while (it.hasNext()) {
    23609                                                final long ix = it.aLong;
    23610                                                long ox;
    23611                                                ox = toLong(Math.log(ix));
    23612                                                oai64data[it.oIndex] = ox;
    23613                                        }
    23614                                }
    23615                        } else if (as == 1) {
    23616                                if (it.isOutputDouble()) {
    23617                                        while (it.hasNext()) {
    23618                                                final double ix = it.aDouble;
    23619                                                long ox;
    23620                                                ox = toLong(Math.log(ix));
    23621                                                for (int j = 0; j < is; j++) {
    23622                                                        oai64data[it.oIndex + j] = ox;
    23623                                                }
    23624                                        }
    23625                                } else {
    23626                                        while (it.hasNext()) {
    23627                                                final long ix = it.aLong;
    23628                                                long ox;
    23629                                                ox = toLong(Math.log(ix));
    23630                                                for (int j = 0; j < is; j++) {
    23631                                                        oai64data[it.oIndex + j] = ox;
    23632                                                }
    23633                                        }
    23634                                }
    23635                        } else {
    23636                                if (it.isOutputDouble()) {
    23637                                        while (it.hasNext()) {
    23638                                                for (int j = 0; j < is; j++) {
    23639                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23640                                                        long ox;
    23641                                                        ox = toLong(Math.log(ix));
    23642                                                        oai64data[it.oIndex + j] = ox;
    23643                                                }
    23644                                        }
    23645                                } else {
    23646                                        while (it.hasNext()) {
    23647                                                for (int j = 0; j < is; j++) {
    23648                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23649                                                        long ox;
    23650                                                        ox = toLong(Math.log(ix));
    23651                                                        oai64data[it.oIndex + j] = ox;
    23652                                                }
    23653                                        }
    23654                                }
    23655                        }
    23656                        break;
    23657                case Dataset.ARRAYINT32:
    23658                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    23659                        if (is == 1) {
    23660                                if (it.isOutputDouble()) {
    23661                                        while (it.hasNext()) {
    23662                                                final double ix = it.aDouble;
    23663                                                int ox;
    23664                                                ox = (int) toLong(Math.log(ix));
    23665                                                oai32data[it.oIndex] = ox;
    23666                                        }
    23667                                } else {
    23668                                        while (it.hasNext()) {
    23669                                                final long ix = it.aLong;
    23670                                                int ox;
    23671                                                ox = (int) toLong(Math.log(ix));
    23672                                                oai32data[it.oIndex] = ox;
    23673                                        }
    23674                                }
    23675                        } else if (as == 1) {
    23676                                if (it.isOutputDouble()) {
    23677                                        while (it.hasNext()) {
    23678                                                final double ix = it.aDouble;
    23679                                                int ox;
    23680                                                ox = (int) toLong(Math.log(ix));
    23681                                                for (int j = 0; j < is; j++) {
    23682                                                        oai32data[it.oIndex + j] = ox;
    23683                                                }
    23684                                        }
    23685                                } else {
    23686                                        while (it.hasNext()) {
    23687                                                final long ix = it.aLong;
    23688                                                int ox;
    23689                                                ox = (int) toLong(Math.log(ix));
    23690                                                for (int j = 0; j < is; j++) {
    23691                                                        oai32data[it.oIndex + j] = ox;
    23692                                                }
    23693                                        }
    23694                                }
    23695                        } else {
    23696                                if (it.isOutputDouble()) {
    23697                                        while (it.hasNext()) {
    23698                                                for (int j = 0; j < is; j++) {
    23699                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23700                                                        int ox;
    23701                                                        ox = (int) toLong(Math.log(ix));
    23702                                                        oai32data[it.oIndex + j] = ox;
    23703                                                }
    23704                                        }
    23705                                } else {
    23706                                        while (it.hasNext()) {
    23707                                                for (int j = 0; j < is; j++) {
    23708                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23709                                                        int ox;
    23710                                                        ox = (int) toLong(Math.log(ix));
    23711                                                        oai32data[it.oIndex + j] = ox;
    23712                                                }
    23713                                        }
    23714                                }
    23715                        }
    23716                        break;
    23717                case Dataset.FLOAT32:
    23718                        final float[] of32data = ((FloatDataset) result).getData();
    23719                        if (it.isOutputDouble()) {
    23720                                while (it.hasNext()) {
    23721                                        final double ix = it.aDouble;
    23722                                        float ox;
    23723                                        ox = (float) (Math.log(ix));
    23724                                        of32data[it.oIndex] = ox;
    23725                                }
    23726                        } else {
    23727                                while (it.hasNext()) {
    23728                                        final long ix = it.aLong;
    23729                                        float ox;
    23730                                        ox = (float) (Math.log(ix));
    23731                                        of32data[it.oIndex] = ox;
    23732                                }
    23733                        }
    23734                        break;
    23735                case Dataset.FLOAT64:
    23736                        final double[] of64data = ((DoubleDataset) result).getData();
    23737                        if (it.isOutputDouble()) {
    23738                                while (it.hasNext()) {
    23739                                        final double ix = it.aDouble;
    23740                                        double ox;
    23741                                        ox = (Math.log(ix));
    23742                                        of64data[it.oIndex] = ox;
    23743                                }
    23744                        } else {
    23745                                while (it.hasNext()) {
    23746                                        final long ix = it.aLong;
    23747                                        double ox;
    23748                                        ox = (Math.log(ix));
    23749                                        of64data[it.oIndex] = ox;
    23750                                }
    23751                        }
    23752                        break;
    23753                case Dataset.ARRAYFLOAT32:
    23754                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    23755                        if (is == 1) {
    23756                                if (it.isOutputDouble()) {
    23757                                        while (it.hasNext()) {
    23758                                                final double ix = it.aDouble;
    23759                                                float ox;
    23760                                                ox = (float) (Math.log(ix));
    23761                                                oaf32data[it.oIndex] = ox;
    23762                                        }
    23763                                } else {
    23764                                        while (it.hasNext()) {
    23765                                                final long ix = it.aLong;
    23766                                                float ox;
    23767                                                ox = (float) (Math.log(ix));
    23768                                                oaf32data[it.oIndex] = ox;
    23769                                        }
    23770                                }
    23771                        } else if (as == 1) {
    23772                                if (it.isOutputDouble()) {
    23773                                        while (it.hasNext()) {
    23774                                                final double ix = it.aDouble;
    23775                                                float ox;
    23776                                                ox = (float) (Math.log(ix));
    23777                                                for (int j = 0; j < is; j++) {
    23778                                                        oaf32data[it.oIndex + j] = ox;
    23779                                                }
    23780                                        }
    23781                                } else {
    23782                                        while (it.hasNext()) {
    23783                                                final long ix = it.aLong;
    23784                                                float ox;
    23785                                                ox = (float) (Math.log(ix));
    23786                                                for (int j = 0; j < is; j++) {
    23787                                                        oaf32data[it.oIndex + j] = ox;
    23788                                                }
    23789                                        }
    23790                                }
    23791                        } else {
    23792                                if (it.isOutputDouble()) {
    23793                                        while (it.hasNext()) {
    23794                                                for (int j = 0; j < is; j++) {
    23795                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23796                                                        float ox;
    23797                                                        ox = (float) (Math.log(ix));
    23798                                                        oaf32data[it.oIndex + j] = ox;
    23799                                                }
    23800                                        }
    23801                                } else {
    23802                                        while (it.hasNext()) {
    23803                                                for (int j = 0; j < is; j++) {
    23804                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23805                                                        float ox;
    23806                                                        ox = (float) (Math.log(ix));
    23807                                                        oaf32data[it.oIndex + j] = ox;
    23808                                                }
    23809                                        }
    23810                                }
    23811                        }
    23812                        break;
    23813                case Dataset.ARRAYFLOAT64:
    23814                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    23815                        if (is == 1) {
    23816                                if (it.isOutputDouble()) {
    23817                                        while (it.hasNext()) {
    23818                                                final double ix = it.aDouble;
    23819                                                double ox;
    23820                                                ox = (Math.log(ix));
    23821                                                oaf64data[it.oIndex] = ox;
    23822                                        }
    23823                                } else {
    23824                                        while (it.hasNext()) {
    23825                                                final long ix = it.aLong;
    23826                                                double ox;
    23827                                                ox = (Math.log(ix));
    23828                                                oaf64data[it.oIndex] = ox;
    23829                                        }
    23830                                }
    23831                        } else if (as == 1) {
    23832                                if (it.isOutputDouble()) {
    23833                                        while (it.hasNext()) {
    23834                                                final double ix = it.aDouble;
    23835                                                double ox;
    23836                                                ox = (Math.log(ix));
    23837                                                for (int j = 0; j < is; j++) {
    23838                                                        oaf64data[it.oIndex + j] = ox;
    23839                                                }
    23840                                        }
    23841                                } else {
    23842                                        while (it.hasNext()) {
    23843                                                final long ix = it.aLong;
    23844                                                double ox;
    23845                                                ox = (Math.log(ix));
    23846                                                for (int j = 0; j < is; j++) {
    23847                                                        oaf64data[it.oIndex + j] = ox;
    23848                                                }
    23849                                        }
    23850                                }
    23851                        } else {
    23852                                if (it.isOutputDouble()) {
    23853                                        while (it.hasNext()) {
    23854                                                for (int j = 0; j < is; j++) {
    23855                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    23856                                                        double ox;
    23857                                                        ox = (Math.log(ix));
    23858                                                        oaf64data[it.oIndex + j] = ox;
    23859                                                }
    23860                                        }
    23861                                } else {
    23862                                        while (it.hasNext()) {
    23863                                                for (int j = 0; j < is; j++) {
    23864                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    23865                                                        double ox;
    23866                                                        ox = (Math.log(ix));
    23867                                                        oaf64data[it.oIndex + j] = ox;
    23868                                                }
    23869                                        }
    23870                                }
    23871                        }
    23872                        break;
    23873                case Dataset.COMPLEX64:
    23874                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    23875                        if (as == 1) {
    23876                                final double iy = 0;
    23877                                while (it.hasNext()) {
    23878                                        final double ix = it.aDouble;
    23879                                        float ox;
    23880                                        float oy;
    23881                                        ox = (float) (Math.log(Math.hypot(ix, iy)));
    23882                                        oy = (float) (Math.atan2(iy, ix));
    23883                                        oc64data[it.oIndex] = ox;
    23884                                        oc64data[it.oIndex + 1] = oy;
    23885                                }
    23886                        } else {
    23887                                while (it.hasNext()) {
    23888                                        final double ix = it.aDouble;
    23889                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    23890                                        float ox;
    23891                                        float oy;
    23892                                        ox = (float) (Math.log(Math.hypot(ix, iy)));
    23893                                        oy = (float) (Math.atan2(iy, ix));
    23894                                        oc64data[it.oIndex] = ox;
    23895                                        oc64data[it.oIndex + 1] = oy;
    23896                                }
    23897                        }
    23898                        break;
    23899                case Dataset.COMPLEX128:
    23900                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    23901                        if (as == 1) {
    23902                                final double iy = 0;
    23903                                while (it.hasNext()) {
    23904                                        final double ix = it.aDouble;
    23905                                        double ox;
    23906                                        double oy;
    23907                                        ox = (Math.log(Math.hypot(ix, iy)));
    23908                                        oy = (Math.atan2(iy, ix));
    23909                                        oc128data[it.oIndex] = ox;
    23910                                        oc128data[it.oIndex + 1] = oy;
    23911                                }
    23912                        } else {
    23913                                while (it.hasNext()) {
    23914                                        final double ix = it.aDouble;
    23915                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    23916                                        double ox;
    23917                                        double oy;
    23918                                        ox = (Math.log(Math.hypot(ix, iy)));
    23919                                        oy = (Math.atan2(iy, ix));
    23920                                        oc128data[it.oIndex] = ox;
    23921                                        oc128data[it.oIndex + 1] = oy;
    23922                                }
    23923                        }
    23924                        break;
    23925                default:
    23926                        throw new IllegalArgumentException("log supports integer, compound integer, real, compound real, complex datasets only");
    23927                }
    23928
    23929                addFunctionName(result, "log");
    23930                return result;
    23931        }
    23932
    23933        /**
    23934         * log2 - evaluate the logarithm function on each element of the dataset
    23935         * @param a
    23936         * @return dataset
    23937         */
    23938        public static Dataset log2(final Object a) {
    23939                return log2(a, null);
    23940        }
    23941
    23942        /**
    23943         * log2 - evaluate the logarithm function on each element of the dataset
    23944         * @param a
    23945         * @param o output can be null - in which case, a new dataset is created
    23946         * @return dataset
    23947         */
    23948        public static Dataset log2(final Object a, final Dataset o) {
    23949                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    23950                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    23951                final Dataset result = it.getOutput();
    23952                final int is = result.getElementsPerItem();
    23953                final int as = da.getElementsPerItem();
    23954                final int dt = result.getDType();
    23955
    23956                switch(dt) {
    23957                case Dataset.INT8:
    23958                        final byte[] oi8data = ((ByteDataset) result).getData();
    23959                        if (it.isOutputDouble()) {
    23960                                while (it.hasNext()) {
    23961                                        final double ix = it.aDouble;
    23962                                        byte ox;
    23963                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    23964                                        oi8data[it.oIndex] = ox;
    23965                                }
    23966                        } else {
    23967                                while (it.hasNext()) {
    23968                                        final long ix = it.aLong;
    23969                                        byte ox;
    23970                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    23971                                        oi8data[it.oIndex] = ox;
    23972                                }
    23973                        }
    23974                        break;
    23975                case Dataset.INT16:
    23976                        final short[] oi16data = ((ShortDataset) result).getData();
    23977                        if (it.isOutputDouble()) {
    23978                                while (it.hasNext()) {
    23979                                        final double ix = it.aDouble;
    23980                                        short ox;
    23981                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
    23982                                        oi16data[it.oIndex] = ox;
    23983                                }
    23984                        } else {
    23985                                while (it.hasNext()) {
    23986                                        final long ix = it.aLong;
    23987                                        short ox;
    23988                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
    23989                                        oi16data[it.oIndex] = ox;
    23990                                }
    23991                        }
    23992                        break;
    23993                case Dataset.INT64:
    23994                        final long[] oi64data = ((LongDataset) result).getData();
    23995                        if (it.isOutputDouble()) {
    23996                                while (it.hasNext()) {
    23997                                        final double ix = it.aDouble;
    23998                                        long ox;
    23999                                        ox = toLong(Math.log(ix)/Math.log(2.));
    24000                                        oi64data[it.oIndex] = ox;
    24001                                }
    24002                        } else {
    24003                                while (it.hasNext()) {
    24004                                        final long ix = it.aLong;
    24005                                        long ox;
    24006                                        ox = toLong(Math.log(ix)/Math.log(2.));
    24007                                        oi64data[it.oIndex] = ox;
    24008                                }
    24009                        }
    24010                        break;
    24011                case Dataset.INT32:
    24012                        final int[] oi32data = ((IntegerDataset) result).getData();
    24013                        if (it.isOutputDouble()) {
    24014                                while (it.hasNext()) {
    24015                                        final double ix = it.aDouble;
    24016                                        int ox;
    24017                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24018                                        oi32data[it.oIndex] = ox;
    24019                                }
    24020                        } else {
    24021                                while (it.hasNext()) {
    24022                                        final long ix = it.aLong;
    24023                                        int ox;
    24024                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24025                                        oi32data[it.oIndex] = ox;
    24026                                }
    24027                        }
    24028                        break;
    24029                case Dataset.ARRAYINT8:
    24030                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    24031                        if (is == 1) {
    24032                                if (it.isOutputDouble()) {
    24033                                        while (it.hasNext()) {
    24034                                                final double ix = it.aDouble;
    24035                                                byte ox;
    24036                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    24037                                                oai8data[it.oIndex] = ox;
    24038                                        }
    24039                                } else {
    24040                                        while (it.hasNext()) {
    24041                                                final long ix = it.aLong;
    24042                                                byte ox;
    24043                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    24044                                                oai8data[it.oIndex] = ox;
    24045                                        }
    24046                                }
    24047                        } else if (as == 1) {
    24048                                if (it.isOutputDouble()) {
    24049                                        while (it.hasNext()) {
    24050                                                final double ix = it.aDouble;
    24051                                                byte ox;
    24052                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    24053                                                for (int j = 0; j < is; j++) {
    24054                                                        oai8data[it.oIndex + j] = ox;
    24055                                                }
    24056                                        }
    24057                                } else {
    24058                                        while (it.hasNext()) {
    24059                                                final long ix = it.aLong;
    24060                                                byte ox;
    24061                                                ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    24062                                                for (int j = 0; j < is; j++) {
    24063                                                        oai8data[it.oIndex + j] = ox;
    24064                                                }
    24065                                        }
    24066                                }
    24067                        } else {
    24068                                if (it.isOutputDouble()) {
    24069                                        while (it.hasNext()) {
    24070                                                for (int j = 0; j < is; j++) {
    24071                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24072                                                        byte ox;
    24073                                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    24074                                                        oai8data[it.oIndex + j] = ox;
    24075                                                }
    24076                                        }
    24077                                } else {
    24078                                        while (it.hasNext()) {
    24079                                                for (int j = 0; j < is; j++) {
    24080                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24081                                                        byte ox;
    24082                                                        ox = (byte) toLong(Math.log(ix)/Math.log(2.));
    24083                                                        oai8data[it.oIndex + j] = ox;
    24084                                                }
    24085                                        }
    24086                                }
    24087                        }
    24088                        break;
    24089                case Dataset.ARRAYINT16:
    24090                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    24091                        if (is == 1) {
    24092                                if (it.isOutputDouble()) {
    24093                                        while (it.hasNext()) {
    24094                                                final double ix = it.aDouble;
    24095                                                short ox;
    24096                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
    24097                                                oai16data[it.oIndex] = ox;
    24098                                        }
    24099                                } else {
    24100                                        while (it.hasNext()) {
    24101                                                final long ix = it.aLong;
    24102                                                short ox;
    24103                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
    24104                                                oai16data[it.oIndex] = ox;
    24105                                        }
    24106                                }
    24107                        } else if (as == 1) {
    24108                                if (it.isOutputDouble()) {
    24109                                        while (it.hasNext()) {
    24110                                                final double ix = it.aDouble;
    24111                                                short ox;
    24112                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
    24113                                                for (int j = 0; j < is; j++) {
    24114                                                        oai16data[it.oIndex + j] = ox;
    24115                                                }
    24116                                        }
    24117                                } else {
    24118                                        while (it.hasNext()) {
    24119                                                final long ix = it.aLong;
    24120                                                short ox;
    24121                                                ox = (short) toLong(Math.log(ix)/Math.log(2.));
    24122                                                for (int j = 0; j < is; j++) {
    24123                                                        oai16data[it.oIndex + j] = ox;
    24124                                                }
    24125                                        }
    24126                                }
    24127                        } else {
    24128                                if (it.isOutputDouble()) {
    24129                                        while (it.hasNext()) {
    24130                                                for (int j = 0; j < is; j++) {
    24131                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24132                                                        short ox;
    24133                                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
    24134                                                        oai16data[it.oIndex + j] = ox;
    24135                                                }
    24136                                        }
    24137                                } else {
    24138                                        while (it.hasNext()) {
    24139                                                for (int j = 0; j < is; j++) {
    24140                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24141                                                        short ox;
    24142                                                        ox = (short) toLong(Math.log(ix)/Math.log(2.));
    24143                                                        oai16data[it.oIndex + j] = ox;
    24144                                                }
    24145                                        }
    24146                                }
    24147                        }
    24148                        break;
    24149                case Dataset.ARRAYINT64:
    24150                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    24151                        if (is == 1) {
    24152                                if (it.isOutputDouble()) {
    24153                                        while (it.hasNext()) {
    24154                                                final double ix = it.aDouble;
    24155                                                long ox;
    24156                                                ox = toLong(Math.log(ix)/Math.log(2.));
    24157                                                oai64data[it.oIndex] = ox;
    24158                                        }
    24159                                } else {
    24160                                        while (it.hasNext()) {
    24161                                                final long ix = it.aLong;
    24162                                                long ox;
    24163                                                ox = toLong(Math.log(ix)/Math.log(2.));
    24164                                                oai64data[it.oIndex] = ox;
    24165                                        }
    24166                                }
    24167                        } else if (as == 1) {
    24168                                if (it.isOutputDouble()) {
    24169                                        while (it.hasNext()) {
    24170                                                final double ix = it.aDouble;
    24171                                                long ox;
    24172                                                ox = toLong(Math.log(ix)/Math.log(2.));
    24173                                                for (int j = 0; j < is; j++) {
    24174                                                        oai64data[it.oIndex + j] = ox;
    24175                                                }
    24176                                        }
    24177                                } else {
    24178                                        while (it.hasNext()) {
    24179                                                final long ix = it.aLong;
    24180                                                long ox;
    24181                                                ox = toLong(Math.log(ix)/Math.log(2.));
    24182                                                for (int j = 0; j < is; j++) {
    24183                                                        oai64data[it.oIndex + j] = ox;
    24184                                                }
    24185                                        }
    24186                                }
    24187                        } else {
    24188                                if (it.isOutputDouble()) {
    24189                                        while (it.hasNext()) {
    24190                                                for (int j = 0; j < is; j++) {
    24191                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24192                                                        long ox;
    24193                                                        ox = toLong(Math.log(ix)/Math.log(2.));
    24194                                                        oai64data[it.oIndex + j] = ox;
    24195                                                }
    24196                                        }
    24197                                } else {
    24198                                        while (it.hasNext()) {
    24199                                                for (int j = 0; j < is; j++) {
    24200                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24201                                                        long ox;
    24202                                                        ox = toLong(Math.log(ix)/Math.log(2.));
    24203                                                        oai64data[it.oIndex + j] = ox;
    24204                                                }
    24205                                        }
    24206                                }
    24207                        }
    24208                        break;
    24209                case Dataset.ARRAYINT32:
    24210                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    24211                        if (is == 1) {
    24212                                if (it.isOutputDouble()) {
    24213                                        while (it.hasNext()) {
    24214                                                final double ix = it.aDouble;
    24215                                                int ox;
    24216                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24217                                                oai32data[it.oIndex] = ox;
    24218                                        }
    24219                                } else {
    24220                                        while (it.hasNext()) {
    24221                                                final long ix = it.aLong;
    24222                                                int ox;
    24223                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24224                                                oai32data[it.oIndex] = ox;
    24225                                        }
    24226                                }
    24227                        } else if (as == 1) {
    24228                                if (it.isOutputDouble()) {
    24229                                        while (it.hasNext()) {
    24230                                                final double ix = it.aDouble;
    24231                                                int ox;
    24232                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24233                                                for (int j = 0; j < is; j++) {
    24234                                                        oai32data[it.oIndex + j] = ox;
    24235                                                }
    24236                                        }
    24237                                } else {
    24238                                        while (it.hasNext()) {
    24239                                                final long ix = it.aLong;
    24240                                                int ox;
    24241                                                ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24242                                                for (int j = 0; j < is; j++) {
    24243                                                        oai32data[it.oIndex + j] = ox;
    24244                                                }
    24245                                        }
    24246                                }
    24247                        } else {
    24248                                if (it.isOutputDouble()) {
    24249                                        while (it.hasNext()) {
    24250                                                for (int j = 0; j < is; j++) {
    24251                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24252                                                        int ox;
    24253                                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24254                                                        oai32data[it.oIndex + j] = ox;
    24255                                                }
    24256                                        }
    24257                                } else {
    24258                                        while (it.hasNext()) {
    24259                                                for (int j = 0; j < is; j++) {
    24260                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24261                                                        int ox;
    24262                                                        ox = (int) toLong(Math.log(ix)/Math.log(2.));
    24263                                                        oai32data[it.oIndex + j] = ox;
    24264                                                }
    24265                                        }
    24266                                }
    24267                        }
    24268                        break;
    24269                case Dataset.FLOAT32:
    24270                        final float[] of32data = ((FloatDataset) result).getData();
    24271                        if (it.isOutputDouble()) {
    24272                                while (it.hasNext()) {
    24273                                        final double ix = it.aDouble;
    24274                                        float ox;
    24275                                        ox = (float) (Math.log(ix)/Math.log(2.));
    24276                                        of32data[it.oIndex] = ox;
    24277                                }
    24278                        } else {
    24279                                while (it.hasNext()) {
    24280                                        final long ix = it.aLong;
    24281                                        float ox;
    24282                                        ox = (float) (Math.log(ix)/Math.log(2.));
    24283                                        of32data[it.oIndex] = ox;
    24284                                }
    24285                        }
    24286                        break;
    24287                case Dataset.FLOAT64:
    24288                        final double[] of64data = ((DoubleDataset) result).getData();
    24289                        if (it.isOutputDouble()) {
    24290                                while (it.hasNext()) {
    24291                                        final double ix = it.aDouble;
    24292                                        double ox;
    24293                                        ox = (Math.log(ix)/Math.log(2.));
    24294                                        of64data[it.oIndex] = ox;
    24295                                }
    24296                        } else {
    24297                                while (it.hasNext()) {
    24298                                        final long ix = it.aLong;
    24299                                        double ox;
    24300                                        ox = (Math.log(ix)/Math.log(2.));
    24301                                        of64data[it.oIndex] = ox;
    24302                                }
    24303                        }
    24304                        break;
    24305                case Dataset.ARRAYFLOAT32:
    24306                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    24307                        if (is == 1) {
    24308                                if (it.isOutputDouble()) {
    24309                                        while (it.hasNext()) {
    24310                                                final double ix = it.aDouble;
    24311                                                float ox;
    24312                                                ox = (float) (Math.log(ix)/Math.log(2.));
    24313                                                oaf32data[it.oIndex] = ox;
    24314                                        }
    24315                                } else {
    24316                                        while (it.hasNext()) {
    24317                                                final long ix = it.aLong;
    24318                                                float ox;
    24319                                                ox = (float) (Math.log(ix)/Math.log(2.));
    24320                                                oaf32data[it.oIndex] = ox;
    24321                                        }
    24322                                }
    24323                        } else if (as == 1) {
    24324                                if (it.isOutputDouble()) {
    24325                                        while (it.hasNext()) {
    24326                                                final double ix = it.aDouble;
    24327                                                float ox;
    24328                                                ox = (float) (Math.log(ix)/Math.log(2.));
    24329                                                for (int j = 0; j < is; j++) {
    24330                                                        oaf32data[it.oIndex + j] = ox;
    24331                                                }
    24332                                        }
    24333                                } else {
    24334                                        while (it.hasNext()) {
    24335                                                final long ix = it.aLong;
    24336                                                float ox;
    24337                                                ox = (float) (Math.log(ix)/Math.log(2.));
    24338                                                for (int j = 0; j < is; j++) {
    24339                                                        oaf32data[it.oIndex + j] = ox;
    24340                                                }
    24341                                        }
    24342                                }
    24343                        } else {
    24344                                if (it.isOutputDouble()) {
    24345                                        while (it.hasNext()) {
    24346                                                for (int j = 0; j < is; j++) {
    24347                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24348                                                        float ox;
    24349                                                        ox = (float) (Math.log(ix)/Math.log(2.));
    24350                                                        oaf32data[it.oIndex + j] = ox;
    24351                                                }
    24352                                        }
    24353                                } else {
    24354                                        while (it.hasNext()) {
    24355                                                for (int j = 0; j < is; j++) {
    24356                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24357                                                        float ox;
    24358                                                        ox = (float) (Math.log(ix)/Math.log(2.));
    24359                                                        oaf32data[it.oIndex + j] = ox;
    24360                                                }
    24361                                        }
    24362                                }
    24363                        }
    24364                        break;
    24365                case Dataset.ARRAYFLOAT64:
    24366                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    24367                        if (is == 1) {
    24368                                if (it.isOutputDouble()) {
    24369                                        while (it.hasNext()) {
    24370                                                final double ix = it.aDouble;
    24371                                                double ox;
    24372                                                ox = (Math.log(ix)/Math.log(2.));
    24373                                                oaf64data[it.oIndex] = ox;
    24374                                        }
    24375                                } else {
    24376                                        while (it.hasNext()) {
    24377                                                final long ix = it.aLong;
    24378                                                double ox;
    24379                                                ox = (Math.log(ix)/Math.log(2.));
    24380                                                oaf64data[it.oIndex] = ox;
    24381                                        }
    24382                                }
    24383                        } else if (as == 1) {
    24384                                if (it.isOutputDouble()) {
    24385                                        while (it.hasNext()) {
    24386                                                final double ix = it.aDouble;
    24387                                                double ox;
    24388                                                ox = (Math.log(ix)/Math.log(2.));
    24389                                                for (int j = 0; j < is; j++) {
    24390                                                        oaf64data[it.oIndex + j] = ox;
    24391                                                }
    24392                                        }
    24393                                } else {
    24394                                        while (it.hasNext()) {
    24395                                                final long ix = it.aLong;
    24396                                                double ox;
    24397                                                ox = (Math.log(ix)/Math.log(2.));
    24398                                                for (int j = 0; j < is; j++) {
    24399                                                        oaf64data[it.oIndex + j] = ox;
    24400                                                }
    24401                                        }
    24402                                }
    24403                        } else {
    24404                                if (it.isOutputDouble()) {
    24405                                        while (it.hasNext()) {
    24406                                                for (int j = 0; j < is; j++) {
    24407                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24408                                                        double ox;
    24409                                                        ox = (Math.log(ix)/Math.log(2.));
    24410                                                        oaf64data[it.oIndex + j] = ox;
    24411                                                }
    24412                                        }
    24413                                } else {
    24414                                        while (it.hasNext()) {
    24415                                                for (int j = 0; j < is; j++) {
    24416                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24417                                                        double ox;
    24418                                                        ox = (Math.log(ix)/Math.log(2.));
    24419                                                        oaf64data[it.oIndex + j] = ox;
    24420                                                }
    24421                                        }
    24422                                }
    24423                        }
    24424                        break;
    24425                case Dataset.COMPLEX64:
    24426                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    24427                        if (as == 1) {
    24428                                final double iy = 0;
    24429                                while (it.hasNext()) {
    24430                                        final double ix = it.aDouble;
    24431                                        float ox;
    24432                                        float oy;
    24433                                        ox = (float) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
    24434                                        oy = (float) (Math.atan2(iy, ix));
    24435                                        oc64data[it.oIndex] = ox;
    24436                                        oc64data[it.oIndex + 1] = oy;
    24437                                }
    24438                        } else {
    24439                                while (it.hasNext()) {
    24440                                        final double ix = it.aDouble;
    24441                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    24442                                        float ox;
    24443                                        float oy;
    24444                                        ox = (float) (Math.log(Math.hypot(ix, iy))/Math.log(2.));
    24445                                        oy = (float) (Math.atan2(iy, ix));
    24446                                        oc64data[it.oIndex] = ox;
    24447                                        oc64data[it.oIndex + 1] = oy;
    24448                                }
    24449                        }
    24450                        break;
    24451                case Dataset.COMPLEX128:
    24452                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    24453                        if (as == 1) {
    24454                                final double iy = 0;
    24455                                while (it.hasNext()) {
    24456                                        final double ix = it.aDouble;
    24457                                        double ox;
    24458                                        double oy;
    24459                                        ox = (Math.log(Math.hypot(ix, iy))/Math.log(2.));
    24460                                        oy = (Math.atan2(iy, ix));
    24461                                        oc128data[it.oIndex] = ox;
    24462                                        oc128data[it.oIndex + 1] = oy;
    24463                                }
    24464                        } else {
    24465                                while (it.hasNext()) {
    24466                                        final double ix = it.aDouble;
    24467                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    24468                                        double ox;
    24469                                        double oy;
    24470                                        ox = (Math.log(Math.hypot(ix, iy))/Math.log(2.));
    24471                                        oy = (Math.atan2(iy, ix));
    24472                                        oc128data[it.oIndex] = ox;
    24473                                        oc128data[it.oIndex + 1] = oy;
    24474                                }
    24475                        }
    24476                        break;
    24477                default:
    24478                        throw new IllegalArgumentException("log2 supports integer, compound integer, real, compound real, complex datasets only");
    24479                }
    24480
    24481                addFunctionName(result, "log2");
    24482                return result;
    24483        }
    24484
    24485        /**
    24486         * log10 - evaluate the logarithm function on each element of the dataset
    24487         * @param a
    24488         * @return dataset
    24489         */
    24490        public static Dataset log10(final Object a) {
    24491                return log10(a, null);
    24492        }
    24493
    24494        /**
    24495         * log10 - evaluate the logarithm function on each element of the dataset
    24496         * @param a
    24497         * @param o output can be null - in which case, a new dataset is created
    24498         * @return dataset
    24499         */
    24500        public static Dataset log10(final Object a, final Dataset o) {
    24501                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    24502                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    24503                final Dataset result = it.getOutput();
    24504                final int is = result.getElementsPerItem();
    24505                final int as = da.getElementsPerItem();
    24506                final int dt = result.getDType();
    24507
    24508                switch(dt) {
    24509                case Dataset.INT8:
    24510                        final byte[] oi8data = ((ByteDataset) result).getData();
    24511                        if (it.isOutputDouble()) {
    24512                                while (it.hasNext()) {
    24513                                        final double ix = it.aDouble;
    24514                                        byte ox;
    24515                                        ox = (byte) toLong(Math.log10(ix));
    24516                                        oi8data[it.oIndex] = ox;
    24517                                }
    24518                        } else {
    24519                                while (it.hasNext()) {
    24520                                        final long ix = it.aLong;
    24521                                        byte ox;
    24522                                        ox = (byte) toLong(Math.log10(ix));
    24523                                        oi8data[it.oIndex] = ox;
    24524                                }
    24525                        }
    24526                        break;
    24527                case Dataset.INT16:
    24528                        final short[] oi16data = ((ShortDataset) result).getData();
    24529                        if (it.isOutputDouble()) {
    24530                                while (it.hasNext()) {
    24531                                        final double ix = it.aDouble;
    24532                                        short ox;
    24533                                        ox = (short) toLong(Math.log10(ix));
    24534                                        oi16data[it.oIndex] = ox;
    24535                                }
    24536                        } else {
    24537                                while (it.hasNext()) {
    24538                                        final long ix = it.aLong;
    24539                                        short ox;
    24540                                        ox = (short) toLong(Math.log10(ix));
    24541                                        oi16data[it.oIndex] = ox;
    24542                                }
    24543                        }
    24544                        break;
    24545                case Dataset.INT64:
    24546                        final long[] oi64data = ((LongDataset) result).getData();
    24547                        if (it.isOutputDouble()) {
    24548                                while (it.hasNext()) {
    24549                                        final double ix = it.aDouble;
    24550                                        long ox;
    24551                                        ox = toLong(Math.log10(ix));
    24552                                        oi64data[it.oIndex] = ox;
    24553                                }
    24554                        } else {
    24555                                while (it.hasNext()) {
    24556                                        final long ix = it.aLong;
    24557                                        long ox;
    24558                                        ox = toLong(Math.log10(ix));
    24559                                        oi64data[it.oIndex] = ox;
    24560                                }
    24561                        }
    24562                        break;
    24563                case Dataset.INT32:
    24564                        final int[] oi32data = ((IntegerDataset) result).getData();
    24565                        if (it.isOutputDouble()) {
    24566                                while (it.hasNext()) {
    24567                                        final double ix = it.aDouble;
    24568                                        int ox;
    24569                                        ox = (int) toLong(Math.log10(ix));
    24570                                        oi32data[it.oIndex] = ox;
    24571                                }
    24572                        } else {
    24573                                while (it.hasNext()) {
    24574                                        final long ix = it.aLong;
    24575                                        int ox;
    24576                                        ox = (int) toLong(Math.log10(ix));
    24577                                        oi32data[it.oIndex] = ox;
    24578                                }
    24579                        }
    24580                        break;
    24581                case Dataset.ARRAYINT8:
    24582                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    24583                        if (is == 1) {
    24584                                if (it.isOutputDouble()) {
    24585                                        while (it.hasNext()) {
    24586                                                final double ix = it.aDouble;
    24587                                                byte ox;
    24588                                                ox = (byte) toLong(Math.log10(ix));
    24589                                                oai8data[it.oIndex] = ox;
    24590                                        }
    24591                                } else {
    24592                                        while (it.hasNext()) {
    24593                                                final long ix = it.aLong;
    24594                                                byte ox;
    24595                                                ox = (byte) toLong(Math.log10(ix));
    24596                                                oai8data[it.oIndex] = ox;
    24597                                        }
    24598                                }
    24599                        } else if (as == 1) {
    24600                                if (it.isOutputDouble()) {
    24601                                        while (it.hasNext()) {
    24602                                                final double ix = it.aDouble;
    24603                                                byte ox;
    24604                                                ox = (byte) toLong(Math.log10(ix));
    24605                                                for (int j = 0; j < is; j++) {
    24606                                                        oai8data[it.oIndex + j] = ox;
    24607                                                }
    24608                                        }
    24609                                } else {
    24610                                        while (it.hasNext()) {
    24611                                                final long ix = it.aLong;
    24612                                                byte ox;
    24613                                                ox = (byte) toLong(Math.log10(ix));
    24614                                                for (int j = 0; j < is; j++) {
    24615                                                        oai8data[it.oIndex + j] = ox;
    24616                                                }
    24617                                        }
    24618                                }
    24619                        } else {
    24620                                if (it.isOutputDouble()) {
    24621                                        while (it.hasNext()) {
    24622                                                for (int j = 0; j < is; j++) {
    24623                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24624                                                        byte ox;
    24625                                                        ox = (byte) toLong(Math.log10(ix));
    24626                                                        oai8data[it.oIndex + j] = ox;
    24627                                                }
    24628                                        }
    24629                                } else {
    24630                                        while (it.hasNext()) {
    24631                                                for (int j = 0; j < is; j++) {
    24632                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24633                                                        byte ox;
    24634                                                        ox = (byte) toLong(Math.log10(ix));
    24635                                                        oai8data[it.oIndex + j] = ox;
    24636                                                }
    24637                                        }
    24638                                }
    24639                        }
    24640                        break;
    24641                case Dataset.ARRAYINT16:
    24642                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    24643                        if (is == 1) {
    24644                                if (it.isOutputDouble()) {
    24645                                        while (it.hasNext()) {
    24646                                                final double ix = it.aDouble;
    24647                                                short ox;
    24648                                                ox = (short) toLong(Math.log10(ix));
    24649                                                oai16data[it.oIndex] = ox;
    24650                                        }
    24651                                } else {
    24652                                        while (it.hasNext()) {
    24653                                                final long ix = it.aLong;
    24654                                                short ox;
    24655                                                ox = (short) toLong(Math.log10(ix));
    24656                                                oai16data[it.oIndex] = ox;
    24657                                        }
    24658                                }
    24659                        } else if (as == 1) {
    24660                                if (it.isOutputDouble()) {
    24661                                        while (it.hasNext()) {
    24662                                                final double ix = it.aDouble;
    24663                                                short ox;
    24664                                                ox = (short) toLong(Math.log10(ix));
    24665                                                for (int j = 0; j < is; j++) {
    24666                                                        oai16data[it.oIndex + j] = ox;
    24667                                                }
    24668                                        }
    24669                                } else {
    24670                                        while (it.hasNext()) {
    24671                                                final long ix = it.aLong;
    24672                                                short ox;
    24673                                                ox = (short) toLong(Math.log10(ix));
    24674                                                for (int j = 0; j < is; j++) {
    24675                                                        oai16data[it.oIndex + j] = ox;
    24676                                                }
    24677                                        }
    24678                                }
    24679                        } else {
    24680                                if (it.isOutputDouble()) {
    24681                                        while (it.hasNext()) {
    24682                                                for (int j = 0; j < is; j++) {
    24683                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24684                                                        short ox;
    24685                                                        ox = (short) toLong(Math.log10(ix));
    24686                                                        oai16data[it.oIndex + j] = ox;
    24687                                                }
    24688                                        }
    24689                                } else {
    24690                                        while (it.hasNext()) {
    24691                                                for (int j = 0; j < is; j++) {
    24692                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24693                                                        short ox;
    24694                                                        ox = (short) toLong(Math.log10(ix));
    24695                                                        oai16data[it.oIndex + j] = ox;
    24696                                                }
    24697                                        }
    24698                                }
    24699                        }
    24700                        break;
    24701                case Dataset.ARRAYINT64:
    24702                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    24703                        if (is == 1) {
    24704                                if (it.isOutputDouble()) {
    24705                                        while (it.hasNext()) {
    24706                                                final double ix = it.aDouble;
    24707                                                long ox;
    24708                                                ox = toLong(Math.log10(ix));
    24709                                                oai64data[it.oIndex] = ox;
    24710                                        }
    24711                                } else {
    24712                                        while (it.hasNext()) {
    24713                                                final long ix = it.aLong;
    24714                                                long ox;
    24715                                                ox = toLong(Math.log10(ix));
    24716                                                oai64data[it.oIndex] = ox;
    24717                                        }
    24718                                }
    24719                        } else if (as == 1) {
    24720                                if (it.isOutputDouble()) {
    24721                                        while (it.hasNext()) {
    24722                                                final double ix = it.aDouble;
    24723                                                long ox;
    24724                                                ox = toLong(Math.log10(ix));
    24725                                                for (int j = 0; j < is; j++) {
    24726                                                        oai64data[it.oIndex + j] = ox;
    24727                                                }
    24728                                        }
    24729                                } else {
    24730                                        while (it.hasNext()) {
    24731                                                final long ix = it.aLong;
    24732                                                long ox;
    24733                                                ox = toLong(Math.log10(ix));
    24734                                                for (int j = 0; j < is; j++) {
    24735                                                        oai64data[it.oIndex + j] = ox;
    24736                                                }
    24737                                        }
    24738                                }
    24739                        } else {
    24740                                if (it.isOutputDouble()) {
    24741                                        while (it.hasNext()) {
    24742                                                for (int j = 0; j < is; j++) {
    24743                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24744                                                        long ox;
    24745                                                        ox = toLong(Math.log10(ix));
    24746                                                        oai64data[it.oIndex + j] = ox;
    24747                                                }
    24748                                        }
    24749                                } else {
    24750                                        while (it.hasNext()) {
    24751                                                for (int j = 0; j < is; j++) {
    24752                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24753                                                        long ox;
    24754                                                        ox = toLong(Math.log10(ix));
    24755                                                        oai64data[it.oIndex + j] = ox;
    24756                                                }
    24757                                        }
    24758                                }
    24759                        }
    24760                        break;
    24761                case Dataset.ARRAYINT32:
    24762                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    24763                        if (is == 1) {
    24764                                if (it.isOutputDouble()) {
    24765                                        while (it.hasNext()) {
    24766                                                final double ix = it.aDouble;
    24767                                                int ox;
    24768                                                ox = (int) toLong(Math.log10(ix));
    24769                                                oai32data[it.oIndex] = ox;
    24770                                        }
    24771                                } else {
    24772                                        while (it.hasNext()) {
    24773                                                final long ix = it.aLong;
    24774                                                int ox;
    24775                                                ox = (int) toLong(Math.log10(ix));
    24776                                                oai32data[it.oIndex] = ox;
    24777                                        }
    24778                                }
    24779                        } else if (as == 1) {
    24780                                if (it.isOutputDouble()) {
    24781                                        while (it.hasNext()) {
    24782                                                final double ix = it.aDouble;
    24783                                                int ox;
    24784                                                ox = (int) toLong(Math.log10(ix));
    24785                                                for (int j = 0; j < is; j++) {
    24786                                                        oai32data[it.oIndex + j] = ox;
    24787                                                }
    24788                                        }
    24789                                } else {
    24790                                        while (it.hasNext()) {
    24791                                                final long ix = it.aLong;
    24792                                                int ox;
    24793                                                ox = (int) toLong(Math.log10(ix));
    24794                                                for (int j = 0; j < is; j++) {
    24795                                                        oai32data[it.oIndex + j] = ox;
    24796                                                }
    24797                                        }
    24798                                }
    24799                        } else {
    24800                                if (it.isOutputDouble()) {
    24801                                        while (it.hasNext()) {
    24802                                                for (int j = 0; j < is; j++) {
    24803                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24804                                                        int ox;
    24805                                                        ox = (int) toLong(Math.log10(ix));
    24806                                                        oai32data[it.oIndex + j] = ox;
    24807                                                }
    24808                                        }
    24809                                } else {
    24810                                        while (it.hasNext()) {
    24811                                                for (int j = 0; j < is; j++) {
    24812                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24813                                                        int ox;
    24814                                                        ox = (int) toLong(Math.log10(ix));
    24815                                                        oai32data[it.oIndex + j] = ox;
    24816                                                }
    24817                                        }
    24818                                }
    24819                        }
    24820                        break;
    24821                case Dataset.FLOAT32:
    24822                        final float[] of32data = ((FloatDataset) result).getData();
    24823                        if (it.isOutputDouble()) {
    24824                                while (it.hasNext()) {
    24825                                        final double ix = it.aDouble;
    24826                                        float ox;
    24827                                        ox = (float) (Math.log10(ix));
    24828                                        of32data[it.oIndex] = ox;
    24829                                }
    24830                        } else {
    24831                                while (it.hasNext()) {
    24832                                        final long ix = it.aLong;
    24833                                        float ox;
    24834                                        ox = (float) (Math.log10(ix));
    24835                                        of32data[it.oIndex] = ox;
    24836                                }
    24837                        }
    24838                        break;
    24839                case Dataset.FLOAT64:
    24840                        final double[] of64data = ((DoubleDataset) result).getData();
    24841                        if (it.isOutputDouble()) {
    24842                                while (it.hasNext()) {
    24843                                        final double ix = it.aDouble;
    24844                                        double ox;
    24845                                        ox = (Math.log10(ix));
    24846                                        of64data[it.oIndex] = ox;
    24847                                }
    24848                        } else {
    24849                                while (it.hasNext()) {
    24850                                        final long ix = it.aLong;
    24851                                        double ox;
    24852                                        ox = (Math.log10(ix));
    24853                                        of64data[it.oIndex] = ox;
    24854                                }
    24855                        }
    24856                        break;
    24857                case Dataset.ARRAYFLOAT32:
    24858                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    24859                        if (is == 1) {
    24860                                if (it.isOutputDouble()) {
    24861                                        while (it.hasNext()) {
    24862                                                final double ix = it.aDouble;
    24863                                                float ox;
    24864                                                ox = (float) (Math.log10(ix));
    24865                                                oaf32data[it.oIndex] = ox;
    24866                                        }
    24867                                } else {
    24868                                        while (it.hasNext()) {
    24869                                                final long ix = it.aLong;
    24870                                                float ox;
    24871                                                ox = (float) (Math.log10(ix));
    24872                                                oaf32data[it.oIndex] = ox;
    24873                                        }
    24874                                }
    24875                        } else if (as == 1) {
    24876                                if (it.isOutputDouble()) {
    24877                                        while (it.hasNext()) {
    24878                                                final double ix = it.aDouble;
    24879                                                float ox;
    24880                                                ox = (float) (Math.log10(ix));
    24881                                                for (int j = 0; j < is; j++) {
    24882                                                        oaf32data[it.oIndex + j] = ox;
    24883                                                }
    24884                                        }
    24885                                } else {
    24886                                        while (it.hasNext()) {
    24887                                                final long ix = it.aLong;
    24888                                                float ox;
    24889                                                ox = (float) (Math.log10(ix));
    24890                                                for (int j = 0; j < is; j++) {
    24891                                                        oaf32data[it.oIndex + j] = ox;
    24892                                                }
    24893                                        }
    24894                                }
    24895                        } else {
    24896                                if (it.isOutputDouble()) {
    24897                                        while (it.hasNext()) {
    24898                                                for (int j = 0; j < is; j++) {
    24899                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24900                                                        float ox;
    24901                                                        ox = (float) (Math.log10(ix));
    24902                                                        oaf32data[it.oIndex + j] = ox;
    24903                                                }
    24904                                        }
    24905                                } else {
    24906                                        while (it.hasNext()) {
    24907                                                for (int j = 0; j < is; j++) {
    24908                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24909                                                        float ox;
    24910                                                        ox = (float) (Math.log10(ix));
    24911                                                        oaf32data[it.oIndex + j] = ox;
    24912                                                }
    24913                                        }
    24914                                }
    24915                        }
    24916                        break;
    24917                case Dataset.ARRAYFLOAT64:
    24918                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    24919                        if (is == 1) {
    24920                                if (it.isOutputDouble()) {
    24921                                        while (it.hasNext()) {
    24922                                                final double ix = it.aDouble;
    24923                                                double ox;
    24924                                                ox = (Math.log10(ix));
    24925                                                oaf64data[it.oIndex] = ox;
    24926                                        }
    24927                                } else {
    24928                                        while (it.hasNext()) {
    24929                                                final long ix = it.aLong;
    24930                                                double ox;
    24931                                                ox = (Math.log10(ix));
    24932                                                oaf64data[it.oIndex] = ox;
    24933                                        }
    24934                                }
    24935                        } else if (as == 1) {
    24936                                if (it.isOutputDouble()) {
    24937                                        while (it.hasNext()) {
    24938                                                final double ix = it.aDouble;
    24939                                                double ox;
    24940                                                ox = (Math.log10(ix));
    24941                                                for (int j = 0; j < is; j++) {
    24942                                                        oaf64data[it.oIndex + j] = ox;
    24943                                                }
    24944                                        }
    24945                                } else {
    24946                                        while (it.hasNext()) {
    24947                                                final long ix = it.aLong;
    24948                                                double ox;
    24949                                                ox = (Math.log10(ix));
    24950                                                for (int j = 0; j < is; j++) {
    24951                                                        oaf64data[it.oIndex + j] = ox;
    24952                                                }
    24953                                        }
    24954                                }
    24955                        } else {
    24956                                if (it.isOutputDouble()) {
    24957                                        while (it.hasNext()) {
    24958                                                for (int j = 0; j < is; j++) {
    24959                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    24960                                                        double ox;
    24961                                                        ox = (Math.log10(ix));
    24962                                                        oaf64data[it.oIndex + j] = ox;
    24963                                                }
    24964                                        }
    24965                                } else {
    24966                                        while (it.hasNext()) {
    24967                                                for (int j = 0; j < is; j++) {
    24968                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    24969                                                        double ox;
    24970                                                        ox = (Math.log10(ix));
    24971                                                        oaf64data[it.oIndex + j] = ox;
    24972                                                }
    24973                                        }
    24974                                }
    24975                        }
    24976                        break;
    24977                case Dataset.COMPLEX64:
    24978                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    24979                        if (as == 1) {
    24980                                final double iy = 0;
    24981                                while (it.hasNext()) {
    24982                                        final double ix = it.aDouble;
    24983                                        float ox;
    24984                                        float oy;
    24985                                        ox = (float) (Math.log10(Math.hypot(ix, iy)));
    24986                                        oy = (float) (Math.atan2(iy, ix));
    24987                                        oc64data[it.oIndex] = ox;
    24988                                        oc64data[it.oIndex + 1] = oy;
    24989                                }
    24990                        } else {
    24991                                while (it.hasNext()) {
    24992                                        final double ix = it.aDouble;
    24993                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    24994                                        float ox;
    24995                                        float oy;
    24996                                        ox = (float) (Math.log10(Math.hypot(ix, iy)));
    24997                                        oy = (float) (Math.atan2(iy, ix));
    24998                                        oc64data[it.oIndex] = ox;
    24999                                        oc64data[it.oIndex + 1] = oy;
    25000                                }
    25001                        }
    25002                        break;
    25003                case Dataset.COMPLEX128:
    25004                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    25005                        if (as == 1) {
    25006                                final double iy = 0;
    25007                                while (it.hasNext()) {
    25008                                        final double ix = it.aDouble;
    25009                                        double ox;
    25010                                        double oy;
    25011                                        ox = (Math.log10(Math.hypot(ix, iy)));
    25012                                        oy = (Math.atan2(iy, ix));
    25013                                        oc128data[it.oIndex] = ox;
    25014                                        oc128data[it.oIndex + 1] = oy;
    25015                                }
    25016                        } else {
    25017                                while (it.hasNext()) {
    25018                                        final double ix = it.aDouble;
    25019                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    25020                                        double ox;
    25021                                        double oy;
    25022                                        ox = (Math.log10(Math.hypot(ix, iy)));
    25023                                        oy = (Math.atan2(iy, ix));
    25024                                        oc128data[it.oIndex] = ox;
    25025                                        oc128data[it.oIndex + 1] = oy;
    25026                                }
    25027                        }
    25028                        break;
    25029                default:
    25030                        throw new IllegalArgumentException("log10 supports integer, compound integer, real, compound real, complex datasets only");
    25031                }
    25032
    25033                addFunctionName(result, "log10");
    25034                return result;
    25035        }
    25036
    25037        /**
    25038         * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
    25039         * @param a
    25040         * @return dataset
    25041         */
    25042        public static Dataset log1p(final Object a) {
    25043                return log1p(a, null);
    25044        }
    25045
    25046        /**
    25047         * log1p - evaluate the logarithm function of 1 plus on each element of the dataset
    25048         * @param a
    25049         * @param o output can be null - in which case, a new dataset is created
    25050         * @return dataset
    25051         */
    25052        public static Dataset log1p(final Object a, final Dataset o) {
    25053                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    25054                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    25055                final Dataset result = it.getOutput();
    25056                final int is = result.getElementsPerItem();
    25057                final int as = da.getElementsPerItem();
    25058                final int dt = result.getDType();
    25059
    25060                switch(dt) {
    25061                case Dataset.INT8:
    25062                        final byte[] oi8data = ((ByteDataset) result).getData();
    25063                        if (it.isOutputDouble()) {
    25064                                while (it.hasNext()) {
    25065                                        final double ix = it.aDouble;
    25066                                        byte ox;
    25067                                        ox = (byte) toLong(Math.log1p(ix));
    25068                                        oi8data[it.oIndex] = ox;
    25069                                }
    25070                        } else {
    25071                                while (it.hasNext()) {
    25072                                        final long ix = it.aLong;
    25073                                        byte ox;
    25074                                        ox = (byte) toLong(Math.log1p(ix));
    25075                                        oi8data[it.oIndex] = ox;
    25076                                }
    25077                        }
    25078                        break;
    25079                case Dataset.INT16:
    25080                        final short[] oi16data = ((ShortDataset) result).getData();
    25081                        if (it.isOutputDouble()) {
    25082                                while (it.hasNext()) {
    25083                                        final double ix = it.aDouble;
    25084                                        short ox;
    25085                                        ox = (short) toLong(Math.log1p(ix));
    25086                                        oi16data[it.oIndex] = ox;
    25087                                }
    25088                        } else {
    25089                                while (it.hasNext()) {
    25090                                        final long ix = it.aLong;
    25091                                        short ox;
    25092                                        ox = (short) toLong(Math.log1p(ix));
    25093                                        oi16data[it.oIndex] = ox;
    25094                                }
    25095                        }
    25096                        break;
    25097                case Dataset.INT64:
    25098                        final long[] oi64data = ((LongDataset) result).getData();
    25099                        if (it.isOutputDouble()) {
    25100                                while (it.hasNext()) {
    25101                                        final double ix = it.aDouble;
    25102                                        long ox;
    25103                                        ox = toLong(Math.log1p(ix));
    25104                                        oi64data[it.oIndex] = ox;
    25105                                }
    25106                        } else {
    25107                                while (it.hasNext()) {
    25108                                        final long ix = it.aLong;
    25109                                        long ox;
    25110                                        ox = toLong(Math.log1p(ix));
    25111                                        oi64data[it.oIndex] = ox;
    25112                                }
    25113                        }
    25114                        break;
    25115                case Dataset.INT32:
    25116                        final int[] oi32data = ((IntegerDataset) result).getData();
    25117                        if (it.isOutputDouble()) {
    25118                                while (it.hasNext()) {
    25119                                        final double ix = it.aDouble;
    25120                                        int ox;
    25121                                        ox = (int) toLong(Math.log1p(ix));
    25122                                        oi32data[it.oIndex] = ox;
    25123                                }
    25124                        } else {
    25125                                while (it.hasNext()) {
    25126                                        final long ix = it.aLong;
    25127                                        int ox;
    25128                                        ox = (int) toLong(Math.log1p(ix));
    25129                                        oi32data[it.oIndex] = ox;
    25130                                }
    25131                        }
    25132                        break;
    25133                case Dataset.ARRAYINT8:
    25134                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    25135                        if (is == 1) {
    25136                                if (it.isOutputDouble()) {
    25137                                        while (it.hasNext()) {
    25138                                                final double ix = it.aDouble;
    25139                                                byte ox;
    25140                                                ox = (byte) toLong(Math.log1p(ix));
    25141                                                oai8data[it.oIndex] = ox;
    25142                                        }
    25143                                } else {
    25144                                        while (it.hasNext()) {
    25145                                                final long ix = it.aLong;
    25146                                                byte ox;
    25147                                                ox = (byte) toLong(Math.log1p(ix));
    25148                                                oai8data[it.oIndex] = ox;
    25149                                        }
    25150                                }
    25151                        } else if (as == 1) {
    25152                                if (it.isOutputDouble()) {
    25153                                        while (it.hasNext()) {
    25154                                                final double ix = it.aDouble;
    25155                                                byte ox;
    25156                                                ox = (byte) toLong(Math.log1p(ix));
    25157                                                for (int j = 0; j < is; j++) {
    25158                                                        oai8data[it.oIndex + j] = ox;
    25159                                                }
    25160                                        }
    25161                                } else {
    25162                                        while (it.hasNext()) {
    25163                                                final long ix = it.aLong;
    25164                                                byte ox;
    25165                                                ox = (byte) toLong(Math.log1p(ix));
    25166                                                for (int j = 0; j < is; j++) {
    25167                                                        oai8data[it.oIndex + j] = ox;
    25168                                                }
    25169                                        }
    25170                                }
    25171                        } else {
    25172                                if (it.isOutputDouble()) {
    25173                                        while (it.hasNext()) {
    25174                                                for (int j = 0; j < is; j++) {
    25175                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25176                                                        byte ox;
    25177                                                        ox = (byte) toLong(Math.log1p(ix));
    25178                                                        oai8data[it.oIndex + j] = ox;
    25179                                                }
    25180                                        }
    25181                                } else {
    25182                                        while (it.hasNext()) {
    25183                                                for (int j = 0; j < is; j++) {
    25184                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25185                                                        byte ox;
    25186                                                        ox = (byte) toLong(Math.log1p(ix));
    25187                                                        oai8data[it.oIndex + j] = ox;
    25188                                                }
    25189                                        }
    25190                                }
    25191                        }
    25192                        break;
    25193                case Dataset.ARRAYINT16:
    25194                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    25195                        if (is == 1) {
    25196                                if (it.isOutputDouble()) {
    25197                                        while (it.hasNext()) {
    25198                                                final double ix = it.aDouble;
    25199                                                short ox;
    25200                                                ox = (short) toLong(Math.log1p(ix));
    25201                                                oai16data[it.oIndex] = ox;
    25202                                        }
    25203                                } else {
    25204                                        while (it.hasNext()) {
    25205                                                final long ix = it.aLong;
    25206                                                short ox;
    25207                                                ox = (short) toLong(Math.log1p(ix));
    25208                                                oai16data[it.oIndex] = ox;
    25209                                        }
    25210                                }
    25211                        } else if (as == 1) {
    25212                                if (it.isOutputDouble()) {
    25213                                        while (it.hasNext()) {
    25214                                                final double ix = it.aDouble;
    25215                                                short ox;
    25216                                                ox = (short) toLong(Math.log1p(ix));
    25217                                                for (int j = 0; j < is; j++) {
    25218                                                        oai16data[it.oIndex + j] = ox;
    25219                                                }
    25220                                        }
    25221                                } else {
    25222                                        while (it.hasNext()) {
    25223                                                final long ix = it.aLong;
    25224                                                short ox;
    25225                                                ox = (short) toLong(Math.log1p(ix));
    25226                                                for (int j = 0; j < is; j++) {
    25227                                                        oai16data[it.oIndex + j] = ox;
    25228                                                }
    25229                                        }
    25230                                }
    25231                        } else {
    25232                                if (it.isOutputDouble()) {
    25233                                        while (it.hasNext()) {
    25234                                                for (int j = 0; j < is; j++) {
    25235                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25236                                                        short ox;
    25237                                                        ox = (short) toLong(Math.log1p(ix));
    25238                                                        oai16data[it.oIndex + j] = ox;
    25239                                                }
    25240                                        }
    25241                                } else {
    25242                                        while (it.hasNext()) {
    25243                                                for (int j = 0; j < is; j++) {
    25244                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25245                                                        short ox;
    25246                                                        ox = (short) toLong(Math.log1p(ix));
    25247                                                        oai16data[it.oIndex + j] = ox;
    25248                                                }
    25249                                        }
    25250                                }
    25251                        }
    25252                        break;
    25253                case Dataset.ARRAYINT64:
    25254                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    25255                        if (is == 1) {
    25256                                if (it.isOutputDouble()) {
    25257                                        while (it.hasNext()) {
    25258                                                final double ix = it.aDouble;
    25259                                                long ox;
    25260                                                ox = toLong(Math.log1p(ix));
    25261                                                oai64data[it.oIndex] = ox;
    25262                                        }
    25263                                } else {
    25264                                        while (it.hasNext()) {
    25265                                                final long ix = it.aLong;
    25266                                                long ox;
    25267                                                ox = toLong(Math.log1p(ix));
    25268                                                oai64data[it.oIndex] = ox;
    25269                                        }
    25270                                }
    25271                        } else if (as == 1) {
    25272                                if (it.isOutputDouble()) {
    25273                                        while (it.hasNext()) {
    25274                                                final double ix = it.aDouble;
    25275                                                long ox;
    25276                                                ox = toLong(Math.log1p(ix));
    25277                                                for (int j = 0; j < is; j++) {
    25278                                                        oai64data[it.oIndex + j] = ox;
    25279                                                }
    25280                                        }
    25281                                } else {
    25282                                        while (it.hasNext()) {
    25283                                                final long ix = it.aLong;
    25284                                                long ox;
    25285                                                ox = toLong(Math.log1p(ix));
    25286                                                for (int j = 0; j < is; j++) {
    25287                                                        oai64data[it.oIndex + j] = ox;
    25288                                                }
    25289                                        }
    25290                                }
    25291                        } else {
    25292                                if (it.isOutputDouble()) {
    25293                                        while (it.hasNext()) {
    25294                                                for (int j = 0; j < is; j++) {
    25295                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25296                                                        long ox;
    25297                                                        ox = toLong(Math.log1p(ix));
    25298                                                        oai64data[it.oIndex + j] = ox;
    25299                                                }
    25300                                        }
    25301                                } else {
    25302                                        while (it.hasNext()) {
    25303                                                for (int j = 0; j < is; j++) {
    25304                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25305                                                        long ox;
    25306                                                        ox = toLong(Math.log1p(ix));
    25307                                                        oai64data[it.oIndex + j] = ox;
    25308                                                }
    25309                                        }
    25310                                }
    25311                        }
    25312                        break;
    25313                case Dataset.ARRAYINT32:
    25314                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    25315                        if (is == 1) {
    25316                                if (it.isOutputDouble()) {
    25317                                        while (it.hasNext()) {
    25318                                                final double ix = it.aDouble;
    25319                                                int ox;
    25320                                                ox = (int) toLong(Math.log1p(ix));
    25321                                                oai32data[it.oIndex] = ox;
    25322                                        }
    25323                                } else {
    25324                                        while (it.hasNext()) {
    25325                                                final long ix = it.aLong;
    25326                                                int ox;
    25327                                                ox = (int) toLong(Math.log1p(ix));
    25328                                                oai32data[it.oIndex] = ox;
    25329                                        }
    25330                                }
    25331                        } else if (as == 1) {
    25332                                if (it.isOutputDouble()) {
    25333                                        while (it.hasNext()) {
    25334                                                final double ix = it.aDouble;
    25335                                                int ox;
    25336                                                ox = (int) toLong(Math.log1p(ix));
    25337                                                for (int j = 0; j < is; j++) {
    25338                                                        oai32data[it.oIndex + j] = ox;
    25339                                                }
    25340                                        }
    25341                                } else {
    25342                                        while (it.hasNext()) {
    25343                                                final long ix = it.aLong;
    25344                                                int ox;
    25345                                                ox = (int) toLong(Math.log1p(ix));
    25346                                                for (int j = 0; j < is; j++) {
    25347                                                        oai32data[it.oIndex + j] = ox;
    25348                                                }
    25349                                        }
    25350                                }
    25351                        } else {
    25352                                if (it.isOutputDouble()) {
    25353                                        while (it.hasNext()) {
    25354                                                for (int j = 0; j < is; j++) {
    25355                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25356                                                        int ox;
    25357                                                        ox = (int) toLong(Math.log1p(ix));
    25358                                                        oai32data[it.oIndex + j] = ox;
    25359                                                }
    25360                                        }
    25361                                } else {
    25362                                        while (it.hasNext()) {
    25363                                                for (int j = 0; j < is; j++) {
    25364                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25365                                                        int ox;
    25366                                                        ox = (int) toLong(Math.log1p(ix));
    25367                                                        oai32data[it.oIndex + j] = ox;
    25368                                                }
    25369                                        }
    25370                                }
    25371                        }
    25372                        break;
    25373                case Dataset.FLOAT32:
    25374                        final float[] of32data = ((FloatDataset) result).getData();
    25375                        if (it.isOutputDouble()) {
    25376                                while (it.hasNext()) {
    25377                                        final double ix = it.aDouble;
    25378                                        float ox;
    25379                                        ox = (float) (Math.log1p(ix));
    25380                                        of32data[it.oIndex] = ox;
    25381                                }
    25382                        } else {
    25383                                while (it.hasNext()) {
    25384                                        final long ix = it.aLong;
    25385                                        float ox;
    25386                                        ox = (float) (Math.log1p(ix));
    25387                                        of32data[it.oIndex] = ox;
    25388                                }
    25389                        }
    25390                        break;
    25391                case Dataset.FLOAT64:
    25392                        final double[] of64data = ((DoubleDataset) result).getData();
    25393                        if (it.isOutputDouble()) {
    25394                                while (it.hasNext()) {
    25395                                        final double ix = it.aDouble;
    25396                                        double ox;
    25397                                        ox = (Math.log1p(ix));
    25398                                        of64data[it.oIndex] = ox;
    25399                                }
    25400                        } else {
    25401                                while (it.hasNext()) {
    25402                                        final long ix = it.aLong;
    25403                                        double ox;
    25404                                        ox = (Math.log1p(ix));
    25405                                        of64data[it.oIndex] = ox;
    25406                                }
    25407                        }
    25408                        break;
    25409                case Dataset.ARRAYFLOAT32:
    25410                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    25411                        if (is == 1) {
    25412                                if (it.isOutputDouble()) {
    25413                                        while (it.hasNext()) {
    25414                                                final double ix = it.aDouble;
    25415                                                float ox;
    25416                                                ox = (float) (Math.log1p(ix));
    25417                                                oaf32data[it.oIndex] = ox;
    25418                                        }
    25419                                } else {
    25420                                        while (it.hasNext()) {
    25421                                                final long ix = it.aLong;
    25422                                                float ox;
    25423                                                ox = (float) (Math.log1p(ix));
    25424                                                oaf32data[it.oIndex] = ox;
    25425                                        }
    25426                                }
    25427                        } else if (as == 1) {
    25428                                if (it.isOutputDouble()) {
    25429                                        while (it.hasNext()) {
    25430                                                final double ix = it.aDouble;
    25431                                                float ox;
    25432                                                ox = (float) (Math.log1p(ix));
    25433                                                for (int j = 0; j < is; j++) {
    25434                                                        oaf32data[it.oIndex + j] = ox;
    25435                                                }
    25436                                        }
    25437                                } else {
    25438                                        while (it.hasNext()) {
    25439                                                final long ix = it.aLong;
    25440                                                float ox;
    25441                                                ox = (float) (Math.log1p(ix));
    25442                                                for (int j = 0; j < is; j++) {
    25443                                                        oaf32data[it.oIndex + j] = ox;
    25444                                                }
    25445                                        }
    25446                                }
    25447                        } else {
    25448                                if (it.isOutputDouble()) {
    25449                                        while (it.hasNext()) {
    25450                                                for (int j = 0; j < is; j++) {
    25451                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25452                                                        float ox;
    25453                                                        ox = (float) (Math.log1p(ix));
    25454                                                        oaf32data[it.oIndex + j] = ox;
    25455                                                }
    25456                                        }
    25457                                } else {
    25458                                        while (it.hasNext()) {
    25459                                                for (int j = 0; j < is; j++) {
    25460                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25461                                                        float ox;
    25462                                                        ox = (float) (Math.log1p(ix));
    25463                                                        oaf32data[it.oIndex + j] = ox;
    25464                                                }
    25465                                        }
    25466                                }
    25467                        }
    25468                        break;
    25469                case Dataset.ARRAYFLOAT64:
    25470                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    25471                        if (is == 1) {
    25472                                if (it.isOutputDouble()) {
    25473                                        while (it.hasNext()) {
    25474                                                final double ix = it.aDouble;
    25475                                                double ox;
    25476                                                ox = (Math.log1p(ix));
    25477                                                oaf64data[it.oIndex] = ox;
    25478                                        }
    25479                                } else {
    25480                                        while (it.hasNext()) {
    25481                                                final long ix = it.aLong;
    25482                                                double ox;
    25483                                                ox = (Math.log1p(ix));
    25484                                                oaf64data[it.oIndex] = ox;
    25485                                        }
    25486                                }
    25487                        } else if (as == 1) {
    25488                                if (it.isOutputDouble()) {
    25489                                        while (it.hasNext()) {
    25490                                                final double ix = it.aDouble;
    25491                                                double ox;
    25492                                                ox = (Math.log1p(ix));
    25493                                                for (int j = 0; j < is; j++) {
    25494                                                        oaf64data[it.oIndex + j] = ox;
    25495                                                }
    25496                                        }
    25497                                } else {
    25498                                        while (it.hasNext()) {
    25499                                                final long ix = it.aLong;
    25500                                                double ox;
    25501                                                ox = (Math.log1p(ix));
    25502                                                for (int j = 0; j < is; j++) {
    25503                                                        oaf64data[it.oIndex + j] = ox;
    25504                                                }
    25505                                        }
    25506                                }
    25507                        } else {
    25508                                if (it.isOutputDouble()) {
    25509                                        while (it.hasNext()) {
    25510                                                for (int j = 0; j < is; j++) {
    25511                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25512                                                        double ox;
    25513                                                        ox = (Math.log1p(ix));
    25514                                                        oaf64data[it.oIndex + j] = ox;
    25515                                                }
    25516                                        }
    25517                                } else {
    25518                                        while (it.hasNext()) {
    25519                                                for (int j = 0; j < is; j++) {
    25520                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25521                                                        double ox;
    25522                                                        ox = (Math.log1p(ix));
    25523                                                        oaf64data[it.oIndex + j] = ox;
    25524                                                }
    25525                                        }
    25526                                }
    25527                        }
    25528                        break;
    25529                case Dataset.COMPLEX64:
    25530                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    25531                        if (as == 1) {
    25532                                final double iy = 0;
    25533                                while (it.hasNext()) {
    25534                                        final double ix = it.aDouble;
    25535                                        float ox;
    25536                                        float oy;
    25537                                        ox = (float) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
    25538                                        oy = (float) (Math.atan2(iy, ix+1));
    25539                                        oc64data[it.oIndex] = ox;
    25540                                        oc64data[it.oIndex + 1] = oy;
    25541                                }
    25542                        } else {
    25543                                while (it.hasNext()) {
    25544                                        final double ix = it.aDouble;
    25545                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    25546                                        float ox;
    25547                                        float oy;
    25548                                        ox = (float) (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
    25549                                        oy = (float) (Math.atan2(iy, ix+1));
    25550                                        oc64data[it.oIndex] = ox;
    25551                                        oc64data[it.oIndex + 1] = oy;
    25552                                }
    25553                        }
    25554                        break;
    25555                case Dataset.COMPLEX128:
    25556                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    25557                        if (as == 1) {
    25558                                final double iy = 0;
    25559                                while (it.hasNext()) {
    25560                                        final double ix = it.aDouble;
    25561                                        double ox;
    25562                                        double oy;
    25563                                        ox = (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
    25564                                        oy = (Math.atan2(iy, ix+1));
    25565                                        oc128data[it.oIndex] = ox;
    25566                                        oc128data[it.oIndex + 1] = oy;
    25567                                }
    25568                        } else {
    25569                                while (it.hasNext()) {
    25570                                        final double ix = it.aDouble;
    25571                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    25572                                        double ox;
    25573                                        double oy;
    25574                                        ox = (0.5*Math.log1p(ix*ix + 2.*ix + iy*iy));
    25575                                        oy = (Math.atan2(iy, ix+1));
    25576                                        oc128data[it.oIndex] = ox;
    25577                                        oc128data[it.oIndex + 1] = oy;
    25578                                }
    25579                        }
    25580                        break;
    25581                default:
    25582                        throw new IllegalArgumentException("log1p supports integer, compound integer, real, compound real, complex datasets only");
    25583                }
    25584
    25585                addFunctionName(result, "log1p");
    25586                return result;
    25587        }
    25588
    25589        /**
    25590         * exp - evaluate the exponential function on each element of the dataset
    25591         * @param a
    25592         * @return dataset
    25593         */
    25594        public static Dataset exp(final Object a) {
    25595                return exp(a, null);
    25596        }
    25597
    25598        /**
    25599         * exp - evaluate the exponential function on each element of the dataset
    25600         * @param a
    25601         * @param o output can be null - in which case, a new dataset is created
    25602         * @return dataset
    25603         */
    25604        public static Dataset exp(final Object a, final Dataset o) {
    25605                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    25606                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    25607                final Dataset result = it.getOutput();
    25608                final int is = result.getElementsPerItem();
    25609                final int as = da.getElementsPerItem();
    25610                final int dt = result.getDType();
    25611
    25612                switch(dt) {
    25613                case Dataset.INT8:
    25614                        final byte[] oi8data = ((ByteDataset) result).getData();
    25615                        if (it.isOutputDouble()) {
    25616                                while (it.hasNext()) {
    25617                                        final double ix = it.aDouble;
    25618                                        byte ox;
    25619                                        ox = (byte) toLong(Math.exp(ix));
    25620                                        oi8data[it.oIndex] = ox;
    25621                                }
    25622                        } else {
    25623                                while (it.hasNext()) {
    25624                                        final long ix = it.aLong;
    25625                                        byte ox;
    25626                                        ox = (byte) toLong(Math.exp(ix));
    25627                                        oi8data[it.oIndex] = ox;
    25628                                }
    25629                        }
    25630                        break;
    25631                case Dataset.INT16:
    25632                        final short[] oi16data = ((ShortDataset) result).getData();
    25633                        if (it.isOutputDouble()) {
    25634                                while (it.hasNext()) {
    25635                                        final double ix = it.aDouble;
    25636                                        short ox;
    25637                                        ox = (short) toLong(Math.exp(ix));
    25638                                        oi16data[it.oIndex] = ox;
    25639                                }
    25640                        } else {
    25641                                while (it.hasNext()) {
    25642                                        final long ix = it.aLong;
    25643                                        short ox;
    25644                                        ox = (short) toLong(Math.exp(ix));
    25645                                        oi16data[it.oIndex] = ox;
    25646                                }
    25647                        }
    25648                        break;
    25649                case Dataset.INT64:
    25650                        final long[] oi64data = ((LongDataset) result).getData();
    25651                        if (it.isOutputDouble()) {
    25652                                while (it.hasNext()) {
    25653                                        final double ix = it.aDouble;
    25654                                        long ox;
    25655                                        ox = toLong(Math.exp(ix));
    25656                                        oi64data[it.oIndex] = ox;
    25657                                }
    25658                        } else {
    25659                                while (it.hasNext()) {
    25660                                        final long ix = it.aLong;
    25661                                        long ox;
    25662                                        ox = toLong(Math.exp(ix));
    25663                                        oi64data[it.oIndex] = ox;
    25664                                }
    25665                        }
    25666                        break;
    25667                case Dataset.INT32:
    25668                        final int[] oi32data = ((IntegerDataset) result).getData();
    25669                        if (it.isOutputDouble()) {
    25670                                while (it.hasNext()) {
    25671                                        final double ix = it.aDouble;
    25672                                        int ox;
    25673                                        ox = (int) toLong(Math.exp(ix));
    25674                                        oi32data[it.oIndex] = ox;
    25675                                }
    25676                        } else {
    25677                                while (it.hasNext()) {
    25678                                        final long ix = it.aLong;
    25679                                        int ox;
    25680                                        ox = (int) toLong(Math.exp(ix));
    25681                                        oi32data[it.oIndex] = ox;
    25682                                }
    25683                        }
    25684                        break;
    25685                case Dataset.ARRAYINT8:
    25686                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    25687                        if (is == 1) {
    25688                                if (it.isOutputDouble()) {
    25689                                        while (it.hasNext()) {
    25690                                                final double ix = it.aDouble;
    25691                                                byte ox;
    25692                                                ox = (byte) toLong(Math.exp(ix));
    25693                                                oai8data[it.oIndex] = ox;
    25694                                        }
    25695                                } else {
    25696                                        while (it.hasNext()) {
    25697                                                final long ix = it.aLong;
    25698                                                byte ox;
    25699                                                ox = (byte) toLong(Math.exp(ix));
    25700                                                oai8data[it.oIndex] = ox;
    25701                                        }
    25702                                }
    25703                        } else if (as == 1) {
    25704                                if (it.isOutputDouble()) {
    25705                                        while (it.hasNext()) {
    25706                                                final double ix = it.aDouble;
    25707                                                byte ox;
    25708                                                ox = (byte) toLong(Math.exp(ix));
    25709                                                for (int j = 0; j < is; j++) {
    25710                                                        oai8data[it.oIndex + j] = ox;
    25711                                                }
    25712                                        }
    25713                                } else {
    25714                                        while (it.hasNext()) {
    25715                                                final long ix = it.aLong;
    25716                                                byte ox;
    25717                                                ox = (byte) toLong(Math.exp(ix));
    25718                                                for (int j = 0; j < is; j++) {
    25719                                                        oai8data[it.oIndex + j] = ox;
    25720                                                }
    25721                                        }
    25722                                }
    25723                        } else {
    25724                                if (it.isOutputDouble()) {
    25725                                        while (it.hasNext()) {
    25726                                                for (int j = 0; j < is; j++) {
    25727                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25728                                                        byte ox;
    25729                                                        ox = (byte) toLong(Math.exp(ix));
    25730                                                        oai8data[it.oIndex + j] = ox;
    25731                                                }
    25732                                        }
    25733                                } else {
    25734                                        while (it.hasNext()) {
    25735                                                for (int j = 0; j < is; j++) {
    25736                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25737                                                        byte ox;
    25738                                                        ox = (byte) toLong(Math.exp(ix));
    25739                                                        oai8data[it.oIndex + j] = ox;
    25740                                                }
    25741                                        }
    25742                                }
    25743                        }
    25744                        break;
    25745                case Dataset.ARRAYINT16:
    25746                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    25747                        if (is == 1) {
    25748                                if (it.isOutputDouble()) {
    25749                                        while (it.hasNext()) {
    25750                                                final double ix = it.aDouble;
    25751                                                short ox;
    25752                                                ox = (short) toLong(Math.exp(ix));
    25753                                                oai16data[it.oIndex] = ox;
    25754                                        }
    25755                                } else {
    25756                                        while (it.hasNext()) {
    25757                                                final long ix = it.aLong;
    25758                                                short ox;
    25759                                                ox = (short) toLong(Math.exp(ix));
    25760                                                oai16data[it.oIndex] = ox;
    25761                                        }
    25762                                }
    25763                        } else if (as == 1) {
    25764                                if (it.isOutputDouble()) {
    25765                                        while (it.hasNext()) {
    25766                                                final double ix = it.aDouble;
    25767                                                short ox;
    25768                                                ox = (short) toLong(Math.exp(ix));
    25769                                                for (int j = 0; j < is; j++) {
    25770                                                        oai16data[it.oIndex + j] = ox;
    25771                                                }
    25772                                        }
    25773                                } else {
    25774                                        while (it.hasNext()) {
    25775                                                final long ix = it.aLong;
    25776                                                short ox;
    25777                                                ox = (short) toLong(Math.exp(ix));
    25778                                                for (int j = 0; j < is; j++) {
    25779                                                        oai16data[it.oIndex + j] = ox;
    25780                                                }
    25781                                        }
    25782                                }
    25783                        } else {
    25784                                if (it.isOutputDouble()) {
    25785                                        while (it.hasNext()) {
    25786                                                for (int j = 0; j < is; j++) {
    25787                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25788                                                        short ox;
    25789                                                        ox = (short) toLong(Math.exp(ix));
    25790                                                        oai16data[it.oIndex + j] = ox;
    25791                                                }
    25792                                        }
    25793                                } else {
    25794                                        while (it.hasNext()) {
    25795                                                for (int j = 0; j < is; j++) {
    25796                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25797                                                        short ox;
    25798                                                        ox = (short) toLong(Math.exp(ix));
    25799                                                        oai16data[it.oIndex + j] = ox;
    25800                                                }
    25801                                        }
    25802                                }
    25803                        }
    25804                        break;
    25805                case Dataset.ARRAYINT64:
    25806                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    25807                        if (is == 1) {
    25808                                if (it.isOutputDouble()) {
    25809                                        while (it.hasNext()) {
    25810                                                final double ix = it.aDouble;
    25811                                                long ox;
    25812                                                ox = toLong(Math.exp(ix));
    25813                                                oai64data[it.oIndex] = ox;
    25814                                        }
    25815                                } else {
    25816                                        while (it.hasNext()) {
    25817                                                final long ix = it.aLong;
    25818                                                long ox;
    25819                                                ox = toLong(Math.exp(ix));
    25820                                                oai64data[it.oIndex] = ox;
    25821                                        }
    25822                                }
    25823                        } else if (as == 1) {
    25824                                if (it.isOutputDouble()) {
    25825                                        while (it.hasNext()) {
    25826                                                final double ix = it.aDouble;
    25827                                                long ox;
    25828                                                ox = toLong(Math.exp(ix));
    25829                                                for (int j = 0; j < is; j++) {
    25830                                                        oai64data[it.oIndex + j] = ox;
    25831                                                }
    25832                                        }
    25833                                } else {
    25834                                        while (it.hasNext()) {
    25835                                                final long ix = it.aLong;
    25836                                                long ox;
    25837                                                ox = toLong(Math.exp(ix));
    25838                                                for (int j = 0; j < is; j++) {
    25839                                                        oai64data[it.oIndex + j] = ox;
    25840                                                }
    25841                                        }
    25842                                }
    25843                        } else {
    25844                                if (it.isOutputDouble()) {
    25845                                        while (it.hasNext()) {
    25846                                                for (int j = 0; j < is; j++) {
    25847                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25848                                                        long ox;
    25849                                                        ox = toLong(Math.exp(ix));
    25850                                                        oai64data[it.oIndex + j] = ox;
    25851                                                }
    25852                                        }
    25853                                } else {
    25854                                        while (it.hasNext()) {
    25855                                                for (int j = 0; j < is; j++) {
    25856                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25857                                                        long ox;
    25858                                                        ox = toLong(Math.exp(ix));
    25859                                                        oai64data[it.oIndex + j] = ox;
    25860                                                }
    25861                                        }
    25862                                }
    25863                        }
    25864                        break;
    25865                case Dataset.ARRAYINT32:
    25866                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    25867                        if (is == 1) {
    25868                                if (it.isOutputDouble()) {
    25869                                        while (it.hasNext()) {
    25870                                                final double ix = it.aDouble;
    25871                                                int ox;
    25872                                                ox = (int) toLong(Math.exp(ix));
    25873                                                oai32data[it.oIndex] = ox;
    25874                                        }
    25875                                } else {
    25876                                        while (it.hasNext()) {
    25877                                                final long ix = it.aLong;
    25878                                                int ox;
    25879                                                ox = (int) toLong(Math.exp(ix));
    25880                                                oai32data[it.oIndex] = ox;
    25881                                        }
    25882                                }
    25883                        } else if (as == 1) {
    25884                                if (it.isOutputDouble()) {
    25885                                        while (it.hasNext()) {
    25886                                                final double ix = it.aDouble;
    25887                                                int ox;
    25888                                                ox = (int) toLong(Math.exp(ix));
    25889                                                for (int j = 0; j < is; j++) {
    25890                                                        oai32data[it.oIndex + j] = ox;
    25891                                                }
    25892                                        }
    25893                                } else {
    25894                                        while (it.hasNext()) {
    25895                                                final long ix = it.aLong;
    25896                                                int ox;
    25897                                                ox = (int) toLong(Math.exp(ix));
    25898                                                for (int j = 0; j < is; j++) {
    25899                                                        oai32data[it.oIndex + j] = ox;
    25900                                                }
    25901                                        }
    25902                                }
    25903                        } else {
    25904                                if (it.isOutputDouble()) {
    25905                                        while (it.hasNext()) {
    25906                                                for (int j = 0; j < is; j++) {
    25907                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    25908                                                        int ox;
    25909                                                        ox = (int) toLong(Math.exp(ix));
    25910                                                        oai32data[it.oIndex + j] = ox;
    25911                                                }
    25912                                        }
    25913                                } else {
    25914                                        while (it.hasNext()) {
    25915                                                for (int j = 0; j < is; j++) {
    25916                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    25917                                                        int ox;
    25918                                                        ox = (int) toLong(Math.exp(ix));
    25919                                                        oai32data[it.oIndex + j] = ox;
    25920                                                }
    25921                                        }
    25922                                }
    25923                        }
    25924                        break;
    25925                case Dataset.FLOAT32:
    25926                        final float[] of32data = ((FloatDataset) result).getData();
    25927                        if (it.isOutputDouble()) {
    25928                                while (it.hasNext()) {
    25929                                        final double ix = it.aDouble;
    25930                                        float ox;
    25931                                        ox = (float) (Math.exp(ix));
    25932                                        of32data[it.oIndex] = ox;
    25933                                }
    25934                        } else {
    25935                                while (it.hasNext()) {
    25936                                        final long ix = it.aLong;
    25937                                        float ox;
    25938                                        ox = (float) (Math.exp(ix));
    25939                                        of32data[it.oIndex] = ox;
    25940                                }
    25941                        }
    25942                        break;
    25943                case Dataset.FLOAT64:
    25944                        final double[] of64data = ((DoubleDataset) result).getData();
    25945                        if (it.isOutputDouble()) {
    25946                                while (it.hasNext()) {
    25947                                        final double ix = it.aDouble;
    25948                                        double ox;
    25949                                        ox = (Math.exp(ix));
    25950                                        of64data[it.oIndex] = ox;
    25951                                }
    25952                        } else {
    25953                                while (it.hasNext()) {
    25954                                        final long ix = it.aLong;
    25955                                        double ox;
    25956                                        ox = (Math.exp(ix));
    25957                                        of64data[it.oIndex] = ox;
    25958                                }
    25959                        }
    25960                        break;
    25961                case Dataset.ARRAYFLOAT32:
    25962                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    25963                        if (is == 1) {
    25964                                if (it.isOutputDouble()) {
    25965                                        while (it.hasNext()) {
    25966                                                final double ix = it.aDouble;
    25967                                                float ox;
    25968                                                ox = (float) (Math.exp(ix));
    25969                                                oaf32data[it.oIndex] = ox;
    25970                                        }
    25971                                } else {
    25972                                        while (it.hasNext()) {
    25973                                                final long ix = it.aLong;
    25974                                                float ox;
    25975                                                ox = (float) (Math.exp(ix));
    25976                                                oaf32data[it.oIndex] = ox;
    25977                                        }
    25978                                }
    25979                        } else if (as == 1) {
    25980                                if (it.isOutputDouble()) {
    25981                                        while (it.hasNext()) {
    25982                                                final double ix = it.aDouble;
    25983                                                float ox;
    25984                                                ox = (float) (Math.exp(ix));
    25985                                                for (int j = 0; j < is; j++) {
    25986                                                        oaf32data[it.oIndex + j] = ox;
    25987                                                }
    25988                                        }
    25989                                } else {
    25990                                        while (it.hasNext()) {
    25991                                                final long ix = it.aLong;
    25992                                                float ox;
    25993                                                ox = (float) (Math.exp(ix));
    25994                                                for (int j = 0; j < is; j++) {
    25995                                                        oaf32data[it.oIndex + j] = ox;
    25996                                                }
    25997                                        }
    25998                                }
    25999                        } else {
    26000                                if (it.isOutputDouble()) {
    26001                                        while (it.hasNext()) {
    26002                                                for (int j = 0; j < is; j++) {
    26003                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26004                                                        float ox;
    26005                                                        ox = (float) (Math.exp(ix));
    26006                                                        oaf32data[it.oIndex + j] = ox;
    26007                                                }
    26008                                        }
    26009                                } else {
    26010                                        while (it.hasNext()) {
    26011                                                for (int j = 0; j < is; j++) {
    26012                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26013                                                        float ox;
    26014                                                        ox = (float) (Math.exp(ix));
    26015                                                        oaf32data[it.oIndex + j] = ox;
    26016                                                }
    26017                                        }
    26018                                }
    26019                        }
    26020                        break;
    26021                case Dataset.ARRAYFLOAT64:
    26022                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    26023                        if (is == 1) {
    26024                                if (it.isOutputDouble()) {
    26025                                        while (it.hasNext()) {
    26026                                                final double ix = it.aDouble;
    26027                                                double ox;
    26028                                                ox = (Math.exp(ix));
    26029                                                oaf64data[it.oIndex] = ox;
    26030                                        }
    26031                                } else {
    26032                                        while (it.hasNext()) {
    26033                                                final long ix = it.aLong;
    26034                                                double ox;
    26035                                                ox = (Math.exp(ix));
    26036                                                oaf64data[it.oIndex] = ox;
    26037                                        }
    26038                                }
    26039                        } else if (as == 1) {
    26040                                if (it.isOutputDouble()) {
    26041                                        while (it.hasNext()) {
    26042                                                final double ix = it.aDouble;
    26043                                                double ox;
    26044                                                ox = (Math.exp(ix));
    26045                                                for (int j = 0; j < is; j++) {
    26046                                                        oaf64data[it.oIndex + j] = ox;
    26047                                                }
    26048                                        }
    26049                                } else {
    26050                                        while (it.hasNext()) {
    26051                                                final long ix = it.aLong;
    26052                                                double ox;
    26053                                                ox = (Math.exp(ix));
    26054                                                for (int j = 0; j < is; j++) {
    26055                                                        oaf64data[it.oIndex + j] = ox;
    26056                                                }
    26057                                        }
    26058                                }
    26059                        } else {
    26060                                if (it.isOutputDouble()) {
    26061                                        while (it.hasNext()) {
    26062                                                for (int j = 0; j < is; j++) {
    26063                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26064                                                        double ox;
    26065                                                        ox = (Math.exp(ix));
    26066                                                        oaf64data[it.oIndex + j] = ox;
    26067                                                }
    26068                                        }
    26069                                } else {
    26070                                        while (it.hasNext()) {
    26071                                                for (int j = 0; j < is; j++) {
    26072                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26073                                                        double ox;
    26074                                                        ox = (Math.exp(ix));
    26075                                                        oaf64data[it.oIndex + j] = ox;
    26076                                                }
    26077                                        }
    26078                                }
    26079                        }
    26080                        break;
    26081                case Dataset.COMPLEX64:
    26082                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    26083                        if (as == 1) {
    26084                                final double iy = 0;
    26085                                while (it.hasNext()) {
    26086                                        final double ix = it.aDouble;
    26087                                        float tf;
    26088                                        float ox;
    26089                                        float oy;
    26090                                        tf = (float) (Math.exp(ix));
    26091                                        ox = (float) (tf*Math.cos(iy));
    26092                                        oy = (float) (tf*Math.sin(iy));
    26093                                        oc64data[it.oIndex] = ox;
    26094                                        oc64data[it.oIndex + 1] = oy;
    26095                                }
    26096                        } else {
    26097                                while (it.hasNext()) {
    26098                                        final double ix = it.aDouble;
    26099                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    26100                                        float tf;
    26101                                        float ox;
    26102                                        float oy;
    26103                                        tf = (float) (Math.exp(ix));
    26104                                        ox = (float) (tf*Math.cos(iy));
    26105                                        oy = (float) (tf*Math.sin(iy));
    26106                                        oc64data[it.oIndex] = ox;
    26107                                        oc64data[it.oIndex + 1] = oy;
    26108                                }
    26109                        }
    26110                        break;
    26111                case Dataset.COMPLEX128:
    26112                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    26113                        if (as == 1) {
    26114                                final double iy = 0;
    26115                                while (it.hasNext()) {
    26116                                        final double ix = it.aDouble;
    26117                                        double tf;
    26118                                        double ox;
    26119                                        double oy;
    26120                                        tf = (Math.exp(ix));
    26121                                        ox = (tf*Math.cos(iy));
    26122                                        oy = (tf*Math.sin(iy));
    26123                                        oc128data[it.oIndex] = ox;
    26124                                        oc128data[it.oIndex + 1] = oy;
    26125                                }
    26126                        } else {
    26127                                while (it.hasNext()) {
    26128                                        final double ix = it.aDouble;
    26129                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    26130                                        double tf;
    26131                                        double ox;
    26132                                        double oy;
    26133                                        tf = (Math.exp(ix));
    26134                                        ox = (tf*Math.cos(iy));
    26135                                        oy = (tf*Math.sin(iy));
    26136                                        oc128data[it.oIndex] = ox;
    26137                                        oc128data[it.oIndex + 1] = oy;
    26138                                }
    26139                        }
    26140                        break;
    26141                default:
    26142                        throw new IllegalArgumentException("exp supports integer, compound integer, real, compound real, complex datasets only");
    26143                }
    26144
    26145                addFunctionName(result, "exp");
    26146                return result;
    26147        }
    26148
    26149        /**
    26150         * expm1 - evaluate the exponential function - 1 on each element of the dataset
    26151         * @param a
    26152         * @return dataset
    26153         */
    26154        public static Dataset expm1(final Object a) {
    26155                return expm1(a, null);
    26156        }
    26157
    26158        /**
    26159         * expm1 - evaluate the exponential function - 1 on each element of the dataset
    26160         * @param a
    26161         * @param o output can be null - in which case, a new dataset is created
    26162         * @return dataset
    26163         */
    26164        public static Dataset expm1(final Object a, final Dataset o) {
    26165                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    26166                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    26167                final Dataset result = it.getOutput();
    26168                final int is = result.getElementsPerItem();
    26169                final int as = da.getElementsPerItem();
    26170                final int dt = result.getDType();
    26171
    26172                switch(dt) {
    26173                case Dataset.INT8:
    26174                        final byte[] oi8data = ((ByteDataset) result).getData();
    26175                        if (it.isOutputDouble()) {
    26176                                while (it.hasNext()) {
    26177                                        final double ix = it.aDouble;
    26178                                        byte ox;
    26179                                        ox = (byte) toLong(Math.expm1(ix));
    26180                                        oi8data[it.oIndex] = ox;
    26181                                }
    26182                        } else {
    26183                                while (it.hasNext()) {
    26184                                        final long ix = it.aLong;
    26185                                        byte ox;
    26186                                        ox = (byte) toLong(Math.expm1(ix));
    26187                                        oi8data[it.oIndex] = ox;
    26188                                }
    26189                        }
    26190                        break;
    26191                case Dataset.INT16:
    26192                        final short[] oi16data = ((ShortDataset) result).getData();
    26193                        if (it.isOutputDouble()) {
    26194                                while (it.hasNext()) {
    26195                                        final double ix = it.aDouble;
    26196                                        short ox;
    26197                                        ox = (short) toLong(Math.expm1(ix));
    26198                                        oi16data[it.oIndex] = ox;
    26199                                }
    26200                        } else {
    26201                                while (it.hasNext()) {
    26202                                        final long ix = it.aLong;
    26203                                        short ox;
    26204                                        ox = (short) toLong(Math.expm1(ix));
    26205                                        oi16data[it.oIndex] = ox;
    26206                                }
    26207                        }
    26208                        break;
    26209                case Dataset.INT64:
    26210                        final long[] oi64data = ((LongDataset) result).getData();
    26211                        if (it.isOutputDouble()) {
    26212                                while (it.hasNext()) {
    26213                                        final double ix = it.aDouble;
    26214                                        long ox;
    26215                                        ox = toLong(Math.expm1(ix));
    26216                                        oi64data[it.oIndex] = ox;
    26217                                }
    26218                        } else {
    26219                                while (it.hasNext()) {
    26220                                        final long ix = it.aLong;
    26221                                        long ox;
    26222                                        ox = toLong(Math.expm1(ix));
    26223                                        oi64data[it.oIndex] = ox;
    26224                                }
    26225                        }
    26226                        break;
    26227                case Dataset.INT32:
    26228                        final int[] oi32data = ((IntegerDataset) result).getData();
    26229                        if (it.isOutputDouble()) {
    26230                                while (it.hasNext()) {
    26231                                        final double ix = it.aDouble;
    26232                                        int ox;
    26233                                        ox = (int) toLong(Math.expm1(ix));
    26234                                        oi32data[it.oIndex] = ox;
    26235                                }
    26236                        } else {
    26237                                while (it.hasNext()) {
    26238                                        final long ix = it.aLong;
    26239                                        int ox;
    26240                                        ox = (int) toLong(Math.expm1(ix));
    26241                                        oi32data[it.oIndex] = ox;
    26242                                }
    26243                        }
    26244                        break;
    26245                case Dataset.ARRAYINT8:
    26246                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    26247                        if (is == 1) {
    26248                                if (it.isOutputDouble()) {
    26249                                        while (it.hasNext()) {
    26250                                                final double ix = it.aDouble;
    26251                                                byte ox;
    26252                                                ox = (byte) toLong(Math.expm1(ix));
    26253                                                oai8data[it.oIndex] = ox;
    26254                                        }
    26255                                } else {
    26256                                        while (it.hasNext()) {
    26257                                                final long ix = it.aLong;
    26258                                                byte ox;
    26259                                                ox = (byte) toLong(Math.expm1(ix));
    26260                                                oai8data[it.oIndex] = ox;
    26261                                        }
    26262                                }
    26263                        } else if (as == 1) {
    26264                                if (it.isOutputDouble()) {
    26265                                        while (it.hasNext()) {
    26266                                                final double ix = it.aDouble;
    26267                                                byte ox;
    26268                                                ox = (byte) toLong(Math.expm1(ix));
    26269                                                for (int j = 0; j < is; j++) {
    26270                                                        oai8data[it.oIndex + j] = ox;
    26271                                                }
    26272                                        }
    26273                                } else {
    26274                                        while (it.hasNext()) {
    26275                                                final long ix = it.aLong;
    26276                                                byte ox;
    26277                                                ox = (byte) toLong(Math.expm1(ix));
    26278                                                for (int j = 0; j < is; j++) {
    26279                                                        oai8data[it.oIndex + j] = ox;
    26280                                                }
    26281                                        }
    26282                                }
    26283                        } else {
    26284                                if (it.isOutputDouble()) {
    26285                                        while (it.hasNext()) {
    26286                                                for (int j = 0; j < is; j++) {
    26287                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26288                                                        byte ox;
    26289                                                        ox = (byte) toLong(Math.expm1(ix));
    26290                                                        oai8data[it.oIndex + j] = ox;
    26291                                                }
    26292                                        }
    26293                                } else {
    26294                                        while (it.hasNext()) {
    26295                                                for (int j = 0; j < is; j++) {
    26296                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26297                                                        byte ox;
    26298                                                        ox = (byte) toLong(Math.expm1(ix));
    26299                                                        oai8data[it.oIndex + j] = ox;
    26300                                                }
    26301                                        }
    26302                                }
    26303                        }
    26304                        break;
    26305                case Dataset.ARRAYINT16:
    26306                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    26307                        if (is == 1) {
    26308                                if (it.isOutputDouble()) {
    26309                                        while (it.hasNext()) {
    26310                                                final double ix = it.aDouble;
    26311                                                short ox;
    26312                                                ox = (short) toLong(Math.expm1(ix));
    26313                                                oai16data[it.oIndex] = ox;
    26314                                        }
    26315                                } else {
    26316                                        while (it.hasNext()) {
    26317                                                final long ix = it.aLong;
    26318                                                short ox;
    26319                                                ox = (short) toLong(Math.expm1(ix));
    26320                                                oai16data[it.oIndex] = ox;
    26321                                        }
    26322                                }
    26323                        } else if (as == 1) {
    26324                                if (it.isOutputDouble()) {
    26325                                        while (it.hasNext()) {
    26326                                                final double ix = it.aDouble;
    26327                                                short ox;
    26328                                                ox = (short) toLong(Math.expm1(ix));
    26329                                                for (int j = 0; j < is; j++) {
    26330                                                        oai16data[it.oIndex + j] = ox;
    26331                                                }
    26332                                        }
    26333                                } else {
    26334                                        while (it.hasNext()) {
    26335                                                final long ix = it.aLong;
    26336                                                short ox;
    26337                                                ox = (short) toLong(Math.expm1(ix));
    26338                                                for (int j = 0; j < is; j++) {
    26339                                                        oai16data[it.oIndex + j] = ox;
    26340                                                }
    26341                                        }
    26342                                }
    26343                        } else {
    26344                                if (it.isOutputDouble()) {
    26345                                        while (it.hasNext()) {
    26346                                                for (int j = 0; j < is; j++) {
    26347                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26348                                                        short ox;
    26349                                                        ox = (short) toLong(Math.expm1(ix));
    26350                                                        oai16data[it.oIndex + j] = ox;
    26351                                                }
    26352                                        }
    26353                                } else {
    26354                                        while (it.hasNext()) {
    26355                                                for (int j = 0; j < is; j++) {
    26356                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26357                                                        short ox;
    26358                                                        ox = (short) toLong(Math.expm1(ix));
    26359                                                        oai16data[it.oIndex + j] = ox;
    26360                                                }
    26361                                        }
    26362                                }
    26363                        }
    26364                        break;
    26365                case Dataset.ARRAYINT64:
    26366                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    26367                        if (is == 1) {
    26368                                if (it.isOutputDouble()) {
    26369                                        while (it.hasNext()) {
    26370                                                final double ix = it.aDouble;
    26371                                                long ox;
    26372                                                ox = toLong(Math.expm1(ix));
    26373                                                oai64data[it.oIndex] = ox;
    26374                                        }
    26375                                } else {
    26376                                        while (it.hasNext()) {
    26377                                                final long ix = it.aLong;
    26378                                                long ox;
    26379                                                ox = toLong(Math.expm1(ix));
    26380                                                oai64data[it.oIndex] = ox;
    26381                                        }
    26382                                }
    26383                        } else if (as == 1) {
    26384                                if (it.isOutputDouble()) {
    26385                                        while (it.hasNext()) {
    26386                                                final double ix = it.aDouble;
    26387                                                long ox;
    26388                                                ox = toLong(Math.expm1(ix));
    26389                                                for (int j = 0; j < is; j++) {
    26390                                                        oai64data[it.oIndex + j] = ox;
    26391                                                }
    26392                                        }
    26393                                } else {
    26394                                        while (it.hasNext()) {
    26395                                                final long ix = it.aLong;
    26396                                                long ox;
    26397                                                ox = toLong(Math.expm1(ix));
    26398                                                for (int j = 0; j < is; j++) {
    26399                                                        oai64data[it.oIndex + j] = ox;
    26400                                                }
    26401                                        }
    26402                                }
    26403                        } else {
    26404                                if (it.isOutputDouble()) {
    26405                                        while (it.hasNext()) {
    26406                                                for (int j = 0; j < is; j++) {
    26407                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26408                                                        long ox;
    26409                                                        ox = toLong(Math.expm1(ix));
    26410                                                        oai64data[it.oIndex + j] = ox;
    26411                                                }
    26412                                        }
    26413                                } else {
    26414                                        while (it.hasNext()) {
    26415                                                for (int j = 0; j < is; j++) {
    26416                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26417                                                        long ox;
    26418                                                        ox = toLong(Math.expm1(ix));
    26419                                                        oai64data[it.oIndex + j] = ox;
    26420                                                }
    26421                                        }
    26422                                }
    26423                        }
    26424                        break;
    26425                case Dataset.ARRAYINT32:
    26426                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    26427                        if (is == 1) {
    26428                                if (it.isOutputDouble()) {
    26429                                        while (it.hasNext()) {
    26430                                                final double ix = it.aDouble;
    26431                                                int ox;
    26432                                                ox = (int) toLong(Math.expm1(ix));
    26433                                                oai32data[it.oIndex] = ox;
    26434                                        }
    26435                                } else {
    26436                                        while (it.hasNext()) {
    26437                                                final long ix = it.aLong;
    26438                                                int ox;
    26439                                                ox = (int) toLong(Math.expm1(ix));
    26440                                                oai32data[it.oIndex] = ox;
    26441                                        }
    26442                                }
    26443                        } else if (as == 1) {
    26444                                if (it.isOutputDouble()) {
    26445                                        while (it.hasNext()) {
    26446                                                final double ix = it.aDouble;
    26447                                                int ox;
    26448                                                ox = (int) toLong(Math.expm1(ix));
    26449                                                for (int j = 0; j < is; j++) {
    26450                                                        oai32data[it.oIndex + j] = ox;
    26451                                                }
    26452                                        }
    26453                                } else {
    26454                                        while (it.hasNext()) {
    26455                                                final long ix = it.aLong;
    26456                                                int ox;
    26457                                                ox = (int) toLong(Math.expm1(ix));
    26458                                                for (int j = 0; j < is; j++) {
    26459                                                        oai32data[it.oIndex + j] = ox;
    26460                                                }
    26461                                        }
    26462                                }
    26463                        } else {
    26464                                if (it.isOutputDouble()) {
    26465                                        while (it.hasNext()) {
    26466                                                for (int j = 0; j < is; j++) {
    26467                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26468                                                        int ox;
    26469                                                        ox = (int) toLong(Math.expm1(ix));
    26470                                                        oai32data[it.oIndex + j] = ox;
    26471                                                }
    26472                                        }
    26473                                } else {
    26474                                        while (it.hasNext()) {
    26475                                                for (int j = 0; j < is; j++) {
    26476                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26477                                                        int ox;
    26478                                                        ox = (int) toLong(Math.expm1(ix));
    26479                                                        oai32data[it.oIndex + j] = ox;
    26480                                                }
    26481                                        }
    26482                                }
    26483                        }
    26484                        break;
    26485                case Dataset.FLOAT32:
    26486                        final float[] of32data = ((FloatDataset) result).getData();
    26487                        if (it.isOutputDouble()) {
    26488                                while (it.hasNext()) {
    26489                                        final double ix = it.aDouble;
    26490                                        float ox;
    26491                                        ox = (float) (Math.expm1(ix));
    26492                                        of32data[it.oIndex] = ox;
    26493                                }
    26494                        } else {
    26495                                while (it.hasNext()) {
    26496                                        final long ix = it.aLong;
    26497                                        float ox;
    26498                                        ox = (float) (Math.expm1(ix));
    26499                                        of32data[it.oIndex] = ox;
    26500                                }
    26501                        }
    26502                        break;
    26503                case Dataset.FLOAT64:
    26504                        final double[] of64data = ((DoubleDataset) result).getData();
    26505                        if (it.isOutputDouble()) {
    26506                                while (it.hasNext()) {
    26507                                        final double ix = it.aDouble;
    26508                                        double ox;
    26509                                        ox = (Math.expm1(ix));
    26510                                        of64data[it.oIndex] = ox;
    26511                                }
    26512                        } else {
    26513                                while (it.hasNext()) {
    26514                                        final long ix = it.aLong;
    26515                                        double ox;
    26516                                        ox = (Math.expm1(ix));
    26517                                        of64data[it.oIndex] = ox;
    26518                                }
    26519                        }
    26520                        break;
    26521                case Dataset.ARRAYFLOAT32:
    26522                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    26523                        if (is == 1) {
    26524                                if (it.isOutputDouble()) {
    26525                                        while (it.hasNext()) {
    26526                                                final double ix = it.aDouble;
    26527                                                float ox;
    26528                                                ox = (float) (Math.expm1(ix));
    26529                                                oaf32data[it.oIndex] = ox;
    26530                                        }
    26531                                } else {
    26532                                        while (it.hasNext()) {
    26533                                                final long ix = it.aLong;
    26534                                                float ox;
    26535                                                ox = (float) (Math.expm1(ix));
    26536                                                oaf32data[it.oIndex] = ox;
    26537                                        }
    26538                                }
    26539                        } else if (as == 1) {
    26540                                if (it.isOutputDouble()) {
    26541                                        while (it.hasNext()) {
    26542                                                final double ix = it.aDouble;
    26543                                                float ox;
    26544                                                ox = (float) (Math.expm1(ix));
    26545                                                for (int j = 0; j < is; j++) {
    26546                                                        oaf32data[it.oIndex + j] = ox;
    26547                                                }
    26548                                        }
    26549                                } else {
    26550                                        while (it.hasNext()) {
    26551                                                final long ix = it.aLong;
    26552                                                float ox;
    26553                                                ox = (float) (Math.expm1(ix));
    26554                                                for (int j = 0; j < is; j++) {
    26555                                                        oaf32data[it.oIndex + j] = ox;
    26556                                                }
    26557                                        }
    26558                                }
    26559                        } else {
    26560                                if (it.isOutputDouble()) {
    26561                                        while (it.hasNext()) {
    26562                                                for (int j = 0; j < is; j++) {
    26563                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26564                                                        float ox;
    26565                                                        ox = (float) (Math.expm1(ix));
    26566                                                        oaf32data[it.oIndex + j] = ox;
    26567                                                }
    26568                                        }
    26569                                } else {
    26570                                        while (it.hasNext()) {
    26571                                                for (int j = 0; j < is; j++) {
    26572                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26573                                                        float ox;
    26574                                                        ox = (float) (Math.expm1(ix));
    26575                                                        oaf32data[it.oIndex + j] = ox;
    26576                                                }
    26577                                        }
    26578                                }
    26579                        }
    26580                        break;
    26581                case Dataset.ARRAYFLOAT64:
    26582                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    26583                        if (is == 1) {
    26584                                if (it.isOutputDouble()) {
    26585                                        while (it.hasNext()) {
    26586                                                final double ix = it.aDouble;
    26587                                                double ox;
    26588                                                ox = (Math.expm1(ix));
    26589                                                oaf64data[it.oIndex] = ox;
    26590                                        }
    26591                                } else {
    26592                                        while (it.hasNext()) {
    26593                                                final long ix = it.aLong;
    26594                                                double ox;
    26595                                                ox = (Math.expm1(ix));
    26596                                                oaf64data[it.oIndex] = ox;
    26597                                        }
    26598                                }
    26599                        } else if (as == 1) {
    26600                                if (it.isOutputDouble()) {
    26601                                        while (it.hasNext()) {
    26602                                                final double ix = it.aDouble;
    26603                                                double ox;
    26604                                                ox = (Math.expm1(ix));
    26605                                                for (int j = 0; j < is; j++) {
    26606                                                        oaf64data[it.oIndex + j] = ox;
    26607                                                }
    26608                                        }
    26609                                } else {
    26610                                        while (it.hasNext()) {
    26611                                                final long ix = it.aLong;
    26612                                                double ox;
    26613                                                ox = (Math.expm1(ix));
    26614                                                for (int j = 0; j < is; j++) {
    26615                                                        oaf64data[it.oIndex + j] = ox;
    26616                                                }
    26617                                        }
    26618                                }
    26619                        } else {
    26620                                if (it.isOutputDouble()) {
    26621                                        while (it.hasNext()) {
    26622                                                for (int j = 0; j < is; j++) {
    26623                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26624                                                        double ox;
    26625                                                        ox = (Math.expm1(ix));
    26626                                                        oaf64data[it.oIndex + j] = ox;
    26627                                                }
    26628                                        }
    26629                                } else {
    26630                                        while (it.hasNext()) {
    26631                                                for (int j = 0; j < is; j++) {
    26632                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26633                                                        double ox;
    26634                                                        ox = (Math.expm1(ix));
    26635                                                        oaf64data[it.oIndex + j] = ox;
    26636                                                }
    26637                                        }
    26638                                }
    26639                        }
    26640                        break;
    26641                case Dataset.COMPLEX64:
    26642                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    26643                        if (as == 1) {
    26644                                final double iy = 0;
    26645                                while (it.hasNext()) {
    26646                                        final double ix = it.aDouble;
    26647                                        float tf;
    26648                                        float ox;
    26649                                        float oy;
    26650                                        tf = (float) (Math.expm1(ix));
    26651                                        ox = (float) (tf*Math.cos(iy));
    26652                                        oy = (float) (tf*Math.sin(iy));
    26653                                        oc64data[it.oIndex] = ox;
    26654                                        oc64data[it.oIndex + 1] = oy;
    26655                                }
    26656                        } else {
    26657                                while (it.hasNext()) {
    26658                                        final double ix = it.aDouble;
    26659                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    26660                                        float tf;
    26661                                        float ox;
    26662                                        float oy;
    26663                                        tf = (float) (Math.expm1(ix));
    26664                                        ox = (float) (tf*Math.cos(iy));
    26665                                        oy = (float) (tf*Math.sin(iy));
    26666                                        oc64data[it.oIndex] = ox;
    26667                                        oc64data[it.oIndex + 1] = oy;
    26668                                }
    26669                        }
    26670                        break;
    26671                case Dataset.COMPLEX128:
    26672                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    26673                        if (as == 1) {
    26674                                final double iy = 0;
    26675                                while (it.hasNext()) {
    26676                                        final double ix = it.aDouble;
    26677                                        double tf;
    26678                                        double ox;
    26679                                        double oy;
    26680                                        tf = (Math.expm1(ix));
    26681                                        ox = (tf*Math.cos(iy));
    26682                                        oy = (tf*Math.sin(iy));
    26683                                        oc128data[it.oIndex] = ox;
    26684                                        oc128data[it.oIndex + 1] = oy;
    26685                                }
    26686                        } else {
    26687                                while (it.hasNext()) {
    26688                                        final double ix = it.aDouble;
    26689                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    26690                                        double tf;
    26691                                        double ox;
    26692                                        double oy;
    26693                                        tf = (Math.expm1(ix));
    26694                                        ox = (tf*Math.cos(iy));
    26695                                        oy = (tf*Math.sin(iy));
    26696                                        oc128data[it.oIndex] = ox;
    26697                                        oc128data[it.oIndex + 1] = oy;
    26698                                }
    26699                        }
    26700                        break;
    26701                default:
    26702                        throw new IllegalArgumentException("expm1 supports integer, compound integer, real, compound real, complex datasets only");
    26703                }
    26704
    26705                addFunctionName(result, "expm1");
    26706                return result;
    26707        }
    26708
    26709        /**
    26710         * sqrt - evaluate the square root function on each element of the dataset
    26711         * @param a
    26712         * @return dataset
    26713         */
    26714        public static Dataset sqrt(final Object a) {
    26715                return sqrt(a, null);
    26716        }
    26717
    26718        /**
    26719         * sqrt - evaluate the square root function on each element of the dataset
    26720         * @param a
    26721         * @param o output can be null - in which case, a new dataset is created
    26722         * @return dataset
    26723         */
    26724        public static Dataset sqrt(final Object a, final Dataset o) {
    26725                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    26726                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    26727                final Dataset result = it.getOutput();
    26728                final int is = result.getElementsPerItem();
    26729                final int as = da.getElementsPerItem();
    26730                final int dt = result.getDType();
    26731
    26732                switch(dt) {
    26733                case Dataset.INT8:
    26734                        final byte[] oi8data = ((ByteDataset) result).getData();
    26735                        if (it.isOutputDouble()) {
    26736                                while (it.hasNext()) {
    26737                                        final double ix = it.aDouble;
    26738                                        byte ox;
    26739                                        ox = (byte) toLong(Math.sqrt(ix));
    26740                                        oi8data[it.oIndex] = ox;
    26741                                }
    26742                        } else {
    26743                                while (it.hasNext()) {
    26744                                        final long ix = it.aLong;
    26745                                        byte ox;
    26746                                        ox = (byte) toLong(Math.sqrt(ix));
    26747                                        oi8data[it.oIndex] = ox;
    26748                                }
    26749                        }
    26750                        break;
    26751                case Dataset.INT16:
    26752                        final short[] oi16data = ((ShortDataset) result).getData();
    26753                        if (it.isOutputDouble()) {
    26754                                while (it.hasNext()) {
    26755                                        final double ix = it.aDouble;
    26756                                        short ox;
    26757                                        ox = (short) toLong(Math.sqrt(ix));
    26758                                        oi16data[it.oIndex] = ox;
    26759                                }
    26760                        } else {
    26761                                while (it.hasNext()) {
    26762                                        final long ix = it.aLong;
    26763                                        short ox;
    26764                                        ox = (short) toLong(Math.sqrt(ix));
    26765                                        oi16data[it.oIndex] = ox;
    26766                                }
    26767                        }
    26768                        break;
    26769                case Dataset.INT64:
    26770                        final long[] oi64data = ((LongDataset) result).getData();
    26771                        if (it.isOutputDouble()) {
    26772                                while (it.hasNext()) {
    26773                                        final double ix = it.aDouble;
    26774                                        long ox;
    26775                                        ox = toLong(Math.sqrt(ix));
    26776                                        oi64data[it.oIndex] = ox;
    26777                                }
    26778                        } else {
    26779                                while (it.hasNext()) {
    26780                                        final long ix = it.aLong;
    26781                                        long ox;
    26782                                        ox = toLong(Math.sqrt(ix));
    26783                                        oi64data[it.oIndex] = ox;
    26784                                }
    26785                        }
    26786                        break;
    26787                case Dataset.INT32:
    26788                        final int[] oi32data = ((IntegerDataset) result).getData();
    26789                        if (it.isOutputDouble()) {
    26790                                while (it.hasNext()) {
    26791                                        final double ix = it.aDouble;
    26792                                        int ox;
    26793                                        ox = (int) toLong(Math.sqrt(ix));
    26794                                        oi32data[it.oIndex] = ox;
    26795                                }
    26796                        } else {
    26797                                while (it.hasNext()) {
    26798                                        final long ix = it.aLong;
    26799                                        int ox;
    26800                                        ox = (int) toLong(Math.sqrt(ix));
    26801                                        oi32data[it.oIndex] = ox;
    26802                                }
    26803                        }
    26804                        break;
    26805                case Dataset.ARRAYINT8:
    26806                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    26807                        if (is == 1) {
    26808                                if (it.isOutputDouble()) {
    26809                                        while (it.hasNext()) {
    26810                                                final double ix = it.aDouble;
    26811                                                byte ox;
    26812                                                ox = (byte) toLong(Math.sqrt(ix));
    26813                                                oai8data[it.oIndex] = ox;
    26814                                        }
    26815                                } else {
    26816                                        while (it.hasNext()) {
    26817                                                final long ix = it.aLong;
    26818                                                byte ox;
    26819                                                ox = (byte) toLong(Math.sqrt(ix));
    26820                                                oai8data[it.oIndex] = ox;
    26821                                        }
    26822                                }
    26823                        } else if (as == 1) {
    26824                                if (it.isOutputDouble()) {
    26825                                        while (it.hasNext()) {
    26826                                                final double ix = it.aDouble;
    26827                                                byte ox;
    26828                                                ox = (byte) toLong(Math.sqrt(ix));
    26829                                                for (int j = 0; j < is; j++) {
    26830                                                        oai8data[it.oIndex + j] = ox;
    26831                                                }
    26832                                        }
    26833                                } else {
    26834                                        while (it.hasNext()) {
    26835                                                final long ix = it.aLong;
    26836                                                byte ox;
    26837                                                ox = (byte) toLong(Math.sqrt(ix));
    26838                                                for (int j = 0; j < is; j++) {
    26839                                                        oai8data[it.oIndex + j] = ox;
    26840                                                }
    26841                                        }
    26842                                }
    26843                        } else {
    26844                                if (it.isOutputDouble()) {
    26845                                        while (it.hasNext()) {
    26846                                                for (int j = 0; j < is; j++) {
    26847                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26848                                                        byte ox;
    26849                                                        ox = (byte) toLong(Math.sqrt(ix));
    26850                                                        oai8data[it.oIndex + j] = ox;
    26851                                                }
    26852                                        }
    26853                                } else {
    26854                                        while (it.hasNext()) {
    26855                                                for (int j = 0; j < is; j++) {
    26856                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26857                                                        byte ox;
    26858                                                        ox = (byte) toLong(Math.sqrt(ix));
    26859                                                        oai8data[it.oIndex + j] = ox;
    26860                                                }
    26861                                        }
    26862                                }
    26863                        }
    26864                        break;
    26865                case Dataset.ARRAYINT16:
    26866                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    26867                        if (is == 1) {
    26868                                if (it.isOutputDouble()) {
    26869                                        while (it.hasNext()) {
    26870                                                final double ix = it.aDouble;
    26871                                                short ox;
    26872                                                ox = (short) toLong(Math.sqrt(ix));
    26873                                                oai16data[it.oIndex] = ox;
    26874                                        }
    26875                                } else {
    26876                                        while (it.hasNext()) {
    26877                                                final long ix = it.aLong;
    26878                                                short ox;
    26879                                                ox = (short) toLong(Math.sqrt(ix));
    26880                                                oai16data[it.oIndex] = ox;
    26881                                        }
    26882                                }
    26883                        } else if (as == 1) {
    26884                                if (it.isOutputDouble()) {
    26885                                        while (it.hasNext()) {
    26886                                                final double ix = it.aDouble;
    26887                                                short ox;
    26888                                                ox = (short) toLong(Math.sqrt(ix));
    26889                                                for (int j = 0; j < is; j++) {
    26890                                                        oai16data[it.oIndex + j] = ox;
    26891                                                }
    26892                                        }
    26893                                } else {
    26894                                        while (it.hasNext()) {
    26895                                                final long ix = it.aLong;
    26896                                                short ox;
    26897                                                ox = (short) toLong(Math.sqrt(ix));
    26898                                                for (int j = 0; j < is; j++) {
    26899                                                        oai16data[it.oIndex + j] = ox;
    26900                                                }
    26901                                        }
    26902                                }
    26903                        } else {
    26904                                if (it.isOutputDouble()) {
    26905                                        while (it.hasNext()) {
    26906                                                for (int j = 0; j < is; j++) {
    26907                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26908                                                        short ox;
    26909                                                        ox = (short) toLong(Math.sqrt(ix));
    26910                                                        oai16data[it.oIndex + j] = ox;
    26911                                                }
    26912                                        }
    26913                                } else {
    26914                                        while (it.hasNext()) {
    26915                                                for (int j = 0; j < is; j++) {
    26916                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26917                                                        short ox;
    26918                                                        ox = (short) toLong(Math.sqrt(ix));
    26919                                                        oai16data[it.oIndex + j] = ox;
    26920                                                }
    26921                                        }
    26922                                }
    26923                        }
    26924                        break;
    26925                case Dataset.ARRAYINT64:
    26926                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    26927                        if (is == 1) {
    26928                                if (it.isOutputDouble()) {
    26929                                        while (it.hasNext()) {
    26930                                                final double ix = it.aDouble;
    26931                                                long ox;
    26932                                                ox = toLong(Math.sqrt(ix));
    26933                                                oai64data[it.oIndex] = ox;
    26934                                        }
    26935                                } else {
    26936                                        while (it.hasNext()) {
    26937                                                final long ix = it.aLong;
    26938                                                long ox;
    26939                                                ox = toLong(Math.sqrt(ix));
    26940                                                oai64data[it.oIndex] = ox;
    26941                                        }
    26942                                }
    26943                        } else if (as == 1) {
    26944                                if (it.isOutputDouble()) {
    26945                                        while (it.hasNext()) {
    26946                                                final double ix = it.aDouble;
    26947                                                long ox;
    26948                                                ox = toLong(Math.sqrt(ix));
    26949                                                for (int j = 0; j < is; j++) {
    26950                                                        oai64data[it.oIndex + j] = ox;
    26951                                                }
    26952                                        }
    26953                                } else {
    26954                                        while (it.hasNext()) {
    26955                                                final long ix = it.aLong;
    26956                                                long ox;
    26957                                                ox = toLong(Math.sqrt(ix));
    26958                                                for (int j = 0; j < is; j++) {
    26959                                                        oai64data[it.oIndex + j] = ox;
    26960                                                }
    26961                                        }
    26962                                }
    26963                        } else {
    26964                                if (it.isOutputDouble()) {
    26965                                        while (it.hasNext()) {
    26966                                                for (int j = 0; j < is; j++) {
    26967                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    26968                                                        long ox;
    26969                                                        ox = toLong(Math.sqrt(ix));
    26970                                                        oai64data[it.oIndex + j] = ox;
    26971                                                }
    26972                                        }
    26973                                } else {
    26974                                        while (it.hasNext()) {
    26975                                                for (int j = 0; j < is; j++) {
    26976                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    26977                                                        long ox;
    26978                                                        ox = toLong(Math.sqrt(ix));
    26979                                                        oai64data[it.oIndex + j] = ox;
    26980                                                }
    26981                                        }
    26982                                }
    26983                        }
    26984                        break;
    26985                case Dataset.ARRAYINT32:
    26986                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    26987                        if (is == 1) {
    26988                                if (it.isOutputDouble()) {
    26989                                        while (it.hasNext()) {
    26990                                                final double ix = it.aDouble;
    26991                                                int ox;
    26992                                                ox = (int) toLong(Math.sqrt(ix));
    26993                                                oai32data[it.oIndex] = ox;
    26994                                        }
    26995                                } else {
    26996                                        while (it.hasNext()) {
    26997                                                final long ix = it.aLong;
    26998                                                int ox;
    26999                                                ox = (int) toLong(Math.sqrt(ix));
    27000                                                oai32data[it.oIndex] = ox;
    27001                                        }
    27002                                }
    27003                        } else if (as == 1) {
    27004                                if (it.isOutputDouble()) {
    27005                                        while (it.hasNext()) {
    27006                                                final double ix = it.aDouble;
    27007                                                int ox;
    27008                                                ox = (int) toLong(Math.sqrt(ix));
    27009                                                for (int j = 0; j < is; j++) {
    27010                                                        oai32data[it.oIndex + j] = ox;
    27011                                                }
    27012                                        }
    27013                                } else {
    27014                                        while (it.hasNext()) {
    27015                                                final long ix = it.aLong;
    27016                                                int ox;
    27017                                                ox = (int) toLong(Math.sqrt(ix));
    27018                                                for (int j = 0; j < is; j++) {
    27019                                                        oai32data[it.oIndex + j] = ox;
    27020                                                }
    27021                                        }
    27022                                }
    27023                        } else {
    27024                                if (it.isOutputDouble()) {
    27025                                        while (it.hasNext()) {
    27026                                                for (int j = 0; j < is; j++) {
    27027                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27028                                                        int ox;
    27029                                                        ox = (int) toLong(Math.sqrt(ix));
    27030                                                        oai32data[it.oIndex + j] = ox;
    27031                                                }
    27032                                        }
    27033                                } else {
    27034                                        while (it.hasNext()) {
    27035                                                for (int j = 0; j < is; j++) {
    27036                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27037                                                        int ox;
    27038                                                        ox = (int) toLong(Math.sqrt(ix));
    27039                                                        oai32data[it.oIndex + j] = ox;
    27040                                                }
    27041                                        }
    27042                                }
    27043                        }
    27044                        break;
    27045                case Dataset.FLOAT32:
    27046                        final float[] of32data = ((FloatDataset) result).getData();
    27047                        if (it.isOutputDouble()) {
    27048                                while (it.hasNext()) {
    27049                                        final double ix = it.aDouble;
    27050                                        float ox;
    27051                                        ox = (float) (Math.sqrt(ix));
    27052                                        of32data[it.oIndex] = ox;
    27053                                }
    27054                        } else {
    27055                                while (it.hasNext()) {
    27056                                        final long ix = it.aLong;
    27057                                        float ox;
    27058                                        ox = (float) (Math.sqrt(ix));
    27059                                        of32data[it.oIndex] = ox;
    27060                                }
    27061                        }
    27062                        break;
    27063                case Dataset.FLOAT64:
    27064                        final double[] of64data = ((DoubleDataset) result).getData();
    27065                        if (it.isOutputDouble()) {
    27066                                while (it.hasNext()) {
    27067                                        final double ix = it.aDouble;
    27068                                        double ox;
    27069                                        ox = (Math.sqrt(ix));
    27070                                        of64data[it.oIndex] = ox;
    27071                                }
    27072                        } else {
    27073                                while (it.hasNext()) {
    27074                                        final long ix = it.aLong;
    27075                                        double ox;
    27076                                        ox = (Math.sqrt(ix));
    27077                                        of64data[it.oIndex] = ox;
    27078                                }
    27079                        }
    27080                        break;
    27081                case Dataset.ARRAYFLOAT32:
    27082                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    27083                        if (is == 1) {
    27084                                if (it.isOutputDouble()) {
    27085                                        while (it.hasNext()) {
    27086                                                final double ix = it.aDouble;
    27087                                                float ox;
    27088                                                ox = (float) (Math.sqrt(ix));
    27089                                                oaf32data[it.oIndex] = ox;
    27090                                        }
    27091                                } else {
    27092                                        while (it.hasNext()) {
    27093                                                final long ix = it.aLong;
    27094                                                float ox;
    27095                                                ox = (float) (Math.sqrt(ix));
    27096                                                oaf32data[it.oIndex] = ox;
    27097                                        }
    27098                                }
    27099                        } else if (as == 1) {
    27100                                if (it.isOutputDouble()) {
    27101                                        while (it.hasNext()) {
    27102                                                final double ix = it.aDouble;
    27103                                                float ox;
    27104                                                ox = (float) (Math.sqrt(ix));
    27105                                                for (int j = 0; j < is; j++) {
    27106                                                        oaf32data[it.oIndex + j] = ox;
    27107                                                }
    27108                                        }
    27109                                } else {
    27110                                        while (it.hasNext()) {
    27111                                                final long ix = it.aLong;
    27112                                                float ox;
    27113                                                ox = (float) (Math.sqrt(ix));
    27114                                                for (int j = 0; j < is; j++) {
    27115                                                        oaf32data[it.oIndex + j] = ox;
    27116                                                }
    27117                                        }
    27118                                }
    27119                        } else {
    27120                                if (it.isOutputDouble()) {
    27121                                        while (it.hasNext()) {
    27122                                                for (int j = 0; j < is; j++) {
    27123                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27124                                                        float ox;
    27125                                                        ox = (float) (Math.sqrt(ix));
    27126                                                        oaf32data[it.oIndex + j] = ox;
    27127                                                }
    27128                                        }
    27129                                } else {
    27130                                        while (it.hasNext()) {
    27131                                                for (int j = 0; j < is; j++) {
    27132                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27133                                                        float ox;
    27134                                                        ox = (float) (Math.sqrt(ix));
    27135                                                        oaf32data[it.oIndex + j] = ox;
    27136                                                }
    27137                                        }
    27138                                }
    27139                        }
    27140                        break;
    27141                case Dataset.ARRAYFLOAT64:
    27142                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    27143                        if (is == 1) {
    27144                                if (it.isOutputDouble()) {
    27145                                        while (it.hasNext()) {
    27146                                                final double ix = it.aDouble;
    27147                                                double ox;
    27148                                                ox = (Math.sqrt(ix));
    27149                                                oaf64data[it.oIndex] = ox;
    27150                                        }
    27151                                } else {
    27152                                        while (it.hasNext()) {
    27153                                                final long ix = it.aLong;
    27154                                                double ox;
    27155                                                ox = (Math.sqrt(ix));
    27156                                                oaf64data[it.oIndex] = ox;
    27157                                        }
    27158                                }
    27159                        } else if (as == 1) {
    27160                                if (it.isOutputDouble()) {
    27161                                        while (it.hasNext()) {
    27162                                                final double ix = it.aDouble;
    27163                                                double ox;
    27164                                                ox = (Math.sqrt(ix));
    27165                                                for (int j = 0; j < is; j++) {
    27166                                                        oaf64data[it.oIndex + j] = ox;
    27167                                                }
    27168                                        }
    27169                                } else {
    27170                                        while (it.hasNext()) {
    27171                                                final long ix = it.aLong;
    27172                                                double ox;
    27173                                                ox = (Math.sqrt(ix));
    27174                                                for (int j = 0; j < is; j++) {
    27175                                                        oaf64data[it.oIndex + j] = ox;
    27176                                                }
    27177                                        }
    27178                                }
    27179                        } else {
    27180                                if (it.isOutputDouble()) {
    27181                                        while (it.hasNext()) {
    27182                                                for (int j = 0; j < is; j++) {
    27183                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27184                                                        double ox;
    27185                                                        ox = (Math.sqrt(ix));
    27186                                                        oaf64data[it.oIndex + j] = ox;
    27187                                                }
    27188                                        }
    27189                                } else {
    27190                                        while (it.hasNext()) {
    27191                                                for (int j = 0; j < is; j++) {
    27192                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27193                                                        double ox;
    27194                                                        ox = (Math.sqrt(ix));
    27195                                                        oaf64data[it.oIndex + j] = ox;
    27196                                                }
    27197                                        }
    27198                                }
    27199                        }
    27200                        break;
    27201                case Dataset.COMPLEX64:
    27202                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    27203                        if (as == 1) {
    27204                                final double iy = 0;
    27205                                while (it.hasNext()) {
    27206                                        final double ix = it.aDouble;
    27207                                        Complex tz;
    27208                                        float ox;
    27209                                        float oy;
    27210                                        tz = new Complex(ix, iy).sqrt();
    27211                                        ox = (float) (tz.getReal());
    27212                                        oy = (float) (tz.getImaginary());
    27213                                        oc64data[it.oIndex] = ox;
    27214                                        oc64data[it.oIndex + 1] = oy;
    27215                                }
    27216                        } else {
    27217                                while (it.hasNext()) {
    27218                                        final double ix = it.aDouble;
    27219                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    27220                                        Complex tz;
    27221                                        float ox;
    27222                                        float oy;
    27223                                        tz = new Complex(ix, iy).sqrt();
    27224                                        ox = (float) (tz.getReal());
    27225                                        oy = (float) (tz.getImaginary());
    27226                                        oc64data[it.oIndex] = ox;
    27227                                        oc64data[it.oIndex + 1] = oy;
    27228                                }
    27229                        }
    27230                        break;
    27231                case Dataset.COMPLEX128:
    27232                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    27233                        if (as == 1) {
    27234                                final double iy = 0;
    27235                                while (it.hasNext()) {
    27236                                        final double ix = it.aDouble;
    27237                                        Complex tz;
    27238                                        double ox;
    27239                                        double oy;
    27240                                        tz = new Complex(ix, iy).sqrt();
    27241                                        ox = (tz.getReal());
    27242                                        oy = (tz.getImaginary());
    27243                                        oc128data[it.oIndex] = ox;
    27244                                        oc128data[it.oIndex + 1] = oy;
    27245                                }
    27246                        } else {
    27247                                while (it.hasNext()) {
    27248                                        final double ix = it.aDouble;
    27249                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    27250                                        Complex tz;
    27251                                        double ox;
    27252                                        double oy;
    27253                                        tz = new Complex(ix, iy).sqrt();
    27254                                        ox = (tz.getReal());
    27255                                        oy = (tz.getImaginary());
    27256                                        oc128data[it.oIndex] = ox;
    27257                                        oc128data[it.oIndex + 1] = oy;
    27258                                }
    27259                        }
    27260                        break;
    27261                default:
    27262                        throw new IllegalArgumentException("sqrt supports integer, compound integer, real, compound real, complex datasets only");
    27263                }
    27264
    27265                addFunctionName(result, "sqrt");
    27266                return result;
    27267        }
    27268
    27269        /**
    27270         * cbrt - evaluate the cube root function on each element of the dataset
    27271         * @param a
    27272         * @return dataset
    27273         */
    27274        public static Dataset cbrt(final Object a) {
    27275                return cbrt(a, null);
    27276        }
    27277
    27278        /**
    27279         * cbrt - evaluate the cube root function on each element of the dataset
    27280         * @param a
    27281         * @param o output can be null - in which case, a new dataset is created
    27282         * @return dataset
    27283         */
    27284        public static Dataset cbrt(final Object a, final Dataset o) {
    27285                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    27286                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    27287                final Dataset result = it.getOutput();
    27288                final int is = result.getElementsPerItem();
    27289                final int as = da.getElementsPerItem();
    27290                final int dt = result.getDType();
    27291
    27292                switch(dt) {
    27293                case Dataset.INT8:
    27294                        final byte[] oi8data = ((ByteDataset) result).getData();
    27295                        if (it.isOutputDouble()) {
    27296                                while (it.hasNext()) {
    27297                                        final double ix = it.aDouble;
    27298                                        byte ox;
    27299                                        ox = (byte) toLong(Math.cbrt(ix));
    27300                                        oi8data[it.oIndex] = ox;
    27301                                }
    27302                        } else {
    27303                                while (it.hasNext()) {
    27304                                        final long ix = it.aLong;
    27305                                        byte ox;
    27306                                        ox = (byte) toLong(Math.cbrt(ix));
    27307                                        oi8data[it.oIndex] = ox;
    27308                                }
    27309                        }
    27310                        break;
    27311                case Dataset.INT16:
    27312                        final short[] oi16data = ((ShortDataset) result).getData();
    27313                        if (it.isOutputDouble()) {
    27314                                while (it.hasNext()) {
    27315                                        final double ix = it.aDouble;
    27316                                        short ox;
    27317                                        ox = (short) toLong(Math.cbrt(ix));
    27318                                        oi16data[it.oIndex] = ox;
    27319                                }
    27320                        } else {
    27321                                while (it.hasNext()) {
    27322                                        final long ix = it.aLong;
    27323                                        short ox;
    27324                                        ox = (short) toLong(Math.cbrt(ix));
    27325                                        oi16data[it.oIndex] = ox;
    27326                                }
    27327                        }
    27328                        break;
    27329                case Dataset.INT64:
    27330                        final long[] oi64data = ((LongDataset) result).getData();
    27331                        if (it.isOutputDouble()) {
    27332                                while (it.hasNext()) {
    27333                                        final double ix = it.aDouble;
    27334                                        long ox;
    27335                                        ox = toLong(Math.cbrt(ix));
    27336                                        oi64data[it.oIndex] = ox;
    27337                                }
    27338                        } else {
    27339                                while (it.hasNext()) {
    27340                                        final long ix = it.aLong;
    27341                                        long ox;
    27342                                        ox = toLong(Math.cbrt(ix));
    27343                                        oi64data[it.oIndex] = ox;
    27344                                }
    27345                        }
    27346                        break;
    27347                case Dataset.INT32:
    27348                        final int[] oi32data = ((IntegerDataset) result).getData();
    27349                        if (it.isOutputDouble()) {
    27350                                while (it.hasNext()) {
    27351                                        final double ix = it.aDouble;
    27352                                        int ox;
    27353                                        ox = (int) toLong(Math.cbrt(ix));
    27354                                        oi32data[it.oIndex] = ox;
    27355                                }
    27356                        } else {
    27357                                while (it.hasNext()) {
    27358                                        final long ix = it.aLong;
    27359                                        int ox;
    27360                                        ox = (int) toLong(Math.cbrt(ix));
    27361                                        oi32data[it.oIndex] = ox;
    27362                                }
    27363                        }
    27364                        break;
    27365                case Dataset.ARRAYINT8:
    27366                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    27367                        if (is == 1) {
    27368                                if (it.isOutputDouble()) {
    27369                                        while (it.hasNext()) {
    27370                                                final double ix = it.aDouble;
    27371                                                byte ox;
    27372                                                ox = (byte) toLong(Math.cbrt(ix));
    27373                                                oai8data[it.oIndex] = ox;
    27374                                        }
    27375                                } else {
    27376                                        while (it.hasNext()) {
    27377                                                final long ix = it.aLong;
    27378                                                byte ox;
    27379                                                ox = (byte) toLong(Math.cbrt(ix));
    27380                                                oai8data[it.oIndex] = ox;
    27381                                        }
    27382                                }
    27383                        } else if (as == 1) {
    27384                                if (it.isOutputDouble()) {
    27385                                        while (it.hasNext()) {
    27386                                                final double ix = it.aDouble;
    27387                                                byte ox;
    27388                                                ox = (byte) toLong(Math.cbrt(ix));
    27389                                                for (int j = 0; j < is; j++) {
    27390                                                        oai8data[it.oIndex + j] = ox;
    27391                                                }
    27392                                        }
    27393                                } else {
    27394                                        while (it.hasNext()) {
    27395                                                final long ix = it.aLong;
    27396                                                byte ox;
    27397                                                ox = (byte) toLong(Math.cbrt(ix));
    27398                                                for (int j = 0; j < is; j++) {
    27399                                                        oai8data[it.oIndex + j] = ox;
    27400                                                }
    27401                                        }
    27402                                }
    27403                        } else {
    27404                                if (it.isOutputDouble()) {
    27405                                        while (it.hasNext()) {
    27406                                                for (int j = 0; j < is; j++) {
    27407                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27408                                                        byte ox;
    27409                                                        ox = (byte) toLong(Math.cbrt(ix));
    27410                                                        oai8data[it.oIndex + j] = ox;
    27411                                                }
    27412                                        }
    27413                                } else {
    27414                                        while (it.hasNext()) {
    27415                                                for (int j = 0; j < is; j++) {
    27416                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27417                                                        byte ox;
    27418                                                        ox = (byte) toLong(Math.cbrt(ix));
    27419                                                        oai8data[it.oIndex + j] = ox;
    27420                                                }
    27421                                        }
    27422                                }
    27423                        }
    27424                        break;
    27425                case Dataset.ARRAYINT16:
    27426                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    27427                        if (is == 1) {
    27428                                if (it.isOutputDouble()) {
    27429                                        while (it.hasNext()) {
    27430                                                final double ix = it.aDouble;
    27431                                                short ox;
    27432                                                ox = (short) toLong(Math.cbrt(ix));
    27433                                                oai16data[it.oIndex] = ox;
    27434                                        }
    27435                                } else {
    27436                                        while (it.hasNext()) {
    27437                                                final long ix = it.aLong;
    27438                                                short ox;
    27439                                                ox = (short) toLong(Math.cbrt(ix));
    27440                                                oai16data[it.oIndex] = ox;
    27441                                        }
    27442                                }
    27443                        } else if (as == 1) {
    27444                                if (it.isOutputDouble()) {
    27445                                        while (it.hasNext()) {
    27446                                                final double ix = it.aDouble;
    27447                                                short ox;
    27448                                                ox = (short) toLong(Math.cbrt(ix));
    27449                                                for (int j = 0; j < is; j++) {
    27450                                                        oai16data[it.oIndex + j] = ox;
    27451                                                }
    27452                                        }
    27453                                } else {
    27454                                        while (it.hasNext()) {
    27455                                                final long ix = it.aLong;
    27456                                                short ox;
    27457                                                ox = (short) toLong(Math.cbrt(ix));
    27458                                                for (int j = 0; j < is; j++) {
    27459                                                        oai16data[it.oIndex + j] = ox;
    27460                                                }
    27461                                        }
    27462                                }
    27463                        } else {
    27464                                if (it.isOutputDouble()) {
    27465                                        while (it.hasNext()) {
    27466                                                for (int j = 0; j < is; j++) {
    27467                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27468                                                        short ox;
    27469                                                        ox = (short) toLong(Math.cbrt(ix));
    27470                                                        oai16data[it.oIndex + j] = ox;
    27471                                                }
    27472                                        }
    27473                                } else {
    27474                                        while (it.hasNext()) {
    27475                                                for (int j = 0; j < is; j++) {
    27476                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27477                                                        short ox;
    27478                                                        ox = (short) toLong(Math.cbrt(ix));
    27479                                                        oai16data[it.oIndex + j] = ox;
    27480                                                }
    27481                                        }
    27482                                }
    27483                        }
    27484                        break;
    27485                case Dataset.ARRAYINT64:
    27486                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    27487                        if (is == 1) {
    27488                                if (it.isOutputDouble()) {
    27489                                        while (it.hasNext()) {
    27490                                                final double ix = it.aDouble;
    27491                                                long ox;
    27492                                                ox = toLong(Math.cbrt(ix));
    27493                                                oai64data[it.oIndex] = ox;
    27494                                        }
    27495                                } else {
    27496                                        while (it.hasNext()) {
    27497                                                final long ix = it.aLong;
    27498                                                long ox;
    27499                                                ox = toLong(Math.cbrt(ix));
    27500                                                oai64data[it.oIndex] = ox;
    27501                                        }
    27502                                }
    27503                        } else if (as == 1) {
    27504                                if (it.isOutputDouble()) {
    27505                                        while (it.hasNext()) {
    27506                                                final double ix = it.aDouble;
    27507                                                long ox;
    27508                                                ox = toLong(Math.cbrt(ix));
    27509                                                for (int j = 0; j < is; j++) {
    27510                                                        oai64data[it.oIndex + j] = ox;
    27511                                                }
    27512                                        }
    27513                                } else {
    27514                                        while (it.hasNext()) {
    27515                                                final long ix = it.aLong;
    27516                                                long ox;
    27517                                                ox = toLong(Math.cbrt(ix));
    27518                                                for (int j = 0; j < is; j++) {
    27519                                                        oai64data[it.oIndex + j] = ox;
    27520                                                }
    27521                                        }
    27522                                }
    27523                        } else {
    27524                                if (it.isOutputDouble()) {
    27525                                        while (it.hasNext()) {
    27526                                                for (int j = 0; j < is; j++) {
    27527                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27528                                                        long ox;
    27529                                                        ox = toLong(Math.cbrt(ix));
    27530                                                        oai64data[it.oIndex + j] = ox;
    27531                                                }
    27532                                        }
    27533                                } else {
    27534                                        while (it.hasNext()) {
    27535                                                for (int j = 0; j < is; j++) {
    27536                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27537                                                        long ox;
    27538                                                        ox = toLong(Math.cbrt(ix));
    27539                                                        oai64data[it.oIndex + j] = ox;
    27540                                                }
    27541                                        }
    27542                                }
    27543                        }
    27544                        break;
    27545                case Dataset.ARRAYINT32:
    27546                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    27547                        if (is == 1) {
    27548                                if (it.isOutputDouble()) {
    27549                                        while (it.hasNext()) {
    27550                                                final double ix = it.aDouble;
    27551                                                int ox;
    27552                                                ox = (int) toLong(Math.cbrt(ix));
    27553                                                oai32data[it.oIndex] = ox;
    27554                                        }
    27555                                } else {
    27556                                        while (it.hasNext()) {
    27557                                                final long ix = it.aLong;
    27558                                                int ox;
    27559                                                ox = (int) toLong(Math.cbrt(ix));
    27560                                                oai32data[it.oIndex] = ox;
    27561                                        }
    27562                                }
    27563                        } else if (as == 1) {
    27564                                if (it.isOutputDouble()) {
    27565                                        while (it.hasNext()) {
    27566                                                final double ix = it.aDouble;
    27567                                                int ox;
    27568                                                ox = (int) toLong(Math.cbrt(ix));
    27569                                                for (int j = 0; j < is; j++) {
    27570                                                        oai32data[it.oIndex + j] = ox;
    27571                                                }
    27572                                        }
    27573                                } else {
    27574                                        while (it.hasNext()) {
    27575                                                final long ix = it.aLong;
    27576                                                int ox;
    27577                                                ox = (int) toLong(Math.cbrt(ix));
    27578                                                for (int j = 0; j < is; j++) {
    27579                                                        oai32data[it.oIndex + j] = ox;
    27580                                                }
    27581                                        }
    27582                                }
    27583                        } else {
    27584                                if (it.isOutputDouble()) {
    27585                                        while (it.hasNext()) {
    27586                                                for (int j = 0; j < is; j++) {
    27587                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27588                                                        int ox;
    27589                                                        ox = (int) toLong(Math.cbrt(ix));
    27590                                                        oai32data[it.oIndex + j] = ox;
    27591                                                }
    27592                                        }
    27593                                } else {
    27594                                        while (it.hasNext()) {
    27595                                                for (int j = 0; j < is; j++) {
    27596                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27597                                                        int ox;
    27598                                                        ox = (int) toLong(Math.cbrt(ix));
    27599                                                        oai32data[it.oIndex + j] = ox;
    27600                                                }
    27601                                        }
    27602                                }
    27603                        }
    27604                        break;
    27605                case Dataset.FLOAT32:
    27606                        final float[] of32data = ((FloatDataset) result).getData();
    27607                        if (it.isOutputDouble()) {
    27608                                while (it.hasNext()) {
    27609                                        final double ix = it.aDouble;
    27610                                        float ox;
    27611                                        ox = (float) (Math.cbrt(ix));
    27612                                        of32data[it.oIndex] = ox;
    27613                                }
    27614                        } else {
    27615                                while (it.hasNext()) {
    27616                                        final long ix = it.aLong;
    27617                                        float ox;
    27618                                        ox = (float) (Math.cbrt(ix));
    27619                                        of32data[it.oIndex] = ox;
    27620                                }
    27621                        }
    27622                        break;
    27623                case Dataset.FLOAT64:
    27624                        final double[] of64data = ((DoubleDataset) result).getData();
    27625                        if (it.isOutputDouble()) {
    27626                                while (it.hasNext()) {
    27627                                        final double ix = it.aDouble;
    27628                                        double ox;
    27629                                        ox = (Math.cbrt(ix));
    27630                                        of64data[it.oIndex] = ox;
    27631                                }
    27632                        } else {
    27633                                while (it.hasNext()) {
    27634                                        final long ix = it.aLong;
    27635                                        double ox;
    27636                                        ox = (Math.cbrt(ix));
    27637                                        of64data[it.oIndex] = ox;
    27638                                }
    27639                        }
    27640                        break;
    27641                case Dataset.ARRAYFLOAT32:
    27642                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    27643                        if (is == 1) {
    27644                                if (it.isOutputDouble()) {
    27645                                        while (it.hasNext()) {
    27646                                                final double ix = it.aDouble;
    27647                                                float ox;
    27648                                                ox = (float) (Math.cbrt(ix));
    27649                                                oaf32data[it.oIndex] = ox;
    27650                                        }
    27651                                } else {
    27652                                        while (it.hasNext()) {
    27653                                                final long ix = it.aLong;
    27654                                                float ox;
    27655                                                ox = (float) (Math.cbrt(ix));
    27656                                                oaf32data[it.oIndex] = ox;
    27657                                        }
    27658                                }
    27659                        } else if (as == 1) {
    27660                                if (it.isOutputDouble()) {
    27661                                        while (it.hasNext()) {
    27662                                                final double ix = it.aDouble;
    27663                                                float ox;
    27664                                                ox = (float) (Math.cbrt(ix));
    27665                                                for (int j = 0; j < is; j++) {
    27666                                                        oaf32data[it.oIndex + j] = ox;
    27667                                                }
    27668                                        }
    27669                                } else {
    27670                                        while (it.hasNext()) {
    27671                                                final long ix = it.aLong;
    27672                                                float ox;
    27673                                                ox = (float) (Math.cbrt(ix));
    27674                                                for (int j = 0; j < is; j++) {
    27675                                                        oaf32data[it.oIndex + j] = ox;
    27676                                                }
    27677                                        }
    27678                                }
    27679                        } else {
    27680                                if (it.isOutputDouble()) {
    27681                                        while (it.hasNext()) {
    27682                                                for (int j = 0; j < is; j++) {
    27683                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27684                                                        float ox;
    27685                                                        ox = (float) (Math.cbrt(ix));
    27686                                                        oaf32data[it.oIndex + j] = ox;
    27687                                                }
    27688                                        }
    27689                                } else {
    27690                                        while (it.hasNext()) {
    27691                                                for (int j = 0; j < is; j++) {
    27692                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27693                                                        float ox;
    27694                                                        ox = (float) (Math.cbrt(ix));
    27695                                                        oaf32data[it.oIndex + j] = ox;
    27696                                                }
    27697                                        }
    27698                                }
    27699                        }
    27700                        break;
    27701                case Dataset.ARRAYFLOAT64:
    27702                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    27703                        if (is == 1) {
    27704                                if (it.isOutputDouble()) {
    27705                                        while (it.hasNext()) {
    27706                                                final double ix = it.aDouble;
    27707                                                double ox;
    27708                                                ox = (Math.cbrt(ix));
    27709                                                oaf64data[it.oIndex] = ox;
    27710                                        }
    27711                                } else {
    27712                                        while (it.hasNext()) {
    27713                                                final long ix = it.aLong;
    27714                                                double ox;
    27715                                                ox = (Math.cbrt(ix));
    27716                                                oaf64data[it.oIndex] = ox;
    27717                                        }
    27718                                }
    27719                        } else if (as == 1) {
    27720                                if (it.isOutputDouble()) {
    27721                                        while (it.hasNext()) {
    27722                                                final double ix = it.aDouble;
    27723                                                double ox;
    27724                                                ox = (Math.cbrt(ix));
    27725                                                for (int j = 0; j < is; j++) {
    27726                                                        oaf64data[it.oIndex + j] = ox;
    27727                                                }
    27728                                        }
    27729                                } else {
    27730                                        while (it.hasNext()) {
    27731                                                final long ix = it.aLong;
    27732                                                double ox;
    27733                                                ox = (Math.cbrt(ix));
    27734                                                for (int j = 0; j < is; j++) {
    27735                                                        oaf64data[it.oIndex + j] = ox;
    27736                                                }
    27737                                        }
    27738                                }
    27739                        } else {
    27740                                if (it.isOutputDouble()) {
    27741                                        while (it.hasNext()) {
    27742                                                for (int j = 0; j < is; j++) {
    27743                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27744                                                        double ox;
    27745                                                        ox = (Math.cbrt(ix));
    27746                                                        oaf64data[it.oIndex + j] = ox;
    27747                                                }
    27748                                        }
    27749                                } else {
    27750                                        while (it.hasNext()) {
    27751                                                for (int j = 0; j < is; j++) {
    27752                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27753                                                        double ox;
    27754                                                        ox = (Math.cbrt(ix));
    27755                                                        oaf64data[it.oIndex + j] = ox;
    27756                                                }
    27757                                        }
    27758                                }
    27759                        }
    27760                        break;
    27761                case Dataset.COMPLEX64:
    27762                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    27763                        if (as == 1) {
    27764                                final double iy = 0;
    27765                                while (it.hasNext()) {
    27766                                        final double ix = it.aDouble;
    27767                                        Complex tz;
    27768                                        float ox;
    27769                                        float oy;
    27770                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
    27771                                        ox = (float) (tz.getReal());
    27772                                        oy = (float) (tz.getImaginary());
    27773                                        oc64data[it.oIndex] = ox;
    27774                                        oc64data[it.oIndex + 1] = oy;
    27775                                }
    27776                        } else {
    27777                                while (it.hasNext()) {
    27778                                        final double ix = it.aDouble;
    27779                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    27780                                        Complex tz;
    27781                                        float ox;
    27782                                        float oy;
    27783                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
    27784                                        ox = (float) (tz.getReal());
    27785                                        oy = (float) (tz.getImaginary());
    27786                                        oc64data[it.oIndex] = ox;
    27787                                        oc64data[it.oIndex + 1] = oy;
    27788                                }
    27789                        }
    27790                        break;
    27791                case Dataset.COMPLEX128:
    27792                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    27793                        if (as == 1) {
    27794                                final double iy = 0;
    27795                                while (it.hasNext()) {
    27796                                        final double ix = it.aDouble;
    27797                                        Complex tz;
    27798                                        double ox;
    27799                                        double oy;
    27800                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
    27801                                        ox = (tz.getReal());
    27802                                        oy = (tz.getImaginary());
    27803                                        oc128data[it.oIndex] = ox;
    27804                                        oc128data[it.oIndex + 1] = oy;
    27805                                }
    27806                        } else {
    27807                                while (it.hasNext()) {
    27808                                        final double ix = it.aDouble;
    27809                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    27810                                        Complex tz;
    27811                                        double ox;
    27812                                        double oy;
    27813                                        tz = new Complex(ix, iy).pow(new Complex(1./3.,0));
    27814                                        ox = (tz.getReal());
    27815                                        oy = (tz.getImaginary());
    27816                                        oc128data[it.oIndex] = ox;
    27817                                        oc128data[it.oIndex + 1] = oy;
    27818                                }
    27819                        }
    27820                        break;
    27821                default:
    27822                        throw new IllegalArgumentException("cbrt supports integer, compound integer, real, compound real, complex datasets only");
    27823                }
    27824
    27825                addFunctionName(result, "cbrt");
    27826                return result;
    27827        }
    27828
    27829        /**
    27830         * square - square each element
    27831         * @param a
    27832         * @return dataset
    27833         */
    27834        public static Dataset square(final Object a) {
    27835                return square(a, null);
    27836        }
    27837
    27838        /**
    27839         * square - square each element
    27840         * @param a
    27841         * @param o output can be null - in which case, a new dataset is created
    27842         * @return dataset
    27843         */
    27844        public static Dataset square(final Object a, final Dataset o) {
    27845                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    27846                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    27847                final Dataset result = it.getOutput();
    27848                final int is = result.getElementsPerItem();
    27849                final int as = da.getElementsPerItem();
    27850                final int dt = result.getDType();
    27851
    27852                switch(dt) {
    27853                case Dataset.INT8:
    27854                        final byte[] oi8data = ((ByteDataset) result).getData();
    27855                        if (it.isOutputDouble()) {
    27856                                while (it.hasNext()) {
    27857                                        final double ix = it.aDouble;
    27858                                        byte ox;
    27859                                        ox = (byte) toLong(ix*ix);
    27860                                        oi8data[it.oIndex] = ox;
    27861                                }
    27862                        } else {
    27863                                while (it.hasNext()) {
    27864                                        final long ix = it.aLong;
    27865                                        byte ox;
    27866                                        ox = (byte) toLong(ix*ix);
    27867                                        oi8data[it.oIndex] = ox;
    27868                                }
    27869                        }
    27870                        break;
    27871                case Dataset.INT16:
    27872                        final short[] oi16data = ((ShortDataset) result).getData();
    27873                        if (it.isOutputDouble()) {
    27874                                while (it.hasNext()) {
    27875                                        final double ix = it.aDouble;
    27876                                        short ox;
    27877                                        ox = (short) toLong(ix*ix);
    27878                                        oi16data[it.oIndex] = ox;
    27879                                }
    27880                        } else {
    27881                                while (it.hasNext()) {
    27882                                        final long ix = it.aLong;
    27883                                        short ox;
    27884                                        ox = (short) toLong(ix*ix);
    27885                                        oi16data[it.oIndex] = ox;
    27886                                }
    27887                        }
    27888                        break;
    27889                case Dataset.INT64:
    27890                        final long[] oi64data = ((LongDataset) result).getData();
    27891                        if (it.isOutputDouble()) {
    27892                                while (it.hasNext()) {
    27893                                        final double ix = it.aDouble;
    27894                                        long ox;
    27895                                        ox = toLong(ix*ix);
    27896                                        oi64data[it.oIndex] = ox;
    27897                                }
    27898                        } else {
    27899                                while (it.hasNext()) {
    27900                                        final long ix = it.aLong;
    27901                                        long ox;
    27902                                        ox = toLong(ix*ix);
    27903                                        oi64data[it.oIndex] = ox;
    27904                                }
    27905                        }
    27906                        break;
    27907                case Dataset.INT32:
    27908                        final int[] oi32data = ((IntegerDataset) result).getData();
    27909                        if (it.isOutputDouble()) {
    27910                                while (it.hasNext()) {
    27911                                        final double ix = it.aDouble;
    27912                                        int ox;
    27913                                        ox = (int) toLong(ix*ix);
    27914                                        oi32data[it.oIndex] = ox;
    27915                                }
    27916                        } else {
    27917                                while (it.hasNext()) {
    27918                                        final long ix = it.aLong;
    27919                                        int ox;
    27920                                        ox = (int) toLong(ix*ix);
    27921                                        oi32data[it.oIndex] = ox;
    27922                                }
    27923                        }
    27924                        break;
    27925                case Dataset.ARRAYINT8:
    27926                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    27927                        if (is == 1) {
    27928                                if (it.isOutputDouble()) {
    27929                                        while (it.hasNext()) {
    27930                                                final double ix = it.aDouble;
    27931                                                byte ox;
    27932                                                ox = (byte) toLong(ix*ix);
    27933                                                oai8data[it.oIndex] = ox;
    27934                                        }
    27935                                } else {
    27936                                        while (it.hasNext()) {
    27937                                                final long ix = it.aLong;
    27938                                                byte ox;
    27939                                                ox = (byte) toLong(ix*ix);
    27940                                                oai8data[it.oIndex] = ox;
    27941                                        }
    27942                                }
    27943                        } else if (as == 1) {
    27944                                if (it.isOutputDouble()) {
    27945                                        while (it.hasNext()) {
    27946                                                final double ix = it.aDouble;
    27947                                                byte ox;
    27948                                                ox = (byte) toLong(ix*ix);
    27949                                                for (int j = 0; j < is; j++) {
    27950                                                        oai8data[it.oIndex + j] = ox;
    27951                                                }
    27952                                        }
    27953                                } else {
    27954                                        while (it.hasNext()) {
    27955                                                final long ix = it.aLong;
    27956                                                byte ox;
    27957                                                ox = (byte) toLong(ix*ix);
    27958                                                for (int j = 0; j < is; j++) {
    27959                                                        oai8data[it.oIndex + j] = ox;
    27960                                                }
    27961                                        }
    27962                                }
    27963                        } else {
    27964                                if (it.isOutputDouble()) {
    27965                                        while (it.hasNext()) {
    27966                                                for (int j = 0; j < is; j++) {
    27967                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    27968                                                        byte ox;
    27969                                                        ox = (byte) toLong(ix*ix);
    27970                                                        oai8data[it.oIndex + j] = ox;
    27971                                                }
    27972                                        }
    27973                                } else {
    27974                                        while (it.hasNext()) {
    27975                                                for (int j = 0; j < is; j++) {
    27976                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    27977                                                        byte ox;
    27978                                                        ox = (byte) toLong(ix*ix);
    27979                                                        oai8data[it.oIndex + j] = ox;
    27980                                                }
    27981                                        }
    27982                                }
    27983                        }
    27984                        break;
    27985                case Dataset.ARRAYINT16:
    27986                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    27987                        if (is == 1) {
    27988                                if (it.isOutputDouble()) {
    27989                                        while (it.hasNext()) {
    27990                                                final double ix = it.aDouble;
    27991                                                short ox;
    27992                                                ox = (short) toLong(ix*ix);
    27993                                                oai16data[it.oIndex] = ox;
    27994                                        }
    27995                                } else {
    27996                                        while (it.hasNext()) {
    27997                                                final long ix = it.aLong;
    27998                                                short ox;
    27999                                                ox = (short) toLong(ix*ix);
    28000                                                oai16data[it.oIndex] = ox;
    28001                                        }
    28002                                }
    28003                        } else if (as == 1) {
    28004                                if (it.isOutputDouble()) {
    28005                                        while (it.hasNext()) {
    28006                                                final double ix = it.aDouble;
    28007                                                short ox;
    28008                                                ox = (short) toLong(ix*ix);
    28009                                                for (int j = 0; j < is; j++) {
    28010                                                        oai16data[it.oIndex + j] = ox;
    28011                                                }
    28012                                        }
    28013                                } else {
    28014                                        while (it.hasNext()) {
    28015                                                final long ix = it.aLong;
    28016                                                short ox;
    28017                                                ox = (short) toLong(ix*ix);
    28018                                                for (int j = 0; j < is; j++) {
    28019                                                        oai16data[it.oIndex + j] = ox;
    28020                                                }
    28021                                        }
    28022                                }
    28023                        } else {
    28024                                if (it.isOutputDouble()) {
    28025                                        while (it.hasNext()) {
    28026                                                for (int j = 0; j < is; j++) {
    28027                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28028                                                        short ox;
    28029                                                        ox = (short) toLong(ix*ix);
    28030                                                        oai16data[it.oIndex + j] = ox;
    28031                                                }
    28032                                        }
    28033                                } else {
    28034                                        while (it.hasNext()) {
    28035                                                for (int j = 0; j < is; j++) {
    28036                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28037                                                        short ox;
    28038                                                        ox = (short) toLong(ix*ix);
    28039                                                        oai16data[it.oIndex + j] = ox;
    28040                                                }
    28041                                        }
    28042                                }
    28043                        }
    28044                        break;
    28045                case Dataset.ARRAYINT64:
    28046                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    28047                        if (is == 1) {
    28048                                if (it.isOutputDouble()) {
    28049                                        while (it.hasNext()) {
    28050                                                final double ix = it.aDouble;
    28051                                                long ox;
    28052                                                ox = toLong(ix*ix);
    28053                                                oai64data[it.oIndex] = ox;
    28054                                        }
    28055                                } else {
    28056                                        while (it.hasNext()) {
    28057                                                final long ix = it.aLong;
    28058                                                long ox;
    28059                                                ox = toLong(ix*ix);
    28060                                                oai64data[it.oIndex] = ox;
    28061                                        }
    28062                                }
    28063                        } else if (as == 1) {
    28064                                if (it.isOutputDouble()) {
    28065                                        while (it.hasNext()) {
    28066                                                final double ix = it.aDouble;
    28067                                                long ox;
    28068                                                ox = toLong(ix*ix);
    28069                                                for (int j = 0; j < is; j++) {
    28070                                                        oai64data[it.oIndex + j] = ox;
    28071                                                }
    28072                                        }
    28073                                } else {
    28074                                        while (it.hasNext()) {
    28075                                                final long ix = it.aLong;
    28076                                                long ox;
    28077                                                ox = toLong(ix*ix);
    28078                                                for (int j = 0; j < is; j++) {
    28079                                                        oai64data[it.oIndex + j] = ox;
    28080                                                }
    28081                                        }
    28082                                }
    28083                        } else {
    28084                                if (it.isOutputDouble()) {
    28085                                        while (it.hasNext()) {
    28086                                                for (int j = 0; j < is; j++) {
    28087                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28088                                                        long ox;
    28089                                                        ox = toLong(ix*ix);
    28090                                                        oai64data[it.oIndex + j] = ox;
    28091                                                }
    28092                                        }
    28093                                } else {
    28094                                        while (it.hasNext()) {
    28095                                                for (int j = 0; j < is; j++) {
    28096                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28097                                                        long ox;
    28098                                                        ox = toLong(ix*ix);
    28099                                                        oai64data[it.oIndex + j] = ox;
    28100                                                }
    28101                                        }
    28102                                }
    28103                        }
    28104                        break;
    28105                case Dataset.ARRAYINT32:
    28106                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    28107                        if (is == 1) {
    28108                                if (it.isOutputDouble()) {
    28109                                        while (it.hasNext()) {
    28110                                                final double ix = it.aDouble;
    28111                                                int ox;
    28112                                                ox = (int) toLong(ix*ix);
    28113                                                oai32data[it.oIndex] = ox;
    28114                                        }
    28115                                } else {
    28116                                        while (it.hasNext()) {
    28117                                                final long ix = it.aLong;
    28118                                                int ox;
    28119                                                ox = (int) toLong(ix*ix);
    28120                                                oai32data[it.oIndex] = ox;
    28121                                        }
    28122                                }
    28123                        } else if (as == 1) {
    28124                                if (it.isOutputDouble()) {
    28125                                        while (it.hasNext()) {
    28126                                                final double ix = it.aDouble;
    28127                                                int ox;
    28128                                                ox = (int) toLong(ix*ix);
    28129                                                for (int j = 0; j < is; j++) {
    28130                                                        oai32data[it.oIndex + j] = ox;
    28131                                                }
    28132                                        }
    28133                                } else {
    28134                                        while (it.hasNext()) {
    28135                                                final long ix = it.aLong;
    28136                                                int ox;
    28137                                                ox = (int) toLong(ix*ix);
    28138                                                for (int j = 0; j < is; j++) {
    28139                                                        oai32data[it.oIndex + j] = ox;
    28140                                                }
    28141                                        }
    28142                                }
    28143                        } else {
    28144                                if (it.isOutputDouble()) {
    28145                                        while (it.hasNext()) {
    28146                                                for (int j = 0; j < is; j++) {
    28147                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28148                                                        int ox;
    28149                                                        ox = (int) toLong(ix*ix);
    28150                                                        oai32data[it.oIndex + j] = ox;
    28151                                                }
    28152                                        }
    28153                                } else {
    28154                                        while (it.hasNext()) {
    28155                                                for (int j = 0; j < is; j++) {
    28156                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28157                                                        int ox;
    28158                                                        ox = (int) toLong(ix*ix);
    28159                                                        oai32data[it.oIndex + j] = ox;
    28160                                                }
    28161                                        }
    28162                                }
    28163                        }
    28164                        break;
    28165                case Dataset.FLOAT32:
    28166                        final float[] of32data = ((FloatDataset) result).getData();
    28167                        if (it.isOutputDouble()) {
    28168                                while (it.hasNext()) {
    28169                                        final double ix = it.aDouble;
    28170                                        float ox;
    28171                                        ox = (float) (ix*ix);
    28172                                        of32data[it.oIndex] = ox;
    28173                                }
    28174                        } else {
    28175                                while (it.hasNext()) {
    28176                                        final long ix = it.aLong;
    28177                                        float ox;
    28178                                        ox = (ix*ix);
    28179                                        of32data[it.oIndex] = ox;
    28180                                }
    28181                        }
    28182                        break;
    28183                case Dataset.FLOAT64:
    28184                        final double[] of64data = ((DoubleDataset) result).getData();
    28185                        if (it.isOutputDouble()) {
    28186                                while (it.hasNext()) {
    28187                                        final double ix = it.aDouble;
    28188                                        double ox;
    28189                                        ox = (ix*ix);
    28190                                        of64data[it.oIndex] = ox;
    28191                                }
    28192                        } else {
    28193                                while (it.hasNext()) {
    28194                                        final long ix = it.aLong;
    28195                                        double ox;
    28196                                        ox = (ix*ix);
    28197                                        of64data[it.oIndex] = ox;
    28198                                }
    28199                        }
    28200                        break;
    28201                case Dataset.ARRAYFLOAT32:
    28202                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    28203                        if (is == 1) {
    28204                                if (it.isOutputDouble()) {
    28205                                        while (it.hasNext()) {
    28206                                                final double ix = it.aDouble;
    28207                                                float ox;
    28208                                                ox = (float) (ix*ix);
    28209                                                oaf32data[it.oIndex] = ox;
    28210                                        }
    28211                                } else {
    28212                                        while (it.hasNext()) {
    28213                                                final long ix = it.aLong;
    28214                                                float ox;
    28215                                                ox = (ix*ix);
    28216                                                oaf32data[it.oIndex] = ox;
    28217                                        }
    28218                                }
    28219                        } else if (as == 1) {
    28220                                if (it.isOutputDouble()) {
    28221                                        while (it.hasNext()) {
    28222                                                final double ix = it.aDouble;
    28223                                                float ox;
    28224                                                ox = (float) (ix*ix);
    28225                                                for (int j = 0; j < is; j++) {
    28226                                                        oaf32data[it.oIndex + j] = ox;
    28227                                                }
    28228                                        }
    28229                                } else {
    28230                                        while (it.hasNext()) {
    28231                                                final long ix = it.aLong;
    28232                                                float ox;
    28233                                                ox = (ix*ix);
    28234                                                for (int j = 0; j < is; j++) {
    28235                                                        oaf32data[it.oIndex + j] = ox;
    28236                                                }
    28237                                        }
    28238                                }
    28239                        } else {
    28240                                if (it.isOutputDouble()) {
    28241                                        while (it.hasNext()) {
    28242                                                for (int j = 0; j < is; j++) {
    28243                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28244                                                        float ox;
    28245                                                        ox = (float) (ix*ix);
    28246                                                        oaf32data[it.oIndex + j] = ox;
    28247                                                }
    28248                                        }
    28249                                } else {
    28250                                        while (it.hasNext()) {
    28251                                                for (int j = 0; j < is; j++) {
    28252                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28253                                                        float ox;
    28254                                                        ox = (ix*ix);
    28255                                                        oaf32data[it.oIndex + j] = ox;
    28256                                                }
    28257                                        }
    28258                                }
    28259                        }
    28260                        break;
    28261                case Dataset.ARRAYFLOAT64:
    28262                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    28263                        if (is == 1) {
    28264                                if (it.isOutputDouble()) {
    28265                                        while (it.hasNext()) {
    28266                                                final double ix = it.aDouble;
    28267                                                double ox;
    28268                                                ox = (ix*ix);
    28269                                                oaf64data[it.oIndex] = ox;
    28270                                        }
    28271                                } else {
    28272                                        while (it.hasNext()) {
    28273                                                final long ix = it.aLong;
    28274                                                double ox;
    28275                                                ox = (ix*ix);
    28276                                                oaf64data[it.oIndex] = ox;
    28277                                        }
    28278                                }
    28279                        } else if (as == 1) {
    28280                                if (it.isOutputDouble()) {
    28281                                        while (it.hasNext()) {
    28282                                                final double ix = it.aDouble;
    28283                                                double ox;
    28284                                                ox = (ix*ix);
    28285                                                for (int j = 0; j < is; j++) {
    28286                                                        oaf64data[it.oIndex + j] = ox;
    28287                                                }
    28288                                        }
    28289                                } else {
    28290                                        while (it.hasNext()) {
    28291                                                final long ix = it.aLong;
    28292                                                double ox;
    28293                                                ox = (ix*ix);
    28294                                                for (int j = 0; j < is; j++) {
    28295                                                        oaf64data[it.oIndex + j] = ox;
    28296                                                }
    28297                                        }
    28298                                }
    28299                        } else {
    28300                                if (it.isOutputDouble()) {
    28301                                        while (it.hasNext()) {
    28302                                                for (int j = 0; j < is; j++) {
    28303                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28304                                                        double ox;
    28305                                                        ox = (ix*ix);
    28306                                                        oaf64data[it.oIndex + j] = ox;
    28307                                                }
    28308                                        }
    28309                                } else {
    28310                                        while (it.hasNext()) {
    28311                                                for (int j = 0; j < is; j++) {
    28312                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28313                                                        double ox;
    28314                                                        ox = (ix*ix);
    28315                                                        oaf64data[it.oIndex + j] = ox;
    28316                                                }
    28317                                        }
    28318                                }
    28319                        }
    28320                        break;
    28321                case Dataset.COMPLEX64:
    28322                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    28323                        if (as == 1) {
    28324                                final double iy = 0;
    28325                                while (it.hasNext()) {
    28326                                        final double ix = it.aDouble;
    28327                                        float ox;
    28328                                        float oy;
    28329                                        ox = (float) (ix*ix - iy*iy);
    28330                                        oy = (float) (2.*ix*iy);
    28331                                        oc64data[it.oIndex] = ox;
    28332                                        oc64data[it.oIndex + 1] = oy;
    28333                                }
    28334                        } else {
    28335                                while (it.hasNext()) {
    28336                                        final double ix = it.aDouble;
    28337                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    28338                                        float ox;
    28339                                        float oy;
    28340                                        ox = (float) (ix*ix - iy*iy);
    28341                                        oy = (float) (2.*ix*iy);
    28342                                        oc64data[it.oIndex] = ox;
    28343                                        oc64data[it.oIndex + 1] = oy;
    28344                                }
    28345                        }
    28346                        break;
    28347                case Dataset.COMPLEX128:
    28348                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    28349                        if (as == 1) {
    28350                                final double iy = 0;
    28351                                while (it.hasNext()) {
    28352                                        final double ix = it.aDouble;
    28353                                        double ox;
    28354                                        double oy;
    28355                                        ox = (ix*ix - iy*iy);
    28356                                        oy = (2.*ix*iy);
    28357                                        oc128data[it.oIndex] = ox;
    28358                                        oc128data[it.oIndex + 1] = oy;
    28359                                }
    28360                        } else {
    28361                                while (it.hasNext()) {
    28362                                        final double ix = it.aDouble;
    28363                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    28364                                        double ox;
    28365                                        double oy;
    28366                                        ox = (ix*ix - iy*iy);
    28367                                        oy = (2.*ix*iy);
    28368                                        oc128data[it.oIndex] = ox;
    28369                                        oc128data[it.oIndex + 1] = oy;
    28370                                }
    28371                        }
    28372                        break;
    28373                default:
    28374                        throw new IllegalArgumentException("square supports integer, compound integer, real, compound real, complex datasets only");
    28375                }
    28376
    28377                addFunctionName(result, "square");
    28378                return result;
    28379        }
    28380
    28381        /**
    28382         * floor - evaluate the floor function on each element of the dataset
    28383         * @param a
    28384         * @return dataset
    28385         */
    28386        public static Dataset floor(final Object a) {
    28387                return floor(a, null);
    28388        }
    28389
    28390        /**
    28391         * floor - evaluate the floor function on each element of the dataset
    28392         * @param a
    28393         * @param o output can be null - in which case, a new dataset is created
    28394         * @return dataset
    28395         */
    28396        public static Dataset floor(final Object a, final Dataset o) {
    28397                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    28398                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    28399                final Dataset result = it.getOutput();
    28400                final int is = result.getElementsPerItem();
    28401                final int as = da.getElementsPerItem();
    28402                final int dt = result.getDType();
    28403
    28404                switch(dt) {
    28405                case Dataset.INT8:
    28406                        final byte[] oi8data = ((ByteDataset) result).getData();
    28407                        if (it.isOutputDouble()) {
    28408                                while (it.hasNext()) {
    28409                                        final double ix = it.aDouble;
    28410                                        byte ox;
    28411                                        ox = (byte) toLong(ix);
    28412                                        oi8data[it.oIndex] = ox;
    28413                                }
    28414                        } else {
    28415                                while (it.hasNext()) {
    28416                                        final long ix = it.aLong;
    28417                                        byte ox;
    28418                                        ox = (byte) toLong(ix);
    28419                                        oi8data[it.oIndex] = ox;
    28420                                }
    28421                        }
    28422                        break;
    28423                case Dataset.INT16:
    28424                        final short[] oi16data = ((ShortDataset) result).getData();
    28425                        if (it.isOutputDouble()) {
    28426                                while (it.hasNext()) {
    28427                                        final double ix = it.aDouble;
    28428                                        short ox;
    28429                                        ox = (short) toLong(ix);
    28430                                        oi16data[it.oIndex] = ox;
    28431                                }
    28432                        } else {
    28433                                while (it.hasNext()) {
    28434                                        final long ix = it.aLong;
    28435                                        short ox;
    28436                                        ox = (short) toLong(ix);
    28437                                        oi16data[it.oIndex] = ox;
    28438                                }
    28439                        }
    28440                        break;
    28441                case Dataset.INT64:
    28442                        final long[] oi64data = ((LongDataset) result).getData();
    28443                        if (it.isOutputDouble()) {
    28444                                while (it.hasNext()) {
    28445                                        final double ix = it.aDouble;
    28446                                        long ox;
    28447                                        ox = toLong(ix);
    28448                                        oi64data[it.oIndex] = ox;
    28449                                }
    28450                        } else {
    28451                                while (it.hasNext()) {
    28452                                        final long ix = it.aLong;
    28453                                        long ox;
    28454                                        ox = toLong(ix);
    28455                                        oi64data[it.oIndex] = ox;
    28456                                }
    28457                        }
    28458                        break;
    28459                case Dataset.INT32:
    28460                        final int[] oi32data = ((IntegerDataset) result).getData();
    28461                        if (it.isOutputDouble()) {
    28462                                while (it.hasNext()) {
    28463                                        final double ix = it.aDouble;
    28464                                        int ox;
    28465                                        ox = (int) toLong(ix);
    28466                                        oi32data[it.oIndex] = ox;
    28467                                }
    28468                        } else {
    28469                                while (it.hasNext()) {
    28470                                        final long ix = it.aLong;
    28471                                        int ox;
    28472                                        ox = (int) toLong(ix);
    28473                                        oi32data[it.oIndex] = ox;
    28474                                }
    28475                        }
    28476                        break;
    28477                case Dataset.ARRAYINT8:
    28478                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    28479                        if (is == 1) {
    28480                                if (it.isOutputDouble()) {
    28481                                        while (it.hasNext()) {
    28482                                                final double ix = it.aDouble;
    28483                                                byte ox;
    28484                                                ox = (byte) toLong(ix);
    28485                                                oai8data[it.oIndex] = ox;
    28486                                        }
    28487                                } else {
    28488                                        while (it.hasNext()) {
    28489                                                final long ix = it.aLong;
    28490                                                byte ox;
    28491                                                ox = (byte) toLong(ix);
    28492                                                oai8data[it.oIndex] = ox;
    28493                                        }
    28494                                }
    28495                        } else if (as == 1) {
    28496                                if (it.isOutputDouble()) {
    28497                                        while (it.hasNext()) {
    28498                                                final double ix = it.aDouble;
    28499                                                byte ox;
    28500                                                ox = (byte) toLong(ix);
    28501                                                for (int j = 0; j < is; j++) {
    28502                                                        oai8data[it.oIndex + j] = ox;
    28503                                                }
    28504                                        }
    28505                                } else {
    28506                                        while (it.hasNext()) {
    28507                                                final long ix = it.aLong;
    28508                                                byte ox;
    28509                                                ox = (byte) toLong(ix);
    28510                                                for (int j = 0; j < is; j++) {
    28511                                                        oai8data[it.oIndex + j] = ox;
    28512                                                }
    28513                                        }
    28514                                }
    28515                        } else {
    28516                                if (it.isOutputDouble()) {
    28517                                        while (it.hasNext()) {
    28518                                                for (int j = 0; j < is; j++) {
    28519                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28520                                                        byte ox;
    28521                                                        ox = (byte) toLong(ix);
    28522                                                        oai8data[it.oIndex + j] = ox;
    28523                                                }
    28524                                        }
    28525                                } else {
    28526                                        while (it.hasNext()) {
    28527                                                for (int j = 0; j < is; j++) {
    28528                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28529                                                        byte ox;
    28530                                                        ox = (byte) toLong(ix);
    28531                                                        oai8data[it.oIndex + j] = ox;
    28532                                                }
    28533                                        }
    28534                                }
    28535                        }
    28536                        break;
    28537                case Dataset.ARRAYINT16:
    28538                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    28539                        if (is == 1) {
    28540                                if (it.isOutputDouble()) {
    28541                                        while (it.hasNext()) {
    28542                                                final double ix = it.aDouble;
    28543                                                short ox;
    28544                                                ox = (short) toLong(ix);
    28545                                                oai16data[it.oIndex] = ox;
    28546                                        }
    28547                                } else {
    28548                                        while (it.hasNext()) {
    28549                                                final long ix = it.aLong;
    28550                                                short ox;
    28551                                                ox = (short) toLong(ix);
    28552                                                oai16data[it.oIndex] = ox;
    28553                                        }
    28554                                }
    28555                        } else if (as == 1) {
    28556                                if (it.isOutputDouble()) {
    28557                                        while (it.hasNext()) {
    28558                                                final double ix = it.aDouble;
    28559                                                short ox;
    28560                                                ox = (short) toLong(ix);
    28561                                                for (int j = 0; j < is; j++) {
    28562                                                        oai16data[it.oIndex + j] = ox;
    28563                                                }
    28564                                        }
    28565                                } else {
    28566                                        while (it.hasNext()) {
    28567                                                final long ix = it.aLong;
    28568                                                short ox;
    28569                                                ox = (short) toLong(ix);
    28570                                                for (int j = 0; j < is; j++) {
    28571                                                        oai16data[it.oIndex + j] = ox;
    28572                                                }
    28573                                        }
    28574                                }
    28575                        } else {
    28576                                if (it.isOutputDouble()) {
    28577                                        while (it.hasNext()) {
    28578                                                for (int j = 0; j < is; j++) {
    28579                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28580                                                        short ox;
    28581                                                        ox = (short) toLong(ix);
    28582                                                        oai16data[it.oIndex + j] = ox;
    28583                                                }
    28584                                        }
    28585                                } else {
    28586                                        while (it.hasNext()) {
    28587                                                for (int j = 0; j < is; j++) {
    28588                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28589                                                        short ox;
    28590                                                        ox = (short) toLong(ix);
    28591                                                        oai16data[it.oIndex + j] = ox;
    28592                                                }
    28593                                        }
    28594                                }
    28595                        }
    28596                        break;
    28597                case Dataset.ARRAYINT64:
    28598                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    28599                        if (is == 1) {
    28600                                if (it.isOutputDouble()) {
    28601                                        while (it.hasNext()) {
    28602                                                final double ix = it.aDouble;
    28603                                                long ox;
    28604                                                ox = toLong(ix);
    28605                                                oai64data[it.oIndex] = ox;
    28606                                        }
    28607                                } else {
    28608                                        while (it.hasNext()) {
    28609                                                final long ix = it.aLong;
    28610                                                long ox;
    28611                                                ox = toLong(ix);
    28612                                                oai64data[it.oIndex] = ox;
    28613                                        }
    28614                                }
    28615                        } else if (as == 1) {
    28616                                if (it.isOutputDouble()) {
    28617                                        while (it.hasNext()) {
    28618                                                final double ix = it.aDouble;
    28619                                                long ox;
    28620                                                ox = toLong(ix);
    28621                                                for (int j = 0; j < is; j++) {
    28622                                                        oai64data[it.oIndex + j] = ox;
    28623                                                }
    28624                                        }
    28625                                } else {
    28626                                        while (it.hasNext()) {
    28627                                                final long ix = it.aLong;
    28628                                                long ox;
    28629                                                ox = toLong(ix);
    28630                                                for (int j = 0; j < is; j++) {
    28631                                                        oai64data[it.oIndex + j] = ox;
    28632                                                }
    28633                                        }
    28634                                }
    28635                        } else {
    28636                                if (it.isOutputDouble()) {
    28637                                        while (it.hasNext()) {
    28638                                                for (int j = 0; j < is; j++) {
    28639                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28640                                                        long ox;
    28641                                                        ox = toLong(ix);
    28642                                                        oai64data[it.oIndex + j] = ox;
    28643                                                }
    28644                                        }
    28645                                } else {
    28646                                        while (it.hasNext()) {
    28647                                                for (int j = 0; j < is; j++) {
    28648                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28649                                                        long ox;
    28650                                                        ox = toLong(ix);
    28651                                                        oai64data[it.oIndex + j] = ox;
    28652                                                }
    28653                                        }
    28654                                }
    28655                        }
    28656                        break;
    28657                case Dataset.ARRAYINT32:
    28658                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    28659                        if (is == 1) {
    28660                                if (it.isOutputDouble()) {
    28661                                        while (it.hasNext()) {
    28662                                                final double ix = it.aDouble;
    28663                                                int ox;
    28664                                                ox = (int) toLong(ix);
    28665                                                oai32data[it.oIndex] = ox;
    28666                                        }
    28667                                } else {
    28668                                        while (it.hasNext()) {
    28669                                                final long ix = it.aLong;
    28670                                                int ox;
    28671                                                ox = (int) toLong(ix);
    28672                                                oai32data[it.oIndex] = ox;
    28673                                        }
    28674                                }
    28675                        } else if (as == 1) {
    28676                                if (it.isOutputDouble()) {
    28677                                        while (it.hasNext()) {
    28678                                                final double ix = it.aDouble;
    28679                                                int ox;
    28680                                                ox = (int) toLong(ix);
    28681                                                for (int j = 0; j < is; j++) {
    28682                                                        oai32data[it.oIndex + j] = ox;
    28683                                                }
    28684                                        }
    28685                                } else {
    28686                                        while (it.hasNext()) {
    28687                                                final long ix = it.aLong;
    28688                                                int ox;
    28689                                                ox = (int) toLong(ix);
    28690                                                for (int j = 0; j < is; j++) {
    28691                                                        oai32data[it.oIndex + j] = ox;
    28692                                                }
    28693                                        }
    28694                                }
    28695                        } else {
    28696                                if (it.isOutputDouble()) {
    28697                                        while (it.hasNext()) {
    28698                                                for (int j = 0; j < is; j++) {
    28699                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28700                                                        int ox;
    28701                                                        ox = (int) toLong(ix);
    28702                                                        oai32data[it.oIndex + j] = ox;
    28703                                                }
    28704                                        }
    28705                                } else {
    28706                                        while (it.hasNext()) {
    28707                                                for (int j = 0; j < is; j++) {
    28708                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28709                                                        int ox;
    28710                                                        ox = (int) toLong(ix);
    28711                                                        oai32data[it.oIndex + j] = ox;
    28712                                                }
    28713                                        }
    28714                                }
    28715                        }
    28716                        break;
    28717                case Dataset.FLOAT32:
    28718                        final float[] of32data = ((FloatDataset) result).getData();
    28719                        if (it.isOutputDouble()) {
    28720                                while (it.hasNext()) {
    28721                                        final double ix = it.aDouble;
    28722                                        float ox;
    28723                                        ox = (float) (Math.floor(ix));
    28724                                        of32data[it.oIndex] = ox;
    28725                                }
    28726                        } else {
    28727                                while (it.hasNext()) {
    28728                                        final long ix = it.aLong;
    28729                                        float ox;
    28730                                        ox = (float) (Math.floor(ix));
    28731                                        of32data[it.oIndex] = ox;
    28732                                }
    28733                        }
    28734                        break;
    28735                case Dataset.FLOAT64:
    28736                        final double[] of64data = ((DoubleDataset) result).getData();
    28737                        if (it.isOutputDouble()) {
    28738                                while (it.hasNext()) {
    28739                                        final double ix = it.aDouble;
    28740                                        double ox;
    28741                                        ox = (Math.floor(ix));
    28742                                        of64data[it.oIndex] = ox;
    28743                                }
    28744                        } else {
    28745                                while (it.hasNext()) {
    28746                                        final long ix = it.aLong;
    28747                                        double ox;
    28748                                        ox = (Math.floor(ix));
    28749                                        of64data[it.oIndex] = ox;
    28750                                }
    28751                        }
    28752                        break;
    28753                case Dataset.ARRAYFLOAT32:
    28754                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    28755                        if (is == 1) {
    28756                                if (it.isOutputDouble()) {
    28757                                        while (it.hasNext()) {
    28758                                                final double ix = it.aDouble;
    28759                                                float ox;
    28760                                                ox = (float) (Math.floor(ix));
    28761                                                oaf32data[it.oIndex] = ox;
    28762                                        }
    28763                                } else {
    28764                                        while (it.hasNext()) {
    28765                                                final long ix = it.aLong;
    28766                                                float ox;
    28767                                                ox = (float) (Math.floor(ix));
    28768                                                oaf32data[it.oIndex] = ox;
    28769                                        }
    28770                                }
    28771                        } else if (as == 1) {
    28772                                if (it.isOutputDouble()) {
    28773                                        while (it.hasNext()) {
    28774                                                final double ix = it.aDouble;
    28775                                                float ox;
    28776                                                ox = (float) (Math.floor(ix));
    28777                                                for (int j = 0; j < is; j++) {
    28778                                                        oaf32data[it.oIndex + j] = ox;
    28779                                                }
    28780                                        }
    28781                                } else {
    28782                                        while (it.hasNext()) {
    28783                                                final long ix = it.aLong;
    28784                                                float ox;
    28785                                                ox = (float) (Math.floor(ix));
    28786                                                for (int j = 0; j < is; j++) {
    28787                                                        oaf32data[it.oIndex + j] = ox;
    28788                                                }
    28789                                        }
    28790                                }
    28791                        } else {
    28792                                if (it.isOutputDouble()) {
    28793                                        while (it.hasNext()) {
    28794                                                for (int j = 0; j < is; j++) {
    28795                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28796                                                        float ox;
    28797                                                        ox = (float) (Math.floor(ix));
    28798                                                        oaf32data[it.oIndex + j] = ox;
    28799                                                }
    28800                                        }
    28801                                } else {
    28802                                        while (it.hasNext()) {
    28803                                                for (int j = 0; j < is; j++) {
    28804                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28805                                                        float ox;
    28806                                                        ox = (float) (Math.floor(ix));
    28807                                                        oaf32data[it.oIndex + j] = ox;
    28808                                                }
    28809                                        }
    28810                                }
    28811                        }
    28812                        break;
    28813                case Dataset.ARRAYFLOAT64:
    28814                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    28815                        if (is == 1) {
    28816                                if (it.isOutputDouble()) {
    28817                                        while (it.hasNext()) {
    28818                                                final double ix = it.aDouble;
    28819                                                double ox;
    28820                                                ox = (Math.floor(ix));
    28821                                                oaf64data[it.oIndex] = ox;
    28822                                        }
    28823                                } else {
    28824                                        while (it.hasNext()) {
    28825                                                final long ix = it.aLong;
    28826                                                double ox;
    28827                                                ox = (Math.floor(ix));
    28828                                                oaf64data[it.oIndex] = ox;
    28829                                        }
    28830                                }
    28831                        } else if (as == 1) {
    28832                                if (it.isOutputDouble()) {
    28833                                        while (it.hasNext()) {
    28834                                                final double ix = it.aDouble;
    28835                                                double ox;
    28836                                                ox = (Math.floor(ix));
    28837                                                for (int j = 0; j < is; j++) {
    28838                                                        oaf64data[it.oIndex + j] = ox;
    28839                                                }
    28840                                        }
    28841                                } else {
    28842                                        while (it.hasNext()) {
    28843                                                final long ix = it.aLong;
    28844                                                double ox;
    28845                                                ox = (Math.floor(ix));
    28846                                                for (int j = 0; j < is; j++) {
    28847                                                        oaf64data[it.oIndex + j] = ox;
    28848                                                }
    28849                                        }
    28850                                }
    28851                        } else {
    28852                                if (it.isOutputDouble()) {
    28853                                        while (it.hasNext()) {
    28854                                                for (int j = 0; j < is; j++) {
    28855                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    28856                                                        double ox;
    28857                                                        ox = (Math.floor(ix));
    28858                                                        oaf64data[it.oIndex + j] = ox;
    28859                                                }
    28860                                        }
    28861                                } else {
    28862                                        while (it.hasNext()) {
    28863                                                for (int j = 0; j < is; j++) {
    28864                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    28865                                                        double ox;
    28866                                                        ox = (Math.floor(ix));
    28867                                                        oaf64data[it.oIndex + j] = ox;
    28868                                                }
    28869                                        }
    28870                                }
    28871                        }
    28872                        break;
    28873                case Dataset.COMPLEX64:
    28874                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    28875                        if (as == 1) {
    28876                                final double iy = 0;
    28877                                while (it.hasNext()) {
    28878                                        final double ix = it.aDouble;
    28879                                        float ox;
    28880                                        float oy;
    28881                                        ox = (float) (Math.floor(ix));
    28882                                        oy = (float) (Math.floor(iy));
    28883                                        oc64data[it.oIndex] = ox;
    28884                                        oc64data[it.oIndex + 1] = oy;
    28885                                }
    28886                        } else {
    28887                                while (it.hasNext()) {
    28888                                        final double ix = it.aDouble;
    28889                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    28890                                        float ox;
    28891                                        float oy;
    28892                                        ox = (float) (Math.floor(ix));
    28893                                        oy = (float) (Math.floor(iy));
    28894                                        oc64data[it.oIndex] = ox;
    28895                                        oc64data[it.oIndex + 1] = oy;
    28896                                }
    28897                        }
    28898                        break;
    28899                case Dataset.COMPLEX128:
    28900                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    28901                        if (as == 1) {
    28902                                final double iy = 0;
    28903                                while (it.hasNext()) {
    28904                                        final double ix = it.aDouble;
    28905                                        double ox;
    28906                                        double oy;
    28907                                        ox = (Math.floor(ix));
    28908                                        oy = (Math.floor(iy));
    28909                                        oc128data[it.oIndex] = ox;
    28910                                        oc128data[it.oIndex + 1] = oy;
    28911                                }
    28912                        } else {
    28913                                while (it.hasNext()) {
    28914                                        final double ix = it.aDouble;
    28915                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    28916                                        double ox;
    28917                                        double oy;
    28918                                        ox = (Math.floor(ix));
    28919                                        oy = (Math.floor(iy));
    28920                                        oc128data[it.oIndex] = ox;
    28921                                        oc128data[it.oIndex + 1] = oy;
    28922                                }
    28923                        }
    28924                        break;
    28925                default:
    28926                        throw new IllegalArgumentException("floor supports integer, compound integer, real, compound real, complex datasets only");
    28927                }
    28928
    28929                addFunctionName(result, "floor");
    28930                return result;
    28931        }
    28932
    28933        /**
    28934         * ceil - evaluate the ceiling function on each element of the dataset
    28935         * @param a
    28936         * @return dataset
    28937         */
    28938        public static Dataset ceil(final Object a) {
    28939                return ceil(a, null);
    28940        }
    28941
    28942        /**
    28943         * ceil - evaluate the ceiling function on each element of the dataset
    28944         * @param a
    28945         * @param o output can be null - in which case, a new dataset is created
    28946         * @return dataset
    28947         */
    28948        public static Dataset ceil(final Object a, final Dataset o) {
    28949                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    28950                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    28951                final Dataset result = it.getOutput();
    28952                final int is = result.getElementsPerItem();
    28953                final int as = da.getElementsPerItem();
    28954                final int dt = result.getDType();
    28955
    28956                switch(dt) {
    28957                case Dataset.INT8:
    28958                        final byte[] oi8data = ((ByteDataset) result).getData();
    28959                        if (it.isOutputDouble()) {
    28960                                while (it.hasNext()) {
    28961                                        final double ix = it.aDouble;
    28962                                        byte ox;
    28963                                        ox = (byte) toLong(ix);
    28964                                        oi8data[it.oIndex] = ox;
    28965                                }
    28966                        } else {
    28967                                while (it.hasNext()) {
    28968                                        final long ix = it.aLong;
    28969                                        byte ox;
    28970                                        ox = (byte) toLong(ix);
    28971                                        oi8data[it.oIndex] = ox;
    28972                                }
    28973                        }
    28974                        break;
    28975                case Dataset.INT16:
    28976                        final short[] oi16data = ((ShortDataset) result).getData();
    28977                        if (it.isOutputDouble()) {
    28978                                while (it.hasNext()) {
    28979                                        final double ix = it.aDouble;
    28980                                        short ox;
    28981                                        ox = (short) toLong(ix);
    28982                                        oi16data[it.oIndex] = ox;
    28983                                }
    28984                        } else {
    28985                                while (it.hasNext()) {
    28986                                        final long ix = it.aLong;
    28987                                        short ox;
    28988                                        ox = (short) toLong(ix);
    28989                                        oi16data[it.oIndex] = ox;
    28990                                }
    28991                        }
    28992                        break;
    28993                case Dataset.INT64:
    28994                        final long[] oi64data = ((LongDataset) result).getData();
    28995                        if (it.isOutputDouble()) {
    28996                                while (it.hasNext()) {
    28997                                        final double ix = it.aDouble;
    28998                                        long ox;
    28999                                        ox = toLong(ix);
    29000                                        oi64data[it.oIndex] = ox;
    29001                                }
    29002                        } else {
    29003                                while (it.hasNext()) {
    29004                                        final long ix = it.aLong;
    29005                                        long ox;
    29006                                        ox = toLong(ix);
    29007                                        oi64data[it.oIndex] = ox;
    29008                                }
    29009                        }
    29010                        break;
    29011                case Dataset.INT32:
    29012                        final int[] oi32data = ((IntegerDataset) result).getData();
    29013                        if (it.isOutputDouble()) {
    29014                                while (it.hasNext()) {
    29015                                        final double ix = it.aDouble;
    29016                                        int ox;
    29017                                        ox = (int) toLong(ix);
    29018                                        oi32data[it.oIndex] = ox;
    29019                                }
    29020                        } else {
    29021                                while (it.hasNext()) {
    29022                                        final long ix = it.aLong;
    29023                                        int ox;
    29024                                        ox = (int) toLong(ix);
    29025                                        oi32data[it.oIndex] = ox;
    29026                                }
    29027                        }
    29028                        break;
    29029                case Dataset.ARRAYINT8:
    29030                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    29031                        if (is == 1) {
    29032                                if (it.isOutputDouble()) {
    29033                                        while (it.hasNext()) {
    29034                                                final double ix = it.aDouble;
    29035                                                byte ox;
    29036                                                ox = (byte) toLong(ix);
    29037                                                oai8data[it.oIndex] = ox;
    29038                                        }
    29039                                } else {
    29040                                        while (it.hasNext()) {
    29041                                                final long ix = it.aLong;
    29042                                                byte ox;
    29043                                                ox = (byte) toLong(ix);
    29044                                                oai8data[it.oIndex] = ox;
    29045                                        }
    29046                                }
    29047                        } else if (as == 1) {
    29048                                if (it.isOutputDouble()) {
    29049                                        while (it.hasNext()) {
    29050                                                final double ix = it.aDouble;
    29051                                                byte ox;
    29052                                                ox = (byte) toLong(ix);
    29053                                                for (int j = 0; j < is; j++) {
    29054                                                        oai8data[it.oIndex + j] = ox;
    29055                                                }
    29056                                        }
    29057                                } else {
    29058                                        while (it.hasNext()) {
    29059                                                final long ix = it.aLong;
    29060                                                byte ox;
    29061                                                ox = (byte) toLong(ix);
    29062                                                for (int j = 0; j < is; j++) {
    29063                                                        oai8data[it.oIndex + j] = ox;
    29064                                                }
    29065                                        }
    29066                                }
    29067                        } else {
    29068                                if (it.isOutputDouble()) {
    29069                                        while (it.hasNext()) {
    29070                                                for (int j = 0; j < is; j++) {
    29071                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29072                                                        byte ox;
    29073                                                        ox = (byte) toLong(ix);
    29074                                                        oai8data[it.oIndex + j] = ox;
    29075                                                }
    29076                                        }
    29077                                } else {
    29078                                        while (it.hasNext()) {
    29079                                                for (int j = 0; j < is; j++) {
    29080                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29081                                                        byte ox;
    29082                                                        ox = (byte) toLong(ix);
    29083                                                        oai8data[it.oIndex + j] = ox;
    29084                                                }
    29085                                        }
    29086                                }
    29087                        }
    29088                        break;
    29089                case Dataset.ARRAYINT16:
    29090                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    29091                        if (is == 1) {
    29092                                if (it.isOutputDouble()) {
    29093                                        while (it.hasNext()) {
    29094                                                final double ix = it.aDouble;
    29095                                                short ox;
    29096                                                ox = (short) toLong(ix);
    29097                                                oai16data[it.oIndex] = ox;
    29098                                        }
    29099                                } else {
    29100                                        while (it.hasNext()) {
    29101                                                final long ix = it.aLong;
    29102                                                short ox;
    29103                                                ox = (short) toLong(ix);
    29104                                                oai16data[it.oIndex] = ox;
    29105                                        }
    29106                                }
    29107                        } else if (as == 1) {
    29108                                if (it.isOutputDouble()) {
    29109                                        while (it.hasNext()) {
    29110                                                final double ix = it.aDouble;
    29111                                                short ox;
    29112                                                ox = (short) toLong(ix);
    29113                                                for (int j = 0; j < is; j++) {
    29114                                                        oai16data[it.oIndex + j] = ox;
    29115                                                }
    29116                                        }
    29117                                } else {
    29118                                        while (it.hasNext()) {
    29119                                                final long ix = it.aLong;
    29120                                                short ox;
    29121                                                ox = (short) toLong(ix);
    29122                                                for (int j = 0; j < is; j++) {
    29123                                                        oai16data[it.oIndex + j] = ox;
    29124                                                }
    29125                                        }
    29126                                }
    29127                        } else {
    29128                                if (it.isOutputDouble()) {
    29129                                        while (it.hasNext()) {
    29130                                                for (int j = 0; j < is; j++) {
    29131                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29132                                                        short ox;
    29133                                                        ox = (short) toLong(ix);
    29134                                                        oai16data[it.oIndex + j] = ox;
    29135                                                }
    29136                                        }
    29137                                } else {
    29138                                        while (it.hasNext()) {
    29139                                                for (int j = 0; j < is; j++) {
    29140                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29141                                                        short ox;
    29142                                                        ox = (short) toLong(ix);
    29143                                                        oai16data[it.oIndex + j] = ox;
    29144                                                }
    29145                                        }
    29146                                }
    29147                        }
    29148                        break;
    29149                case Dataset.ARRAYINT64:
    29150                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    29151                        if (is == 1) {
    29152                                if (it.isOutputDouble()) {
    29153                                        while (it.hasNext()) {
    29154                                                final double ix = it.aDouble;
    29155                                                long ox;
    29156                                                ox = toLong(ix);
    29157                                                oai64data[it.oIndex] = ox;
    29158                                        }
    29159                                } else {
    29160                                        while (it.hasNext()) {
    29161                                                final long ix = it.aLong;
    29162                                                long ox;
    29163                                                ox = toLong(ix);
    29164                                                oai64data[it.oIndex] = ox;
    29165                                        }
    29166                                }
    29167                        } else if (as == 1) {
    29168                                if (it.isOutputDouble()) {
    29169                                        while (it.hasNext()) {
    29170                                                final double ix = it.aDouble;
    29171                                                long ox;
    29172                                                ox = toLong(ix);
    29173                                                for (int j = 0; j < is; j++) {
    29174                                                        oai64data[it.oIndex + j] = ox;
    29175                                                }
    29176                                        }
    29177                                } else {
    29178                                        while (it.hasNext()) {
    29179                                                final long ix = it.aLong;
    29180                                                long ox;
    29181                                                ox = toLong(ix);
    29182                                                for (int j = 0; j < is; j++) {
    29183                                                        oai64data[it.oIndex + j] = ox;
    29184                                                }
    29185                                        }
    29186                                }
    29187                        } else {
    29188                                if (it.isOutputDouble()) {
    29189                                        while (it.hasNext()) {
    29190                                                for (int j = 0; j < is; j++) {
    29191                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29192                                                        long ox;
    29193                                                        ox = toLong(ix);
    29194                                                        oai64data[it.oIndex + j] = ox;
    29195                                                }
    29196                                        }
    29197                                } else {
    29198                                        while (it.hasNext()) {
    29199                                                for (int j = 0; j < is; j++) {
    29200                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29201                                                        long ox;
    29202                                                        ox = toLong(ix);
    29203                                                        oai64data[it.oIndex + j] = ox;
    29204                                                }
    29205                                        }
    29206                                }
    29207                        }
    29208                        break;
    29209                case Dataset.ARRAYINT32:
    29210                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    29211                        if (is == 1) {
    29212                                if (it.isOutputDouble()) {
    29213                                        while (it.hasNext()) {
    29214                                                final double ix = it.aDouble;
    29215                                                int ox;
    29216                                                ox = (int) toLong(ix);
    29217                                                oai32data[it.oIndex] = ox;
    29218                                        }
    29219                                } else {
    29220                                        while (it.hasNext()) {
    29221                                                final long ix = it.aLong;
    29222                                                int ox;
    29223                                                ox = (int) toLong(ix);
    29224                                                oai32data[it.oIndex] = ox;
    29225                                        }
    29226                                }
    29227                        } else if (as == 1) {
    29228                                if (it.isOutputDouble()) {
    29229                                        while (it.hasNext()) {
    29230                                                final double ix = it.aDouble;
    29231                                                int ox;
    29232                                                ox = (int) toLong(ix);
    29233                                                for (int j = 0; j < is; j++) {
    29234                                                        oai32data[it.oIndex + j] = ox;
    29235                                                }
    29236                                        }
    29237                                } else {
    29238                                        while (it.hasNext()) {
    29239                                                final long ix = it.aLong;
    29240                                                int ox;
    29241                                                ox = (int) toLong(ix);
    29242                                                for (int j = 0; j < is; j++) {
    29243                                                        oai32data[it.oIndex + j] = ox;
    29244                                                }
    29245                                        }
    29246                                }
    29247                        } else {
    29248                                if (it.isOutputDouble()) {
    29249                                        while (it.hasNext()) {
    29250                                                for (int j = 0; j < is; j++) {
    29251                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29252                                                        int ox;
    29253                                                        ox = (int) toLong(ix);
    29254                                                        oai32data[it.oIndex + j] = ox;
    29255                                                }
    29256                                        }
    29257                                } else {
    29258                                        while (it.hasNext()) {
    29259                                                for (int j = 0; j < is; j++) {
    29260                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29261                                                        int ox;
    29262                                                        ox = (int) toLong(ix);
    29263                                                        oai32data[it.oIndex + j] = ox;
    29264                                                }
    29265                                        }
    29266                                }
    29267                        }
    29268                        break;
    29269                case Dataset.FLOAT32:
    29270                        final float[] of32data = ((FloatDataset) result).getData();
    29271                        if (it.isOutputDouble()) {
    29272                                while (it.hasNext()) {
    29273                                        final double ix = it.aDouble;
    29274                                        float ox;
    29275                                        ox = (float) (Math.ceil(ix));
    29276                                        of32data[it.oIndex] = ox;
    29277                                }
    29278                        } else {
    29279                                while (it.hasNext()) {
    29280                                        final long ix = it.aLong;
    29281                                        float ox;
    29282                                        ox = (float) (Math.ceil(ix));
    29283                                        of32data[it.oIndex] = ox;
    29284                                }
    29285                        }
    29286                        break;
    29287                case Dataset.FLOAT64:
    29288                        final double[] of64data = ((DoubleDataset) result).getData();
    29289                        if (it.isOutputDouble()) {
    29290                                while (it.hasNext()) {
    29291                                        final double ix = it.aDouble;
    29292                                        double ox;
    29293                                        ox = (Math.ceil(ix));
    29294                                        of64data[it.oIndex] = ox;
    29295                                }
    29296                        } else {
    29297                                while (it.hasNext()) {
    29298                                        final long ix = it.aLong;
    29299                                        double ox;
    29300                                        ox = (Math.ceil(ix));
    29301                                        of64data[it.oIndex] = ox;
    29302                                }
    29303                        }
    29304                        break;
    29305                case Dataset.ARRAYFLOAT32:
    29306                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    29307                        if (is == 1) {
    29308                                if (it.isOutputDouble()) {
    29309                                        while (it.hasNext()) {
    29310                                                final double ix = it.aDouble;
    29311                                                float ox;
    29312                                                ox = (float) (Math.ceil(ix));
    29313                                                oaf32data[it.oIndex] = ox;
    29314                                        }
    29315                                } else {
    29316                                        while (it.hasNext()) {
    29317                                                final long ix = it.aLong;
    29318                                                float ox;
    29319                                                ox = (float) (Math.ceil(ix));
    29320                                                oaf32data[it.oIndex] = ox;
    29321                                        }
    29322                                }
    29323                        } else if (as == 1) {
    29324                                if (it.isOutputDouble()) {
    29325                                        while (it.hasNext()) {
    29326                                                final double ix = it.aDouble;
    29327                                                float ox;
    29328                                                ox = (float) (Math.ceil(ix));
    29329                                                for (int j = 0; j < is; j++) {
    29330                                                        oaf32data[it.oIndex + j] = ox;
    29331                                                }
    29332                                        }
    29333                                } else {
    29334                                        while (it.hasNext()) {
    29335                                                final long ix = it.aLong;
    29336                                                float ox;
    29337                                                ox = (float) (Math.ceil(ix));
    29338                                                for (int j = 0; j < is; j++) {
    29339                                                        oaf32data[it.oIndex + j] = ox;
    29340                                                }
    29341                                        }
    29342                                }
    29343                        } else {
    29344                                if (it.isOutputDouble()) {
    29345                                        while (it.hasNext()) {
    29346                                                for (int j = 0; j < is; j++) {
    29347                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29348                                                        float ox;
    29349                                                        ox = (float) (Math.ceil(ix));
    29350                                                        oaf32data[it.oIndex + j] = ox;
    29351                                                }
    29352                                        }
    29353                                } else {
    29354                                        while (it.hasNext()) {
    29355                                                for (int j = 0; j < is; j++) {
    29356                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29357                                                        float ox;
    29358                                                        ox = (float) (Math.ceil(ix));
    29359                                                        oaf32data[it.oIndex + j] = ox;
    29360                                                }
    29361                                        }
    29362                                }
    29363                        }
    29364                        break;
    29365                case Dataset.ARRAYFLOAT64:
    29366                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    29367                        if (is == 1) {
    29368                                if (it.isOutputDouble()) {
    29369                                        while (it.hasNext()) {
    29370                                                final double ix = it.aDouble;
    29371                                                double ox;
    29372                                                ox = (Math.ceil(ix));
    29373                                                oaf64data[it.oIndex] = ox;
    29374                                        }
    29375                                } else {
    29376                                        while (it.hasNext()) {
    29377                                                final long ix = it.aLong;
    29378                                                double ox;
    29379                                                ox = (Math.ceil(ix));
    29380                                                oaf64data[it.oIndex] = ox;
    29381                                        }
    29382                                }
    29383                        } else if (as == 1) {
    29384                                if (it.isOutputDouble()) {
    29385                                        while (it.hasNext()) {
    29386                                                final double ix = it.aDouble;
    29387                                                double ox;
    29388                                                ox = (Math.ceil(ix));
    29389                                                for (int j = 0; j < is; j++) {
    29390                                                        oaf64data[it.oIndex + j] = ox;
    29391                                                }
    29392                                        }
    29393                                } else {
    29394                                        while (it.hasNext()) {
    29395                                                final long ix = it.aLong;
    29396                                                double ox;
    29397                                                ox = (Math.ceil(ix));
    29398                                                for (int j = 0; j < is; j++) {
    29399                                                        oaf64data[it.oIndex + j] = ox;
    29400                                                }
    29401                                        }
    29402                                }
    29403                        } else {
    29404                                if (it.isOutputDouble()) {
    29405                                        while (it.hasNext()) {
    29406                                                for (int j = 0; j < is; j++) {
    29407                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29408                                                        double ox;
    29409                                                        ox = (Math.ceil(ix));
    29410                                                        oaf64data[it.oIndex + j] = ox;
    29411                                                }
    29412                                        }
    29413                                } else {
    29414                                        while (it.hasNext()) {
    29415                                                for (int j = 0; j < is; j++) {
    29416                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29417                                                        double ox;
    29418                                                        ox = (Math.ceil(ix));
    29419                                                        oaf64data[it.oIndex + j] = ox;
    29420                                                }
    29421                                        }
    29422                                }
    29423                        }
    29424                        break;
    29425                case Dataset.COMPLEX64:
    29426                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    29427                        if (as == 1) {
    29428                                final double iy = 0;
    29429                                while (it.hasNext()) {
    29430                                        final double ix = it.aDouble;
    29431                                        float ox;
    29432                                        float oy;
    29433                                        ox = (float) (Math.ceil(ix));
    29434                                        oy = (float) (Math.ceil(iy));
    29435                                        oc64data[it.oIndex] = ox;
    29436                                        oc64data[it.oIndex + 1] = oy;
    29437                                }
    29438                        } else {
    29439                                while (it.hasNext()) {
    29440                                        final double ix = it.aDouble;
    29441                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    29442                                        float ox;
    29443                                        float oy;
    29444                                        ox = (float) (Math.ceil(ix));
    29445                                        oy = (float) (Math.ceil(iy));
    29446                                        oc64data[it.oIndex] = ox;
    29447                                        oc64data[it.oIndex + 1] = oy;
    29448                                }
    29449                        }
    29450                        break;
    29451                case Dataset.COMPLEX128:
    29452                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    29453                        if (as == 1) {
    29454                                final double iy = 0;
    29455                                while (it.hasNext()) {
    29456                                        final double ix = it.aDouble;
    29457                                        double ox;
    29458                                        double oy;
    29459                                        ox = (Math.ceil(ix));
    29460                                        oy = (Math.ceil(iy));
    29461                                        oc128data[it.oIndex] = ox;
    29462                                        oc128data[it.oIndex + 1] = oy;
    29463                                }
    29464                        } else {
    29465                                while (it.hasNext()) {
    29466                                        final double ix = it.aDouble;
    29467                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    29468                                        double ox;
    29469                                        double oy;
    29470                                        ox = (Math.ceil(ix));
    29471                                        oy = (Math.ceil(iy));
    29472                                        oc128data[it.oIndex] = ox;
    29473                                        oc128data[it.oIndex + 1] = oy;
    29474                                }
    29475                        }
    29476                        break;
    29477                default:
    29478                        throw new IllegalArgumentException("ceil supports integer, compound integer, real, compound real, complex datasets only");
    29479                }
    29480
    29481                addFunctionName(result, "ceil");
    29482                return result;
    29483        }
    29484
    29485        /**
    29486         * rint - round each element of the dataset
    29487         * @param a
    29488         * @return dataset
    29489         */
    29490        public static Dataset rint(final Object a) {
    29491                return rint(a, null);
    29492        }
    29493
    29494        /**
    29495         * rint - round each element of the dataset
    29496         * @param a
    29497         * @param o output can be null - in which case, a new dataset is created
    29498         * @return dataset
    29499         */
    29500        public static Dataset rint(final Object a, final Dataset o) {
    29501                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    29502                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    29503                final Dataset result = it.getOutput();
    29504                final int is = result.getElementsPerItem();
    29505                final int as = da.getElementsPerItem();
    29506                final int dt = result.getDType();
    29507
    29508                switch(dt) {
    29509                case Dataset.INT8:
    29510                        final byte[] oi8data = ((ByteDataset) result).getData();
    29511                        if (it.isOutputDouble()) {
    29512                                while (it.hasNext()) {
    29513                                        final double ix = it.aDouble;
    29514                                        byte ox;
    29515                                        ox = (byte) toLong(ix);
    29516                                        oi8data[it.oIndex] = ox;
    29517                                }
    29518                        } else {
    29519                                while (it.hasNext()) {
    29520                                        final long ix = it.aLong;
    29521                                        byte ox;
    29522                                        ox = (byte) toLong(ix);
    29523                                        oi8data[it.oIndex] = ox;
    29524                                }
    29525                        }
    29526                        break;
    29527                case Dataset.INT16:
    29528                        final short[] oi16data = ((ShortDataset) result).getData();
    29529                        if (it.isOutputDouble()) {
    29530                                while (it.hasNext()) {
    29531                                        final double ix = it.aDouble;
    29532                                        short ox;
    29533                                        ox = (short) toLong(ix);
    29534                                        oi16data[it.oIndex] = ox;
    29535                                }
    29536                        } else {
    29537                                while (it.hasNext()) {
    29538                                        final long ix = it.aLong;
    29539                                        short ox;
    29540                                        ox = (short) toLong(ix);
    29541                                        oi16data[it.oIndex] = ox;
    29542                                }
    29543                        }
    29544                        break;
    29545                case Dataset.INT64:
    29546                        final long[] oi64data = ((LongDataset) result).getData();
    29547                        if (it.isOutputDouble()) {
    29548                                while (it.hasNext()) {
    29549                                        final double ix = it.aDouble;
    29550                                        long ox;
    29551                                        ox = toLong(ix);
    29552                                        oi64data[it.oIndex] = ox;
    29553                                }
    29554                        } else {
    29555                                while (it.hasNext()) {
    29556                                        final long ix = it.aLong;
    29557                                        long ox;
    29558                                        ox = toLong(ix);
    29559                                        oi64data[it.oIndex] = ox;
    29560                                }
    29561                        }
    29562                        break;
    29563                case Dataset.INT32:
    29564                        final int[] oi32data = ((IntegerDataset) result).getData();
    29565                        if (it.isOutputDouble()) {
    29566                                while (it.hasNext()) {
    29567                                        final double ix = it.aDouble;
    29568                                        int ox;
    29569                                        ox = (int) toLong(ix);
    29570                                        oi32data[it.oIndex] = ox;
    29571                                }
    29572                        } else {
    29573                                while (it.hasNext()) {
    29574                                        final long ix = it.aLong;
    29575                                        int ox;
    29576                                        ox = (int) toLong(ix);
    29577                                        oi32data[it.oIndex] = ox;
    29578                                }
    29579                        }
    29580                        break;
    29581                case Dataset.ARRAYINT8:
    29582                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    29583                        if (is == 1) {
    29584                                if (it.isOutputDouble()) {
    29585                                        while (it.hasNext()) {
    29586                                                final double ix = it.aDouble;
    29587                                                byte ox;
    29588                                                ox = (byte) toLong(ix);
    29589                                                oai8data[it.oIndex] = ox;
    29590                                        }
    29591                                } else {
    29592                                        while (it.hasNext()) {
    29593                                                final long ix = it.aLong;
    29594                                                byte ox;
    29595                                                ox = (byte) toLong(ix);
    29596                                                oai8data[it.oIndex] = ox;
    29597                                        }
    29598                                }
    29599                        } else if (as == 1) {
    29600                                if (it.isOutputDouble()) {
    29601                                        while (it.hasNext()) {
    29602                                                final double ix = it.aDouble;
    29603                                                byte ox;
    29604                                                ox = (byte) toLong(ix);
    29605                                                for (int j = 0; j < is; j++) {
    29606                                                        oai8data[it.oIndex + j] = ox;
    29607                                                }
    29608                                        }
    29609                                } else {
    29610                                        while (it.hasNext()) {
    29611                                                final long ix = it.aLong;
    29612                                                byte ox;
    29613                                                ox = (byte) toLong(ix);
    29614                                                for (int j = 0; j < is; j++) {
    29615                                                        oai8data[it.oIndex + j] = ox;
    29616                                                }
    29617                                        }
    29618                                }
    29619                        } else {
    29620                                if (it.isOutputDouble()) {
    29621                                        while (it.hasNext()) {
    29622                                                for (int j = 0; j < is; j++) {
    29623                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29624                                                        byte ox;
    29625                                                        ox = (byte) toLong(ix);
    29626                                                        oai8data[it.oIndex + j] = ox;
    29627                                                }
    29628                                        }
    29629                                } else {
    29630                                        while (it.hasNext()) {
    29631                                                for (int j = 0; j < is; j++) {
    29632                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29633                                                        byte ox;
    29634                                                        ox = (byte) toLong(ix);
    29635                                                        oai8data[it.oIndex + j] = ox;
    29636                                                }
    29637                                        }
    29638                                }
    29639                        }
    29640                        break;
    29641                case Dataset.ARRAYINT16:
    29642                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    29643                        if (is == 1) {
    29644                                if (it.isOutputDouble()) {
    29645                                        while (it.hasNext()) {
    29646                                                final double ix = it.aDouble;
    29647                                                short ox;
    29648                                                ox = (short) toLong(ix);
    29649                                                oai16data[it.oIndex] = ox;
    29650                                        }
    29651                                } else {
    29652                                        while (it.hasNext()) {
    29653                                                final long ix = it.aLong;
    29654                                                short ox;
    29655                                                ox = (short) toLong(ix);
    29656                                                oai16data[it.oIndex] = ox;
    29657                                        }
    29658                                }
    29659                        } else if (as == 1) {
    29660                                if (it.isOutputDouble()) {
    29661                                        while (it.hasNext()) {
    29662                                                final double ix = it.aDouble;
    29663                                                short ox;
    29664                                                ox = (short) toLong(ix);
    29665                                                for (int j = 0; j < is; j++) {
    29666                                                        oai16data[it.oIndex + j] = ox;
    29667                                                }
    29668                                        }
    29669                                } else {
    29670                                        while (it.hasNext()) {
    29671                                                final long ix = it.aLong;
    29672                                                short ox;
    29673                                                ox = (short) toLong(ix);
    29674                                                for (int j = 0; j < is; j++) {
    29675                                                        oai16data[it.oIndex + j] = ox;
    29676                                                }
    29677                                        }
    29678                                }
    29679                        } else {
    29680                                if (it.isOutputDouble()) {
    29681                                        while (it.hasNext()) {
    29682                                                for (int j = 0; j < is; j++) {
    29683                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29684                                                        short ox;
    29685                                                        ox = (short) toLong(ix);
    29686                                                        oai16data[it.oIndex + j] = ox;
    29687                                                }
    29688                                        }
    29689                                } else {
    29690                                        while (it.hasNext()) {
    29691                                                for (int j = 0; j < is; j++) {
    29692                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29693                                                        short ox;
    29694                                                        ox = (short) toLong(ix);
    29695                                                        oai16data[it.oIndex + j] = ox;
    29696                                                }
    29697                                        }
    29698                                }
    29699                        }
    29700                        break;
    29701                case Dataset.ARRAYINT64:
    29702                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    29703                        if (is == 1) {
    29704                                if (it.isOutputDouble()) {
    29705                                        while (it.hasNext()) {
    29706                                                final double ix = it.aDouble;
    29707                                                long ox;
    29708                                                ox = toLong(ix);
    29709                                                oai64data[it.oIndex] = ox;
    29710                                        }
    29711                                } else {
    29712                                        while (it.hasNext()) {
    29713                                                final long ix = it.aLong;
    29714                                                long ox;
    29715                                                ox = toLong(ix);
    29716                                                oai64data[it.oIndex] = ox;
    29717                                        }
    29718                                }
    29719                        } else if (as == 1) {
    29720                                if (it.isOutputDouble()) {
    29721                                        while (it.hasNext()) {
    29722                                                final double ix = it.aDouble;
    29723                                                long ox;
    29724                                                ox = toLong(ix);
    29725                                                for (int j = 0; j < is; j++) {
    29726                                                        oai64data[it.oIndex + j] = ox;
    29727                                                }
    29728                                        }
    29729                                } else {
    29730                                        while (it.hasNext()) {
    29731                                                final long ix = it.aLong;
    29732                                                long ox;
    29733                                                ox = toLong(ix);
    29734                                                for (int j = 0; j < is; j++) {
    29735                                                        oai64data[it.oIndex + j] = ox;
    29736                                                }
    29737                                        }
    29738                                }
    29739                        } else {
    29740                                if (it.isOutputDouble()) {
    29741                                        while (it.hasNext()) {
    29742                                                for (int j = 0; j < is; j++) {
    29743                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29744                                                        long ox;
    29745                                                        ox = toLong(ix);
    29746                                                        oai64data[it.oIndex + j] = ox;
    29747                                                }
    29748                                        }
    29749                                } else {
    29750                                        while (it.hasNext()) {
    29751                                                for (int j = 0; j < is; j++) {
    29752                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29753                                                        long ox;
    29754                                                        ox = toLong(ix);
    29755                                                        oai64data[it.oIndex + j] = ox;
    29756                                                }
    29757                                        }
    29758                                }
    29759                        }
    29760                        break;
    29761                case Dataset.ARRAYINT32:
    29762                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    29763                        if (is == 1) {
    29764                                if (it.isOutputDouble()) {
    29765                                        while (it.hasNext()) {
    29766                                                final double ix = it.aDouble;
    29767                                                int ox;
    29768                                                ox = (int) toLong(ix);
    29769                                                oai32data[it.oIndex] = ox;
    29770                                        }
    29771                                } else {
    29772                                        while (it.hasNext()) {
    29773                                                final long ix = it.aLong;
    29774                                                int ox;
    29775                                                ox = (int) toLong(ix);
    29776                                                oai32data[it.oIndex] = ox;
    29777                                        }
    29778                                }
    29779                        } else if (as == 1) {
    29780                                if (it.isOutputDouble()) {
    29781                                        while (it.hasNext()) {
    29782                                                final double ix = it.aDouble;
    29783                                                int ox;
    29784                                                ox = (int) toLong(ix);
    29785                                                for (int j = 0; j < is; j++) {
    29786                                                        oai32data[it.oIndex + j] = ox;
    29787                                                }
    29788                                        }
    29789                                } else {
    29790                                        while (it.hasNext()) {
    29791                                                final long ix = it.aLong;
    29792                                                int ox;
    29793                                                ox = (int) toLong(ix);
    29794                                                for (int j = 0; j < is; j++) {
    29795                                                        oai32data[it.oIndex + j] = ox;
    29796                                                }
    29797                                        }
    29798                                }
    29799                        } else {
    29800                                if (it.isOutputDouble()) {
    29801                                        while (it.hasNext()) {
    29802                                                for (int j = 0; j < is; j++) {
    29803                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29804                                                        int ox;
    29805                                                        ox = (int) toLong(ix);
    29806                                                        oai32data[it.oIndex + j] = ox;
    29807                                                }
    29808                                        }
    29809                                } else {
    29810                                        while (it.hasNext()) {
    29811                                                for (int j = 0; j < is; j++) {
    29812                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29813                                                        int ox;
    29814                                                        ox = (int) toLong(ix);
    29815                                                        oai32data[it.oIndex + j] = ox;
    29816                                                }
    29817                                        }
    29818                                }
    29819                        }
    29820                        break;
    29821                case Dataset.FLOAT32:
    29822                        final float[] of32data = ((FloatDataset) result).getData();
    29823                        if (it.isOutputDouble()) {
    29824                                while (it.hasNext()) {
    29825                                        final double ix = it.aDouble;
    29826                                        float ox;
    29827                                        ox = (float) (Math.rint(ix));
    29828                                        of32data[it.oIndex] = ox;
    29829                                }
    29830                        } else {
    29831                                while (it.hasNext()) {
    29832                                        final long ix = it.aLong;
    29833                                        float ox;
    29834                                        ox = (float) (Math.rint(ix));
    29835                                        of32data[it.oIndex] = ox;
    29836                                }
    29837                        }
    29838                        break;
    29839                case Dataset.FLOAT64:
    29840                        final double[] of64data = ((DoubleDataset) result).getData();
    29841                        if (it.isOutputDouble()) {
    29842                                while (it.hasNext()) {
    29843                                        final double ix = it.aDouble;
    29844                                        double ox;
    29845                                        ox = (Math.rint(ix));
    29846                                        of64data[it.oIndex] = ox;
    29847                                }
    29848                        } else {
    29849                                while (it.hasNext()) {
    29850                                        final long ix = it.aLong;
    29851                                        double ox;
    29852                                        ox = (Math.rint(ix));
    29853                                        of64data[it.oIndex] = ox;
    29854                                }
    29855                        }
    29856                        break;
    29857                case Dataset.ARRAYFLOAT32:
    29858                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    29859                        if (is == 1) {
    29860                                if (it.isOutputDouble()) {
    29861                                        while (it.hasNext()) {
    29862                                                final double ix = it.aDouble;
    29863                                                float ox;
    29864                                                ox = (float) (Math.rint(ix));
    29865                                                oaf32data[it.oIndex] = ox;
    29866                                        }
    29867                                } else {
    29868                                        while (it.hasNext()) {
    29869                                                final long ix = it.aLong;
    29870                                                float ox;
    29871                                                ox = (float) (Math.rint(ix));
    29872                                                oaf32data[it.oIndex] = ox;
    29873                                        }
    29874                                }
    29875                        } else if (as == 1) {
    29876                                if (it.isOutputDouble()) {
    29877                                        while (it.hasNext()) {
    29878                                                final double ix = it.aDouble;
    29879                                                float ox;
    29880                                                ox = (float) (Math.rint(ix));
    29881                                                for (int j = 0; j < is; j++) {
    29882                                                        oaf32data[it.oIndex + j] = ox;
    29883                                                }
    29884                                        }
    29885                                } else {
    29886                                        while (it.hasNext()) {
    29887                                                final long ix = it.aLong;
    29888                                                float ox;
    29889                                                ox = (float) (Math.rint(ix));
    29890                                                for (int j = 0; j < is; j++) {
    29891                                                        oaf32data[it.oIndex + j] = ox;
    29892                                                }
    29893                                        }
    29894                                }
    29895                        } else {
    29896                                if (it.isOutputDouble()) {
    29897                                        while (it.hasNext()) {
    29898                                                for (int j = 0; j < is; j++) {
    29899                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29900                                                        float ox;
    29901                                                        ox = (float) (Math.rint(ix));
    29902                                                        oaf32data[it.oIndex + j] = ox;
    29903                                                }
    29904                                        }
    29905                                } else {
    29906                                        while (it.hasNext()) {
    29907                                                for (int j = 0; j < is; j++) {
    29908                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29909                                                        float ox;
    29910                                                        ox = (float) (Math.rint(ix));
    29911                                                        oaf32data[it.oIndex + j] = ox;
    29912                                                }
    29913                                        }
    29914                                }
    29915                        }
    29916                        break;
    29917                case Dataset.ARRAYFLOAT64:
    29918                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    29919                        if (is == 1) {
    29920                                if (it.isOutputDouble()) {
    29921                                        while (it.hasNext()) {
    29922                                                final double ix = it.aDouble;
    29923                                                double ox;
    29924                                                ox = (Math.rint(ix));
    29925                                                oaf64data[it.oIndex] = ox;
    29926                                        }
    29927                                } else {
    29928                                        while (it.hasNext()) {
    29929                                                final long ix = it.aLong;
    29930                                                double ox;
    29931                                                ox = (Math.rint(ix));
    29932                                                oaf64data[it.oIndex] = ox;
    29933                                        }
    29934                                }
    29935                        } else if (as == 1) {
    29936                                if (it.isOutputDouble()) {
    29937                                        while (it.hasNext()) {
    29938                                                final double ix = it.aDouble;
    29939                                                double ox;
    29940                                                ox = (Math.rint(ix));
    29941                                                for (int j = 0; j < is; j++) {
    29942                                                        oaf64data[it.oIndex + j] = ox;
    29943                                                }
    29944                                        }
    29945                                } else {
    29946                                        while (it.hasNext()) {
    29947                                                final long ix = it.aLong;
    29948                                                double ox;
    29949                                                ox = (Math.rint(ix));
    29950                                                for (int j = 0; j < is; j++) {
    29951                                                        oaf64data[it.oIndex + j] = ox;
    29952                                                }
    29953                                        }
    29954                                }
    29955                        } else {
    29956                                if (it.isOutputDouble()) {
    29957                                        while (it.hasNext()) {
    29958                                                for (int j = 0; j < is; j++) {
    29959                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    29960                                                        double ox;
    29961                                                        ox = (Math.rint(ix));
    29962                                                        oaf64data[it.oIndex + j] = ox;
    29963                                                }
    29964                                        }
    29965                                } else {
    29966                                        while (it.hasNext()) {
    29967                                                for (int j = 0; j < is; j++) {
    29968                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    29969                                                        double ox;
    29970                                                        ox = (Math.rint(ix));
    29971                                                        oaf64data[it.oIndex + j] = ox;
    29972                                                }
    29973                                        }
    29974                                }
    29975                        }
    29976                        break;
    29977                case Dataset.COMPLEX64:
    29978                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    29979                        if (as == 1) {
    29980                                final double iy = 0;
    29981                                while (it.hasNext()) {
    29982                                        final double ix = it.aDouble;
    29983                                        float ox;
    29984                                        float oy;
    29985                                        ox = (float) (Math.rint(ix));
    29986                                        oy = (float) (Math.rint(iy));
    29987                                        oc64data[it.oIndex] = ox;
    29988                                        oc64data[it.oIndex + 1] = oy;
    29989                                }
    29990                        } else {
    29991                                while (it.hasNext()) {
    29992                                        final double ix = it.aDouble;
    29993                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    29994                                        float ox;
    29995                                        float oy;
    29996                                        ox = (float) (Math.rint(ix));
    29997                                        oy = (float) (Math.rint(iy));
    29998                                        oc64data[it.oIndex] = ox;
    29999                                        oc64data[it.oIndex + 1] = oy;
    30000                                }
    30001                        }
    30002                        break;
    30003                case Dataset.COMPLEX128:
    30004                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    30005                        if (as == 1) {
    30006                                final double iy = 0;
    30007                                while (it.hasNext()) {
    30008                                        final double ix = it.aDouble;
    30009                                        double ox;
    30010                                        double oy;
    30011                                        ox = (Math.rint(ix));
    30012                                        oy = (Math.rint(iy));
    30013                                        oc128data[it.oIndex] = ox;
    30014                                        oc128data[it.oIndex + 1] = oy;
    30015                                }
    30016                        } else {
    30017                                while (it.hasNext()) {
    30018                                        final double ix = it.aDouble;
    30019                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    30020                                        double ox;
    30021                                        double oy;
    30022                                        ox = (Math.rint(ix));
    30023                                        oy = (Math.rint(iy));
    30024                                        oc128data[it.oIndex] = ox;
    30025                                        oc128data[it.oIndex + 1] = oy;
    30026                                }
    30027                        }
    30028                        break;
    30029                default:
    30030                        throw new IllegalArgumentException("rint supports integer, compound integer, real, compound real, complex datasets only");
    30031                }
    30032
    30033                addFunctionName(result, "rint");
    30034                return result;
    30035        }
    30036
    30037        /**
    30038         * truncate - truncate each element to integers of the dataset
    30039         * @param a
    30040         * @return dataset
    30041         */
    30042        public static Dataset truncate(final Object a) {
    30043                return truncate(a, null);
    30044        }
    30045
    30046        /**
    30047         * truncate - truncate each element to integers of the dataset
    30048         * @param a
    30049         * @param o output can be null - in which case, a new dataset is created
    30050         * @return dataset
    30051         */
    30052        public static Dataset truncate(final Object a, final Dataset o) {
    30053                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    30054                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    30055                final Dataset result = it.getOutput();
    30056                final int is = result.getElementsPerItem();
    30057                final int as = da.getElementsPerItem();
    30058                final int dt = result.getDType();
    30059
    30060                switch(dt) {
    30061                case Dataset.INT8:
    30062                        final byte[] oi8data = ((ByteDataset) result).getData();
    30063                        if (it.isOutputDouble()) {
    30064                                while (it.hasNext()) {
    30065                                        final double ix = it.aDouble;
    30066                                        byte ox;
    30067                                        ox = (byte) toLong(ix);
    30068                                        oi8data[it.oIndex] = ox;
    30069                                }
    30070                        } else {
    30071                                while (it.hasNext()) {
    30072                                        final long ix = it.aLong;
    30073                                        byte ox;
    30074                                        ox = (byte) toLong(ix);
    30075                                        oi8data[it.oIndex] = ox;
    30076                                }
    30077                        }
    30078                        break;
    30079                case Dataset.INT16:
    30080                        final short[] oi16data = ((ShortDataset) result).getData();
    30081                        if (it.isOutputDouble()) {
    30082                                while (it.hasNext()) {
    30083                                        final double ix = it.aDouble;
    30084                                        short ox;
    30085                                        ox = (short) toLong(ix);
    30086                                        oi16data[it.oIndex] = ox;
    30087                                }
    30088                        } else {
    30089                                while (it.hasNext()) {
    30090                                        final long ix = it.aLong;
    30091                                        short ox;
    30092                                        ox = (short) toLong(ix);
    30093                                        oi16data[it.oIndex] = ox;
    30094                                }
    30095                        }
    30096                        break;
    30097                case Dataset.INT64:
    30098                        final long[] oi64data = ((LongDataset) result).getData();
    30099                        if (it.isOutputDouble()) {
    30100                                while (it.hasNext()) {
    30101                                        final double ix = it.aDouble;
    30102                                        long ox;
    30103                                        ox = toLong(ix);
    30104                                        oi64data[it.oIndex] = ox;
    30105                                }
    30106                        } else {
    30107                                while (it.hasNext()) {
    30108                                        final long ix = it.aLong;
    30109                                        long ox;
    30110                                        ox = toLong(ix);
    30111                                        oi64data[it.oIndex] = ox;
    30112                                }
    30113                        }
    30114                        break;
    30115                case Dataset.INT32:
    30116                        final int[] oi32data = ((IntegerDataset) result).getData();
    30117                        if (it.isOutputDouble()) {
    30118                                while (it.hasNext()) {
    30119                                        final double ix = it.aDouble;
    30120                                        int ox;
    30121                                        ox = (int) toLong(ix);
    30122                                        oi32data[it.oIndex] = ox;
    30123                                }
    30124                        } else {
    30125                                while (it.hasNext()) {
    30126                                        final long ix = it.aLong;
    30127                                        int ox;
    30128                                        ox = (int) toLong(ix);
    30129                                        oi32data[it.oIndex] = ox;
    30130                                }
    30131                        }
    30132                        break;
    30133                case Dataset.ARRAYINT8:
    30134                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    30135                        if (is == 1) {
    30136                                if (it.isOutputDouble()) {
    30137                                        while (it.hasNext()) {
    30138                                                final double ix = it.aDouble;
    30139                                                byte ox;
    30140                                                ox = (byte) toLong(ix);
    30141                                                oai8data[it.oIndex] = ox;
    30142                                        }
    30143                                } else {
    30144                                        while (it.hasNext()) {
    30145                                                final long ix = it.aLong;
    30146                                                byte ox;
    30147                                                ox = (byte) toLong(ix);
    30148                                                oai8data[it.oIndex] = ox;
    30149                                        }
    30150                                }
    30151                        } else if (as == 1) {
    30152                                if (it.isOutputDouble()) {
    30153                                        while (it.hasNext()) {
    30154                                                final double ix = it.aDouble;
    30155                                                byte ox;
    30156                                                ox = (byte) toLong(ix);
    30157                                                for (int j = 0; j < is; j++) {
    30158                                                        oai8data[it.oIndex + j] = ox;
    30159                                                }
    30160                                        }
    30161                                } else {
    30162                                        while (it.hasNext()) {
    30163                                                final long ix = it.aLong;
    30164                                                byte ox;
    30165                                                ox = (byte) toLong(ix);
    30166                                                for (int j = 0; j < is; j++) {
    30167                                                        oai8data[it.oIndex + j] = ox;
    30168                                                }
    30169                                        }
    30170                                }
    30171                        } else {
    30172                                if (it.isOutputDouble()) {
    30173                                        while (it.hasNext()) {
    30174                                                for (int j = 0; j < is; j++) {
    30175                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30176                                                        byte ox;
    30177                                                        ox = (byte) toLong(ix);
    30178                                                        oai8data[it.oIndex + j] = ox;
    30179                                                }
    30180                                        }
    30181                                } else {
    30182                                        while (it.hasNext()) {
    30183                                                for (int j = 0; j < is; j++) {
    30184                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30185                                                        byte ox;
    30186                                                        ox = (byte) toLong(ix);
    30187                                                        oai8data[it.oIndex + j] = ox;
    30188                                                }
    30189                                        }
    30190                                }
    30191                        }
    30192                        break;
    30193                case Dataset.ARRAYINT16:
    30194                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    30195                        if (is == 1) {
    30196                                if (it.isOutputDouble()) {
    30197                                        while (it.hasNext()) {
    30198                                                final double ix = it.aDouble;
    30199                                                short ox;
    30200                                                ox = (short) toLong(ix);
    30201                                                oai16data[it.oIndex] = ox;
    30202                                        }
    30203                                } else {
    30204                                        while (it.hasNext()) {
    30205                                                final long ix = it.aLong;
    30206                                                short ox;
    30207                                                ox = (short) toLong(ix);
    30208                                                oai16data[it.oIndex] = ox;
    30209                                        }
    30210                                }
    30211                        } else if (as == 1) {
    30212                                if (it.isOutputDouble()) {
    30213                                        while (it.hasNext()) {
    30214                                                final double ix = it.aDouble;
    30215                                                short ox;
    30216                                                ox = (short) toLong(ix);
    30217                                                for (int j = 0; j < is; j++) {
    30218                                                        oai16data[it.oIndex + j] = ox;
    30219                                                }
    30220                                        }
    30221                                } else {
    30222                                        while (it.hasNext()) {
    30223                                                final long ix = it.aLong;
    30224                                                short ox;
    30225                                                ox = (short) toLong(ix);
    30226                                                for (int j = 0; j < is; j++) {
    30227                                                        oai16data[it.oIndex + j] = ox;
    30228                                                }
    30229                                        }
    30230                                }
    30231                        } else {
    30232                                if (it.isOutputDouble()) {
    30233                                        while (it.hasNext()) {
    30234                                                for (int j = 0; j < is; j++) {
    30235                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30236                                                        short ox;
    30237                                                        ox = (short) toLong(ix);
    30238                                                        oai16data[it.oIndex + j] = ox;
    30239                                                }
    30240                                        }
    30241                                } else {
    30242                                        while (it.hasNext()) {
    30243                                                for (int j = 0; j < is; j++) {
    30244                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30245                                                        short ox;
    30246                                                        ox = (short) toLong(ix);
    30247                                                        oai16data[it.oIndex + j] = ox;
    30248                                                }
    30249                                        }
    30250                                }
    30251                        }
    30252                        break;
    30253                case Dataset.ARRAYINT64:
    30254                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    30255                        if (is == 1) {
    30256                                if (it.isOutputDouble()) {
    30257                                        while (it.hasNext()) {
    30258                                                final double ix = it.aDouble;
    30259                                                long ox;
    30260                                                ox = toLong(ix);
    30261                                                oai64data[it.oIndex] = ox;
    30262                                        }
    30263                                } else {
    30264                                        while (it.hasNext()) {
    30265                                                final long ix = it.aLong;
    30266                                                long ox;
    30267                                                ox = toLong(ix);
    30268                                                oai64data[it.oIndex] = ox;
    30269                                        }
    30270                                }
    30271                        } else if (as == 1) {
    30272                                if (it.isOutputDouble()) {
    30273                                        while (it.hasNext()) {
    30274                                                final double ix = it.aDouble;
    30275                                                long ox;
    30276                                                ox = toLong(ix);
    30277                                                for (int j = 0; j < is; j++) {
    30278                                                        oai64data[it.oIndex + j] = ox;
    30279                                                }
    30280                                        }
    30281                                } else {
    30282                                        while (it.hasNext()) {
    30283                                                final long ix = it.aLong;
    30284                                                long ox;
    30285                                                ox = toLong(ix);
    30286                                                for (int j = 0; j < is; j++) {
    30287                                                        oai64data[it.oIndex + j] = ox;
    30288                                                }
    30289                                        }
    30290                                }
    30291                        } else {
    30292                                if (it.isOutputDouble()) {
    30293                                        while (it.hasNext()) {
    30294                                                for (int j = 0; j < is; j++) {
    30295                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30296                                                        long ox;
    30297                                                        ox = toLong(ix);
    30298                                                        oai64data[it.oIndex + j] = ox;
    30299                                                }
    30300                                        }
    30301                                } else {
    30302                                        while (it.hasNext()) {
    30303                                                for (int j = 0; j < is; j++) {
    30304                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30305                                                        long ox;
    30306                                                        ox = toLong(ix);
    30307                                                        oai64data[it.oIndex + j] = ox;
    30308                                                }
    30309                                        }
    30310                                }
    30311                        }
    30312                        break;
    30313                case Dataset.ARRAYINT32:
    30314                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    30315                        if (is == 1) {
    30316                                if (it.isOutputDouble()) {
    30317                                        while (it.hasNext()) {
    30318                                                final double ix = it.aDouble;
    30319                                                int ox;
    30320                                                ox = (int) toLong(ix);
    30321                                                oai32data[it.oIndex] = ox;
    30322                                        }
    30323                                } else {
    30324                                        while (it.hasNext()) {
    30325                                                final long ix = it.aLong;
    30326                                                int ox;
    30327                                                ox = (int) toLong(ix);
    30328                                                oai32data[it.oIndex] = ox;
    30329                                        }
    30330                                }
    30331                        } else if (as == 1) {
    30332                                if (it.isOutputDouble()) {
    30333                                        while (it.hasNext()) {
    30334                                                final double ix = it.aDouble;
    30335                                                int ox;
    30336                                                ox = (int) toLong(ix);
    30337                                                for (int j = 0; j < is; j++) {
    30338                                                        oai32data[it.oIndex + j] = ox;
    30339                                                }
    30340                                        }
    30341                                } else {
    30342                                        while (it.hasNext()) {
    30343                                                final long ix = it.aLong;
    30344                                                int ox;
    30345                                                ox = (int) toLong(ix);
    30346                                                for (int j = 0; j < is; j++) {
    30347                                                        oai32data[it.oIndex + j] = ox;
    30348                                                }
    30349                                        }
    30350                                }
    30351                        } else {
    30352                                if (it.isOutputDouble()) {
    30353                                        while (it.hasNext()) {
    30354                                                for (int j = 0; j < is; j++) {
    30355                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30356                                                        int ox;
    30357                                                        ox = (int) toLong(ix);
    30358                                                        oai32data[it.oIndex + j] = ox;
    30359                                                }
    30360                                        }
    30361                                } else {
    30362                                        while (it.hasNext()) {
    30363                                                for (int j = 0; j < is; j++) {
    30364                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30365                                                        int ox;
    30366                                                        ox = (int) toLong(ix);
    30367                                                        oai32data[it.oIndex + j] = ox;
    30368                                                }
    30369                                        }
    30370                                }
    30371                        }
    30372                        break;
    30373                case Dataset.FLOAT32:
    30374                        final float[] of32data = ((FloatDataset) result).getData();
    30375                        if (it.isOutputDouble()) {
    30376                                while (it.hasNext()) {
    30377                                        final double ix = it.aDouble;
    30378                                        float ox;
    30379                                        ox = (float) (toLong(ix));
    30380                                        of32data[it.oIndex] = ox;
    30381                                }
    30382                        } else {
    30383                                while (it.hasNext()) {
    30384                                        final long ix = it.aLong;
    30385                                        float ox;
    30386                                        ox = (toLong(ix));
    30387                                        of32data[it.oIndex] = ox;
    30388                                }
    30389                        }
    30390                        break;
    30391                case Dataset.FLOAT64:
    30392                        final double[] of64data = ((DoubleDataset) result).getData();
    30393                        if (it.isOutputDouble()) {
    30394                                while (it.hasNext()) {
    30395                                        final double ix = it.aDouble;
    30396                                        double ox;
    30397                                        ox = (toLong(ix));
    30398                                        of64data[it.oIndex] = ox;
    30399                                }
    30400                        } else {
    30401                                while (it.hasNext()) {
    30402                                        final long ix = it.aLong;
    30403                                        double ox;
    30404                                        ox = (toLong(ix));
    30405                                        of64data[it.oIndex] = ox;
    30406                                }
    30407                        }
    30408                        break;
    30409                case Dataset.ARRAYFLOAT32:
    30410                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    30411                        if (is == 1) {
    30412                                if (it.isOutputDouble()) {
    30413                                        while (it.hasNext()) {
    30414                                                final double ix = it.aDouble;
    30415                                                float ox;
    30416                                                ox = (float) (toLong(ix));
    30417                                                oaf32data[it.oIndex] = ox;
    30418                                        }
    30419                                } else {
    30420                                        while (it.hasNext()) {
    30421                                                final long ix = it.aLong;
    30422                                                float ox;
    30423                                                ox = (toLong(ix));
    30424                                                oaf32data[it.oIndex] = ox;
    30425                                        }
    30426                                }
    30427                        } else if (as == 1) {
    30428                                if (it.isOutputDouble()) {
    30429                                        while (it.hasNext()) {
    30430                                                final double ix = it.aDouble;
    30431                                                float ox;
    30432                                                ox = (float) (toLong(ix));
    30433                                                for (int j = 0; j < is; j++) {
    30434                                                        oaf32data[it.oIndex + j] = ox;
    30435                                                }
    30436                                        }
    30437                                } else {
    30438                                        while (it.hasNext()) {
    30439                                                final long ix = it.aLong;
    30440                                                float ox;
    30441                                                ox = (toLong(ix));
    30442                                                for (int j = 0; j < is; j++) {
    30443                                                        oaf32data[it.oIndex + j] = ox;
    30444                                                }
    30445                                        }
    30446                                }
    30447                        } else {
    30448                                if (it.isOutputDouble()) {
    30449                                        while (it.hasNext()) {
    30450                                                for (int j = 0; j < is; j++) {
    30451                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30452                                                        float ox;
    30453                                                        ox = (float) (toLong(ix));
    30454                                                        oaf32data[it.oIndex + j] = ox;
    30455                                                }
    30456                                        }
    30457                                } else {
    30458                                        while (it.hasNext()) {
    30459                                                for (int j = 0; j < is; j++) {
    30460                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30461                                                        float ox;
    30462                                                        ox = (toLong(ix));
    30463                                                        oaf32data[it.oIndex + j] = ox;
    30464                                                }
    30465                                        }
    30466                                }
    30467                        }
    30468                        break;
    30469                case Dataset.ARRAYFLOAT64:
    30470                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    30471                        if (is == 1) {
    30472                                if (it.isOutputDouble()) {
    30473                                        while (it.hasNext()) {
    30474                                                final double ix = it.aDouble;
    30475                                                double ox;
    30476                                                ox = (toLong(ix));
    30477                                                oaf64data[it.oIndex] = ox;
    30478                                        }
    30479                                } else {
    30480                                        while (it.hasNext()) {
    30481                                                final long ix = it.aLong;
    30482                                                double ox;
    30483                                                ox = (toLong(ix));
    30484                                                oaf64data[it.oIndex] = ox;
    30485                                        }
    30486                                }
    30487                        } else if (as == 1) {
    30488                                if (it.isOutputDouble()) {
    30489                                        while (it.hasNext()) {
    30490                                                final double ix = it.aDouble;
    30491                                                double ox;
    30492                                                ox = (toLong(ix));
    30493                                                for (int j = 0; j < is; j++) {
    30494                                                        oaf64data[it.oIndex + j] = ox;
    30495                                                }
    30496                                        }
    30497                                } else {
    30498                                        while (it.hasNext()) {
    30499                                                final long ix = it.aLong;
    30500                                                double ox;
    30501                                                ox = (toLong(ix));
    30502                                                for (int j = 0; j < is; j++) {
    30503                                                        oaf64data[it.oIndex + j] = ox;
    30504                                                }
    30505                                        }
    30506                                }
    30507                        } else {
    30508                                if (it.isOutputDouble()) {
    30509                                        while (it.hasNext()) {
    30510                                                for (int j = 0; j < is; j++) {
    30511                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30512                                                        double ox;
    30513                                                        ox = (toLong(ix));
    30514                                                        oaf64data[it.oIndex + j] = ox;
    30515                                                }
    30516                                        }
    30517                                } else {
    30518                                        while (it.hasNext()) {
    30519                                                for (int j = 0; j < is; j++) {
    30520                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30521                                                        double ox;
    30522                                                        ox = (toLong(ix));
    30523                                                        oaf64data[it.oIndex + j] = ox;
    30524                                                }
    30525                                        }
    30526                                }
    30527                        }
    30528                        break;
    30529                case Dataset.COMPLEX64:
    30530                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    30531                        if (as == 1) {
    30532                                final double iy = 0;
    30533                                while (it.hasNext()) {
    30534                                        final double ix = it.aDouble;
    30535                                        float ox;
    30536                                        float oy;
    30537                                        ox = (float) (toLong(ix));
    30538                                        oy = (float) (toLong(iy));
    30539                                        oc64data[it.oIndex] = ox;
    30540                                        oc64data[it.oIndex + 1] = oy;
    30541                                }
    30542                        } else {
    30543                                while (it.hasNext()) {
    30544                                        final double ix = it.aDouble;
    30545                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    30546                                        float ox;
    30547                                        float oy;
    30548                                        ox = (float) (toLong(ix));
    30549                                        oy = (float) (toLong(iy));
    30550                                        oc64data[it.oIndex] = ox;
    30551                                        oc64data[it.oIndex + 1] = oy;
    30552                                }
    30553                        }
    30554                        break;
    30555                case Dataset.COMPLEX128:
    30556                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    30557                        if (as == 1) {
    30558                                final double iy = 0;
    30559                                while (it.hasNext()) {
    30560                                        final double ix = it.aDouble;
    30561                                        double ox;
    30562                                        double oy;
    30563                                        ox = (toLong(ix));
    30564                                        oy = (toLong(iy));
    30565                                        oc128data[it.oIndex] = ox;
    30566                                        oc128data[it.oIndex + 1] = oy;
    30567                                }
    30568                        } else {
    30569                                while (it.hasNext()) {
    30570                                        final double ix = it.aDouble;
    30571                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    30572                                        double ox;
    30573                                        double oy;
    30574                                        ox = (toLong(ix));
    30575                                        oy = (toLong(iy));
    30576                                        oc128data[it.oIndex] = ox;
    30577                                        oc128data[it.oIndex + 1] = oy;
    30578                                }
    30579                        }
    30580                        break;
    30581                default:
    30582                        throw new IllegalArgumentException("truncate supports integer, compound integer, real, compound real, complex datasets only");
    30583                }
    30584
    30585                addFunctionName(result, "truncate");
    30586                return result;
    30587        }
    30588
    30589        /**
    30590         * toDegrees - convert to degrees
    30591         * @param a
    30592         * @return dataset
    30593         */
    30594        public static Dataset toDegrees(final Object a) {
    30595                return toDegrees(a, null);
    30596        }
    30597
    30598        /**
    30599         * toDegrees - convert to degrees
    30600         * @param a
    30601         * @param o output can be null - in which case, a new dataset is created
    30602         * @return dataset
    30603         */
    30604        public static Dataset toDegrees(final Object a, final Dataset o) {
    30605                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    30606                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    30607                final Dataset result = it.getOutput();
    30608                final int is = result.getElementsPerItem();
    30609                final int as = da.getElementsPerItem();
    30610                final int dt = result.getDType();
    30611
    30612                switch(dt) {
    30613                case Dataset.INT8:
    30614                        final byte[] oi8data = ((ByteDataset) result).getData();
    30615                        if (it.isOutputDouble()) {
    30616                                while (it.hasNext()) {
    30617                                        final double ix = it.aDouble;
    30618                                        byte ox;
    30619                                        ox = (byte) toLong(Math.toDegrees(ix));
    30620                                        oi8data[it.oIndex] = ox;
    30621                                }
    30622                        } else {
    30623                                while (it.hasNext()) {
    30624                                        final long ix = it.aLong;
    30625                                        byte ox;
    30626                                        ox = (byte) toLong(Math.toDegrees(ix));
    30627                                        oi8data[it.oIndex] = ox;
    30628                                }
    30629                        }
    30630                        break;
    30631                case Dataset.INT16:
    30632                        final short[] oi16data = ((ShortDataset) result).getData();
    30633                        if (it.isOutputDouble()) {
    30634                                while (it.hasNext()) {
    30635                                        final double ix = it.aDouble;
    30636                                        short ox;
    30637                                        ox = (short) toLong(Math.toDegrees(ix));
    30638                                        oi16data[it.oIndex] = ox;
    30639                                }
    30640                        } else {
    30641                                while (it.hasNext()) {
    30642                                        final long ix = it.aLong;
    30643                                        short ox;
    30644                                        ox = (short) toLong(Math.toDegrees(ix));
    30645                                        oi16data[it.oIndex] = ox;
    30646                                }
    30647                        }
    30648                        break;
    30649                case Dataset.INT64:
    30650                        final long[] oi64data = ((LongDataset) result).getData();
    30651                        if (it.isOutputDouble()) {
    30652                                while (it.hasNext()) {
    30653                                        final double ix = it.aDouble;
    30654                                        long ox;
    30655                                        ox = toLong(Math.toDegrees(ix));
    30656                                        oi64data[it.oIndex] = ox;
    30657                                }
    30658                        } else {
    30659                                while (it.hasNext()) {
    30660                                        final long ix = it.aLong;
    30661                                        long ox;
    30662                                        ox = toLong(Math.toDegrees(ix));
    30663                                        oi64data[it.oIndex] = ox;
    30664                                }
    30665                        }
    30666                        break;
    30667                case Dataset.INT32:
    30668                        final int[] oi32data = ((IntegerDataset) result).getData();
    30669                        if (it.isOutputDouble()) {
    30670                                while (it.hasNext()) {
    30671                                        final double ix = it.aDouble;
    30672                                        int ox;
    30673                                        ox = (int) toLong(Math.toDegrees(ix));
    30674                                        oi32data[it.oIndex] = ox;
    30675                                }
    30676                        } else {
    30677                                while (it.hasNext()) {
    30678                                        final long ix = it.aLong;
    30679                                        int ox;
    30680                                        ox = (int) toLong(Math.toDegrees(ix));
    30681                                        oi32data[it.oIndex] = ox;
    30682                                }
    30683                        }
    30684                        break;
    30685                case Dataset.ARRAYINT8:
    30686                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    30687                        if (is == 1) {
    30688                                if (it.isOutputDouble()) {
    30689                                        while (it.hasNext()) {
    30690                                                final double ix = it.aDouble;
    30691                                                byte ox;
    30692                                                ox = (byte) toLong(Math.toDegrees(ix));
    30693                                                oai8data[it.oIndex] = ox;
    30694                                        }
    30695                                } else {
    30696                                        while (it.hasNext()) {
    30697                                                final long ix = it.aLong;
    30698                                                byte ox;
    30699                                                ox = (byte) toLong(Math.toDegrees(ix));
    30700                                                oai8data[it.oIndex] = ox;
    30701                                        }
    30702                                }
    30703                        } else if (as == 1) {
    30704                                if (it.isOutputDouble()) {
    30705                                        while (it.hasNext()) {
    30706                                                final double ix = it.aDouble;
    30707                                                byte ox;
    30708                                                ox = (byte) toLong(Math.toDegrees(ix));
    30709                                                for (int j = 0; j < is; j++) {
    30710                                                        oai8data[it.oIndex + j] = ox;
    30711                                                }
    30712                                        }
    30713                                } else {
    30714                                        while (it.hasNext()) {
    30715                                                final long ix = it.aLong;
    30716                                                byte ox;
    30717                                                ox = (byte) toLong(Math.toDegrees(ix));
    30718                                                for (int j = 0; j < is; j++) {
    30719                                                        oai8data[it.oIndex + j] = ox;
    30720                                                }
    30721                                        }
    30722                                }
    30723                        } else {
    30724                                if (it.isOutputDouble()) {
    30725                                        while (it.hasNext()) {
    30726                                                for (int j = 0; j < is; j++) {
    30727                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30728                                                        byte ox;
    30729                                                        ox = (byte) toLong(Math.toDegrees(ix));
    30730                                                        oai8data[it.oIndex + j] = ox;
    30731                                                }
    30732                                        }
    30733                                } else {
    30734                                        while (it.hasNext()) {
    30735                                                for (int j = 0; j < is; j++) {
    30736                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30737                                                        byte ox;
    30738                                                        ox = (byte) toLong(Math.toDegrees(ix));
    30739                                                        oai8data[it.oIndex + j] = ox;
    30740                                                }
    30741                                        }
    30742                                }
    30743                        }
    30744                        break;
    30745                case Dataset.ARRAYINT16:
    30746                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    30747                        if (is == 1) {
    30748                                if (it.isOutputDouble()) {
    30749                                        while (it.hasNext()) {
    30750                                                final double ix = it.aDouble;
    30751                                                short ox;
    30752                                                ox = (short) toLong(Math.toDegrees(ix));
    30753                                                oai16data[it.oIndex] = ox;
    30754                                        }
    30755                                } else {
    30756                                        while (it.hasNext()) {
    30757                                                final long ix = it.aLong;
    30758                                                short ox;
    30759                                                ox = (short) toLong(Math.toDegrees(ix));
    30760                                                oai16data[it.oIndex] = ox;
    30761                                        }
    30762                                }
    30763                        } else if (as == 1) {
    30764                                if (it.isOutputDouble()) {
    30765                                        while (it.hasNext()) {
    30766                                                final double ix = it.aDouble;
    30767                                                short ox;
    30768                                                ox = (short) toLong(Math.toDegrees(ix));
    30769                                                for (int j = 0; j < is; j++) {
    30770                                                        oai16data[it.oIndex + j] = ox;
    30771                                                }
    30772                                        }
    30773                                } else {
    30774                                        while (it.hasNext()) {
    30775                                                final long ix = it.aLong;
    30776                                                short ox;
    30777                                                ox = (short) toLong(Math.toDegrees(ix));
    30778                                                for (int j = 0; j < is; j++) {
    30779                                                        oai16data[it.oIndex + j] = ox;
    30780                                                }
    30781                                        }
    30782                                }
    30783                        } else {
    30784                                if (it.isOutputDouble()) {
    30785                                        while (it.hasNext()) {
    30786                                                for (int j = 0; j < is; j++) {
    30787                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30788                                                        short ox;
    30789                                                        ox = (short) toLong(Math.toDegrees(ix));
    30790                                                        oai16data[it.oIndex + j] = ox;
    30791                                                }
    30792                                        }
    30793                                } else {
    30794                                        while (it.hasNext()) {
    30795                                                for (int j = 0; j < is; j++) {
    30796                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30797                                                        short ox;
    30798                                                        ox = (short) toLong(Math.toDegrees(ix));
    30799                                                        oai16data[it.oIndex + j] = ox;
    30800                                                }
    30801                                        }
    30802                                }
    30803                        }
    30804                        break;
    30805                case Dataset.ARRAYINT64:
    30806                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    30807                        if (is == 1) {
    30808                                if (it.isOutputDouble()) {
    30809                                        while (it.hasNext()) {
    30810                                                final double ix = it.aDouble;
    30811                                                long ox;
    30812                                                ox = toLong(Math.toDegrees(ix));
    30813                                                oai64data[it.oIndex] = ox;
    30814                                        }
    30815                                } else {
    30816                                        while (it.hasNext()) {
    30817                                                final long ix = it.aLong;
    30818                                                long ox;
    30819                                                ox = toLong(Math.toDegrees(ix));
    30820                                                oai64data[it.oIndex] = ox;
    30821                                        }
    30822                                }
    30823                        } else if (as == 1) {
    30824                                if (it.isOutputDouble()) {
    30825                                        while (it.hasNext()) {
    30826                                                final double ix = it.aDouble;
    30827                                                long ox;
    30828                                                ox = toLong(Math.toDegrees(ix));
    30829                                                for (int j = 0; j < is; j++) {
    30830                                                        oai64data[it.oIndex + j] = ox;
    30831                                                }
    30832                                        }
    30833                                } else {
    30834                                        while (it.hasNext()) {
    30835                                                final long ix = it.aLong;
    30836                                                long ox;
    30837                                                ox = toLong(Math.toDegrees(ix));
    30838                                                for (int j = 0; j < is; j++) {
    30839                                                        oai64data[it.oIndex + j] = ox;
    30840                                                }
    30841                                        }
    30842                                }
    30843                        } else {
    30844                                if (it.isOutputDouble()) {
    30845                                        while (it.hasNext()) {
    30846                                                for (int j = 0; j < is; j++) {
    30847                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30848                                                        long ox;
    30849                                                        ox = toLong(Math.toDegrees(ix));
    30850                                                        oai64data[it.oIndex + j] = ox;
    30851                                                }
    30852                                        }
    30853                                } else {
    30854                                        while (it.hasNext()) {
    30855                                                for (int j = 0; j < is; j++) {
    30856                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30857                                                        long ox;
    30858                                                        ox = toLong(Math.toDegrees(ix));
    30859                                                        oai64data[it.oIndex + j] = ox;
    30860                                                }
    30861                                        }
    30862                                }
    30863                        }
    30864                        break;
    30865                case Dataset.ARRAYINT32:
    30866                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    30867                        if (is == 1) {
    30868                                if (it.isOutputDouble()) {
    30869                                        while (it.hasNext()) {
    30870                                                final double ix = it.aDouble;
    30871                                                int ox;
    30872                                                ox = (int) toLong(Math.toDegrees(ix));
    30873                                                oai32data[it.oIndex] = ox;
    30874                                        }
    30875                                } else {
    30876                                        while (it.hasNext()) {
    30877                                                final long ix = it.aLong;
    30878                                                int ox;
    30879                                                ox = (int) toLong(Math.toDegrees(ix));
    30880                                                oai32data[it.oIndex] = ox;
    30881                                        }
    30882                                }
    30883                        } else if (as == 1) {
    30884                                if (it.isOutputDouble()) {
    30885                                        while (it.hasNext()) {
    30886                                                final double ix = it.aDouble;
    30887                                                int ox;
    30888                                                ox = (int) toLong(Math.toDegrees(ix));
    30889                                                for (int j = 0; j < is; j++) {
    30890                                                        oai32data[it.oIndex + j] = ox;
    30891                                                }
    30892                                        }
    30893                                } else {
    30894                                        while (it.hasNext()) {
    30895                                                final long ix = it.aLong;
    30896                                                int ox;
    30897                                                ox = (int) toLong(Math.toDegrees(ix));
    30898                                                for (int j = 0; j < is; j++) {
    30899                                                        oai32data[it.oIndex + j] = ox;
    30900                                                }
    30901                                        }
    30902                                }
    30903                        } else {
    30904                                if (it.isOutputDouble()) {
    30905                                        while (it.hasNext()) {
    30906                                                for (int j = 0; j < is; j++) {
    30907                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    30908                                                        int ox;
    30909                                                        ox = (int) toLong(Math.toDegrees(ix));
    30910                                                        oai32data[it.oIndex + j] = ox;
    30911                                                }
    30912                                        }
    30913                                } else {
    30914                                        while (it.hasNext()) {
    30915                                                for (int j = 0; j < is; j++) {
    30916                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    30917                                                        int ox;
    30918                                                        ox = (int) toLong(Math.toDegrees(ix));
    30919                                                        oai32data[it.oIndex + j] = ox;
    30920                                                }
    30921                                        }
    30922                                }
    30923                        }
    30924                        break;
    30925                case Dataset.FLOAT32:
    30926                        final float[] of32data = ((FloatDataset) result).getData();
    30927                        if (it.isOutputDouble()) {
    30928                                while (it.hasNext()) {
    30929                                        final double ix = it.aDouble;
    30930                                        float ox;
    30931                                        ox = (float) (Math.toDegrees(ix));
    30932                                        of32data[it.oIndex] = ox;
    30933                                }
    30934                        } else {
    30935                                while (it.hasNext()) {
    30936                                        final long ix = it.aLong;
    30937                                        float ox;
    30938                                        ox = (float) (Math.toDegrees(ix));
    30939                                        of32data[it.oIndex] = ox;
    30940                                }
    30941                        }
    30942                        break;
    30943                case Dataset.FLOAT64:
    30944                        final double[] of64data = ((DoubleDataset) result).getData();
    30945                        if (it.isOutputDouble()) {
    30946                                while (it.hasNext()) {
    30947                                        final double ix = it.aDouble;
    30948                                        double ox;
    30949                                        ox = (Math.toDegrees(ix));
    30950                                        of64data[it.oIndex] = ox;
    30951                                }
    30952                        } else {
    30953                                while (it.hasNext()) {
    30954                                        final long ix = it.aLong;
    30955                                        double ox;
    30956                                        ox = (Math.toDegrees(ix));
    30957                                        of64data[it.oIndex] = ox;
    30958                                }
    30959                        }
    30960                        break;
    30961                case Dataset.ARRAYFLOAT32:
    30962                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    30963                        if (is == 1) {
    30964                                if (it.isOutputDouble()) {
    30965                                        while (it.hasNext()) {
    30966                                                final double ix = it.aDouble;
    30967                                                float ox;
    30968                                                ox = (float) (Math.toDegrees(ix));
    30969                                                oaf32data[it.oIndex] = ox;
    30970                                        }
    30971                                } else {
    30972                                        while (it.hasNext()) {
    30973                                                final long ix = it.aLong;
    30974                                                float ox;
    30975                                                ox = (float) (Math.toDegrees(ix));
    30976                                                oaf32data[it.oIndex] = ox;
    30977                                        }
    30978                                }
    30979                        } else if (as == 1) {
    30980                                if (it.isOutputDouble()) {
    30981                                        while (it.hasNext()) {
    30982                                                final double ix = it.aDouble;
    30983                                                float ox;
    30984                                                ox = (float) (Math.toDegrees(ix));
    30985                                                for (int j = 0; j < is; j++) {
    30986                                                        oaf32data[it.oIndex + j] = ox;
    30987                                                }
    30988                                        }
    30989                                } else {
    30990                                        while (it.hasNext()) {
    30991                                                final long ix = it.aLong;
    30992                                                float ox;
    30993                                                ox = (float) (Math.toDegrees(ix));
    30994                                                for (int j = 0; j < is; j++) {
    30995                                                        oaf32data[it.oIndex + j] = ox;
    30996                                                }
    30997                                        }
    30998                                }
    30999                        } else {
    31000                                if (it.isOutputDouble()) {
    31001                                        while (it.hasNext()) {
    31002                                                for (int j = 0; j < is; j++) {
    31003                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31004                                                        float ox;
    31005                                                        ox = (float) (Math.toDegrees(ix));
    31006                                                        oaf32data[it.oIndex + j] = ox;
    31007                                                }
    31008                                        }
    31009                                } else {
    31010                                        while (it.hasNext()) {
    31011                                                for (int j = 0; j < is; j++) {
    31012                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31013                                                        float ox;
    31014                                                        ox = (float) (Math.toDegrees(ix));
    31015                                                        oaf32data[it.oIndex + j] = ox;
    31016                                                }
    31017                                        }
    31018                                }
    31019                        }
    31020                        break;
    31021                case Dataset.ARRAYFLOAT64:
    31022                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    31023                        if (is == 1) {
    31024                                if (it.isOutputDouble()) {
    31025                                        while (it.hasNext()) {
    31026                                                final double ix = it.aDouble;
    31027                                                double ox;
    31028                                                ox = (Math.toDegrees(ix));
    31029                                                oaf64data[it.oIndex] = ox;
    31030                                        }
    31031                                } else {
    31032                                        while (it.hasNext()) {
    31033                                                final long ix = it.aLong;
    31034                                                double ox;
    31035                                                ox = (Math.toDegrees(ix));
    31036                                                oaf64data[it.oIndex] = ox;
    31037                                        }
    31038                                }
    31039                        } else if (as == 1) {
    31040                                if (it.isOutputDouble()) {
    31041                                        while (it.hasNext()) {
    31042                                                final double ix = it.aDouble;
    31043                                                double ox;
    31044                                                ox = (Math.toDegrees(ix));
    31045                                                for (int j = 0; j < is; j++) {
    31046                                                        oaf64data[it.oIndex + j] = ox;
    31047                                                }
    31048                                        }
    31049                                } else {
    31050                                        while (it.hasNext()) {
    31051                                                final long ix = it.aLong;
    31052                                                double ox;
    31053                                                ox = (Math.toDegrees(ix));
    31054                                                for (int j = 0; j < is; j++) {
    31055                                                        oaf64data[it.oIndex + j] = ox;
    31056                                                }
    31057                                        }
    31058                                }
    31059                        } else {
    31060                                if (it.isOutputDouble()) {
    31061                                        while (it.hasNext()) {
    31062                                                for (int j = 0; j < is; j++) {
    31063                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31064                                                        double ox;
    31065                                                        ox = (Math.toDegrees(ix));
    31066                                                        oaf64data[it.oIndex + j] = ox;
    31067                                                }
    31068                                        }
    31069                                } else {
    31070                                        while (it.hasNext()) {
    31071                                                for (int j = 0; j < is; j++) {
    31072                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31073                                                        double ox;
    31074                                                        ox = (Math.toDegrees(ix));
    31075                                                        oaf64data[it.oIndex + j] = ox;
    31076                                                }
    31077                                        }
    31078                                }
    31079                        }
    31080                        break;
    31081                case Dataset.COMPLEX64:
    31082                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    31083                        if (as == 1) {
    31084                                final double iy = 0;
    31085                                while (it.hasNext()) {
    31086                                        final double ix = it.aDouble;
    31087                                        float ox;
    31088                                        float oy;
    31089                                        ox = (float) (Math.toDegrees(ix));
    31090                                        oy = (float) (Math.toDegrees(iy));
    31091                                        oc64data[it.oIndex] = ox;
    31092                                        oc64data[it.oIndex + 1] = oy;
    31093                                }
    31094                        } else {
    31095                                while (it.hasNext()) {
    31096                                        final double ix = it.aDouble;
    31097                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    31098                                        float ox;
    31099                                        float oy;
    31100                                        ox = (float) (Math.toDegrees(ix));
    31101                                        oy = (float) (Math.toDegrees(iy));
    31102                                        oc64data[it.oIndex] = ox;
    31103                                        oc64data[it.oIndex + 1] = oy;
    31104                                }
    31105                        }
    31106                        break;
    31107                case Dataset.COMPLEX128:
    31108                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    31109                        if (as == 1) {
    31110                                final double iy = 0;
    31111                                while (it.hasNext()) {
    31112                                        final double ix = it.aDouble;
    31113                                        double ox;
    31114                                        double oy;
    31115                                        ox = (Math.toDegrees(ix));
    31116                                        oy = (Math.toDegrees(iy));
    31117                                        oc128data[it.oIndex] = ox;
    31118                                        oc128data[it.oIndex + 1] = oy;
    31119                                }
    31120                        } else {
    31121                                while (it.hasNext()) {
    31122                                        final double ix = it.aDouble;
    31123                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    31124                                        double ox;
    31125                                        double oy;
    31126                                        ox = (Math.toDegrees(ix));
    31127                                        oy = (Math.toDegrees(iy));
    31128                                        oc128data[it.oIndex] = ox;
    31129                                        oc128data[it.oIndex + 1] = oy;
    31130                                }
    31131                        }
    31132                        break;
    31133                default:
    31134                        throw new IllegalArgumentException("toDegrees supports integer, compound integer, real, compound real, complex datasets only");
    31135                }
    31136
    31137                addFunctionName(result, "toDegrees");
    31138                return result;
    31139        }
    31140
    31141        /**
    31142         * toRadians - convert to radians
    31143         * @param a
    31144         * @return dataset
    31145         */
    31146        public static Dataset toRadians(final Object a) {
    31147                return toRadians(a, null);
    31148        }
    31149
    31150        /**
    31151         * toRadians - convert to radians
    31152         * @param a
    31153         * @param o output can be null - in which case, a new dataset is created
    31154         * @return dataset
    31155         */
    31156        public static Dataset toRadians(final Object a, final Dataset o) {
    31157                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    31158                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    31159                final Dataset result = it.getOutput();
    31160                final int is = result.getElementsPerItem();
    31161                final int as = da.getElementsPerItem();
    31162                final int dt = result.getDType();
    31163
    31164                switch(dt) {
    31165                case Dataset.INT8:
    31166                        final byte[] oi8data = ((ByteDataset) result).getData();
    31167                        if (it.isOutputDouble()) {
    31168                                while (it.hasNext()) {
    31169                                        final double ix = it.aDouble;
    31170                                        byte ox;
    31171                                        ox = (byte) toLong(Math.toRadians(ix));
    31172                                        oi8data[it.oIndex] = ox;
    31173                                }
    31174                        } else {
    31175                                while (it.hasNext()) {
    31176                                        final long ix = it.aLong;
    31177                                        byte ox;
    31178                                        ox = (byte) toLong(Math.toRadians(ix));
    31179                                        oi8data[it.oIndex] = ox;
    31180                                }
    31181                        }
    31182                        break;
    31183                case Dataset.INT16:
    31184                        final short[] oi16data = ((ShortDataset) result).getData();
    31185                        if (it.isOutputDouble()) {
    31186                                while (it.hasNext()) {
    31187                                        final double ix = it.aDouble;
    31188                                        short ox;
    31189                                        ox = (short) toLong(Math.toRadians(ix));
    31190                                        oi16data[it.oIndex] = ox;
    31191                                }
    31192                        } else {
    31193                                while (it.hasNext()) {
    31194                                        final long ix = it.aLong;
    31195                                        short ox;
    31196                                        ox = (short) toLong(Math.toRadians(ix));
    31197                                        oi16data[it.oIndex] = ox;
    31198                                }
    31199                        }
    31200                        break;
    31201                case Dataset.INT64:
    31202                        final long[] oi64data = ((LongDataset) result).getData();
    31203                        if (it.isOutputDouble()) {
    31204                                while (it.hasNext()) {
    31205                                        final double ix = it.aDouble;
    31206                                        long ox;
    31207                                        ox = toLong(Math.toRadians(ix));
    31208                                        oi64data[it.oIndex] = ox;
    31209                                }
    31210                        } else {
    31211                                while (it.hasNext()) {
    31212                                        final long ix = it.aLong;
    31213                                        long ox;
    31214                                        ox = toLong(Math.toRadians(ix));
    31215                                        oi64data[it.oIndex] = ox;
    31216                                }
    31217                        }
    31218                        break;
    31219                case Dataset.INT32:
    31220                        final int[] oi32data = ((IntegerDataset) result).getData();
    31221                        if (it.isOutputDouble()) {
    31222                                while (it.hasNext()) {
    31223                                        final double ix = it.aDouble;
    31224                                        int ox;
    31225                                        ox = (int) toLong(Math.toRadians(ix));
    31226                                        oi32data[it.oIndex] = ox;
    31227                                }
    31228                        } else {
    31229                                while (it.hasNext()) {
    31230                                        final long ix = it.aLong;
    31231                                        int ox;
    31232                                        ox = (int) toLong(Math.toRadians(ix));
    31233                                        oi32data[it.oIndex] = ox;
    31234                                }
    31235                        }
    31236                        break;
    31237                case Dataset.ARRAYINT8:
    31238                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    31239                        if (is == 1) {
    31240                                if (it.isOutputDouble()) {
    31241                                        while (it.hasNext()) {
    31242                                                final double ix = it.aDouble;
    31243                                                byte ox;
    31244                                                ox = (byte) toLong(Math.toRadians(ix));
    31245                                                oai8data[it.oIndex] = ox;
    31246                                        }
    31247                                } else {
    31248                                        while (it.hasNext()) {
    31249                                                final long ix = it.aLong;
    31250                                                byte ox;
    31251                                                ox = (byte) toLong(Math.toRadians(ix));
    31252                                                oai8data[it.oIndex] = ox;
    31253                                        }
    31254                                }
    31255                        } else if (as == 1) {
    31256                                if (it.isOutputDouble()) {
    31257                                        while (it.hasNext()) {
    31258                                                final double ix = it.aDouble;
    31259                                                byte ox;
    31260                                                ox = (byte) toLong(Math.toRadians(ix));
    31261                                                for (int j = 0; j < is; j++) {
    31262                                                        oai8data[it.oIndex + j] = ox;
    31263                                                }
    31264                                        }
    31265                                } else {
    31266                                        while (it.hasNext()) {
    31267                                                final long ix = it.aLong;
    31268                                                byte ox;
    31269                                                ox = (byte) toLong(Math.toRadians(ix));
    31270                                                for (int j = 0; j < is; j++) {
    31271                                                        oai8data[it.oIndex + j] = ox;
    31272                                                }
    31273                                        }
    31274                                }
    31275                        } else {
    31276                                if (it.isOutputDouble()) {
    31277                                        while (it.hasNext()) {
    31278                                                for (int j = 0; j < is; j++) {
    31279                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31280                                                        byte ox;
    31281                                                        ox = (byte) toLong(Math.toRadians(ix));
    31282                                                        oai8data[it.oIndex + j] = ox;
    31283                                                }
    31284                                        }
    31285                                } else {
    31286                                        while (it.hasNext()) {
    31287                                                for (int j = 0; j < is; j++) {
    31288                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31289                                                        byte ox;
    31290                                                        ox = (byte) toLong(Math.toRadians(ix));
    31291                                                        oai8data[it.oIndex + j] = ox;
    31292                                                }
    31293                                        }
    31294                                }
    31295                        }
    31296                        break;
    31297                case Dataset.ARRAYINT16:
    31298                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    31299                        if (is == 1) {
    31300                                if (it.isOutputDouble()) {
    31301                                        while (it.hasNext()) {
    31302                                                final double ix = it.aDouble;
    31303                                                short ox;
    31304                                                ox = (short) toLong(Math.toRadians(ix));
    31305                                                oai16data[it.oIndex] = ox;
    31306                                        }
    31307                                } else {
    31308                                        while (it.hasNext()) {
    31309                                                final long ix = it.aLong;
    31310                                                short ox;
    31311                                                ox = (short) toLong(Math.toRadians(ix));
    31312                                                oai16data[it.oIndex] = ox;
    31313                                        }
    31314                                }
    31315                        } else if (as == 1) {
    31316                                if (it.isOutputDouble()) {
    31317                                        while (it.hasNext()) {
    31318                                                final double ix = it.aDouble;
    31319                                                short ox;
    31320                                                ox = (short) toLong(Math.toRadians(ix));
    31321                                                for (int j = 0; j < is; j++) {
    31322                                                        oai16data[it.oIndex + j] = ox;
    31323                                                }
    31324                                        }
    31325                                } else {
    31326                                        while (it.hasNext()) {
    31327                                                final long ix = it.aLong;
    31328                                                short ox;
    31329                                                ox = (short) toLong(Math.toRadians(ix));
    31330                                                for (int j = 0; j < is; j++) {
    31331                                                        oai16data[it.oIndex + j] = ox;
    31332                                                }
    31333                                        }
    31334                                }
    31335                        } else {
    31336                                if (it.isOutputDouble()) {
    31337                                        while (it.hasNext()) {
    31338                                                for (int j = 0; j < is; j++) {
    31339                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31340                                                        short ox;
    31341                                                        ox = (short) toLong(Math.toRadians(ix));
    31342                                                        oai16data[it.oIndex + j] = ox;
    31343                                                }
    31344                                        }
    31345                                } else {
    31346                                        while (it.hasNext()) {
    31347                                                for (int j = 0; j < is; j++) {
    31348                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31349                                                        short ox;
    31350                                                        ox = (short) toLong(Math.toRadians(ix));
    31351                                                        oai16data[it.oIndex + j] = ox;
    31352                                                }
    31353                                        }
    31354                                }
    31355                        }
    31356                        break;
    31357                case Dataset.ARRAYINT64:
    31358                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    31359                        if (is == 1) {
    31360                                if (it.isOutputDouble()) {
    31361                                        while (it.hasNext()) {
    31362                                                final double ix = it.aDouble;
    31363                                                long ox;
    31364                                                ox = toLong(Math.toRadians(ix));
    31365                                                oai64data[it.oIndex] = ox;
    31366                                        }
    31367                                } else {
    31368                                        while (it.hasNext()) {
    31369                                                final long ix = it.aLong;
    31370                                                long ox;
    31371                                                ox = toLong(Math.toRadians(ix));
    31372                                                oai64data[it.oIndex] = ox;
    31373                                        }
    31374                                }
    31375                        } else if (as == 1) {
    31376                                if (it.isOutputDouble()) {
    31377                                        while (it.hasNext()) {
    31378                                                final double ix = it.aDouble;
    31379                                                long ox;
    31380                                                ox = toLong(Math.toRadians(ix));
    31381                                                for (int j = 0; j < is; j++) {
    31382                                                        oai64data[it.oIndex + j] = ox;
    31383                                                }
    31384                                        }
    31385                                } else {
    31386                                        while (it.hasNext()) {
    31387                                                final long ix = it.aLong;
    31388                                                long ox;
    31389                                                ox = toLong(Math.toRadians(ix));
    31390                                                for (int j = 0; j < is; j++) {
    31391                                                        oai64data[it.oIndex + j] = ox;
    31392                                                }
    31393                                        }
    31394                                }
    31395                        } else {
    31396                                if (it.isOutputDouble()) {
    31397                                        while (it.hasNext()) {
    31398                                                for (int j = 0; j < is; j++) {
    31399                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31400                                                        long ox;
    31401                                                        ox = toLong(Math.toRadians(ix));
    31402                                                        oai64data[it.oIndex + j] = ox;
    31403                                                }
    31404                                        }
    31405                                } else {
    31406                                        while (it.hasNext()) {
    31407                                                for (int j = 0; j < is; j++) {
    31408                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31409                                                        long ox;
    31410                                                        ox = toLong(Math.toRadians(ix));
    31411                                                        oai64data[it.oIndex + j] = ox;
    31412                                                }
    31413                                        }
    31414                                }
    31415                        }
    31416                        break;
    31417                case Dataset.ARRAYINT32:
    31418                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    31419                        if (is == 1) {
    31420                                if (it.isOutputDouble()) {
    31421                                        while (it.hasNext()) {
    31422                                                final double ix = it.aDouble;
    31423                                                int ox;
    31424                                                ox = (int) toLong(Math.toRadians(ix));
    31425                                                oai32data[it.oIndex] = ox;
    31426                                        }
    31427                                } else {
    31428                                        while (it.hasNext()) {
    31429                                                final long ix = it.aLong;
    31430                                                int ox;
    31431                                                ox = (int) toLong(Math.toRadians(ix));
    31432                                                oai32data[it.oIndex] = ox;
    31433                                        }
    31434                                }
    31435                        } else if (as == 1) {
    31436                                if (it.isOutputDouble()) {
    31437                                        while (it.hasNext()) {
    31438                                                final double ix = it.aDouble;
    31439                                                int ox;
    31440                                                ox = (int) toLong(Math.toRadians(ix));
    31441                                                for (int j = 0; j < is; j++) {
    31442                                                        oai32data[it.oIndex + j] = ox;
    31443                                                }
    31444                                        }
    31445                                } else {
    31446                                        while (it.hasNext()) {
    31447                                                final long ix = it.aLong;
    31448                                                int ox;
    31449                                                ox = (int) toLong(Math.toRadians(ix));
    31450                                                for (int j = 0; j < is; j++) {
    31451                                                        oai32data[it.oIndex + j] = ox;
    31452                                                }
    31453                                        }
    31454                                }
    31455                        } else {
    31456                                if (it.isOutputDouble()) {
    31457                                        while (it.hasNext()) {
    31458                                                for (int j = 0; j < is; j++) {
    31459                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31460                                                        int ox;
    31461                                                        ox = (int) toLong(Math.toRadians(ix));
    31462                                                        oai32data[it.oIndex + j] = ox;
    31463                                                }
    31464                                        }
    31465                                } else {
    31466                                        while (it.hasNext()) {
    31467                                                for (int j = 0; j < is; j++) {
    31468                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31469                                                        int ox;
    31470                                                        ox = (int) toLong(Math.toRadians(ix));
    31471                                                        oai32data[it.oIndex + j] = ox;
    31472                                                }
    31473                                        }
    31474                                }
    31475                        }
    31476                        break;
    31477                case Dataset.FLOAT32:
    31478                        final float[] of32data = ((FloatDataset) result).getData();
    31479                        if (it.isOutputDouble()) {
    31480                                while (it.hasNext()) {
    31481                                        final double ix = it.aDouble;
    31482                                        float ox;
    31483                                        ox = (float) (Math.toRadians(ix));
    31484                                        of32data[it.oIndex] = ox;
    31485                                }
    31486                        } else {
    31487                                while (it.hasNext()) {
    31488                                        final long ix = it.aLong;
    31489                                        float ox;
    31490                                        ox = (float) (Math.toRadians(ix));
    31491                                        of32data[it.oIndex] = ox;
    31492                                }
    31493                        }
    31494                        break;
    31495                case Dataset.FLOAT64:
    31496                        final double[] of64data = ((DoubleDataset) result).getData();
    31497                        if (it.isOutputDouble()) {
    31498                                while (it.hasNext()) {
    31499                                        final double ix = it.aDouble;
    31500                                        double ox;
    31501                                        ox = (Math.toRadians(ix));
    31502                                        of64data[it.oIndex] = ox;
    31503                                }
    31504                        } else {
    31505                                while (it.hasNext()) {
    31506                                        final long ix = it.aLong;
    31507                                        double ox;
    31508                                        ox = (Math.toRadians(ix));
    31509                                        of64data[it.oIndex] = ox;
    31510                                }
    31511                        }
    31512                        break;
    31513                case Dataset.ARRAYFLOAT32:
    31514                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    31515                        if (is == 1) {
    31516                                if (it.isOutputDouble()) {
    31517                                        while (it.hasNext()) {
    31518                                                final double ix = it.aDouble;
    31519                                                float ox;
    31520                                                ox = (float) (Math.toRadians(ix));
    31521                                                oaf32data[it.oIndex] = ox;
    31522                                        }
    31523                                } else {
    31524                                        while (it.hasNext()) {
    31525                                                final long ix = it.aLong;
    31526                                                float ox;
    31527                                                ox = (float) (Math.toRadians(ix));
    31528                                                oaf32data[it.oIndex] = ox;
    31529                                        }
    31530                                }
    31531                        } else if (as == 1) {
    31532                                if (it.isOutputDouble()) {
    31533                                        while (it.hasNext()) {
    31534                                                final double ix = it.aDouble;
    31535                                                float ox;
    31536                                                ox = (float) (Math.toRadians(ix));
    31537                                                for (int j = 0; j < is; j++) {
    31538                                                        oaf32data[it.oIndex + j] = ox;
    31539                                                }
    31540                                        }
    31541                                } else {
    31542                                        while (it.hasNext()) {
    31543                                                final long ix = it.aLong;
    31544                                                float ox;
    31545                                                ox = (float) (Math.toRadians(ix));
    31546                                                for (int j = 0; j < is; j++) {
    31547                                                        oaf32data[it.oIndex + j] = ox;
    31548                                                }
    31549                                        }
    31550                                }
    31551                        } else {
    31552                                if (it.isOutputDouble()) {
    31553                                        while (it.hasNext()) {
    31554                                                for (int j = 0; j < is; j++) {
    31555                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31556                                                        float ox;
    31557                                                        ox = (float) (Math.toRadians(ix));
    31558                                                        oaf32data[it.oIndex + j] = ox;
    31559                                                }
    31560                                        }
    31561                                } else {
    31562                                        while (it.hasNext()) {
    31563                                                for (int j = 0; j < is; j++) {
    31564                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31565                                                        float ox;
    31566                                                        ox = (float) (Math.toRadians(ix));
    31567                                                        oaf32data[it.oIndex + j] = ox;
    31568                                                }
    31569                                        }
    31570                                }
    31571                        }
    31572                        break;
    31573                case Dataset.ARRAYFLOAT64:
    31574                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    31575                        if (is == 1) {
    31576                                if (it.isOutputDouble()) {
    31577                                        while (it.hasNext()) {
    31578                                                final double ix = it.aDouble;
    31579                                                double ox;
    31580                                                ox = (Math.toRadians(ix));
    31581                                                oaf64data[it.oIndex] = ox;
    31582                                        }
    31583                                } else {
    31584                                        while (it.hasNext()) {
    31585                                                final long ix = it.aLong;
    31586                                                double ox;
    31587                                                ox = (Math.toRadians(ix));
    31588                                                oaf64data[it.oIndex] = ox;
    31589                                        }
    31590                                }
    31591                        } else if (as == 1) {
    31592                                if (it.isOutputDouble()) {
    31593                                        while (it.hasNext()) {
    31594                                                final double ix = it.aDouble;
    31595                                                double ox;
    31596                                                ox = (Math.toRadians(ix));
    31597                                                for (int j = 0; j < is; j++) {
    31598                                                        oaf64data[it.oIndex + j] = ox;
    31599                                                }
    31600                                        }
    31601                                } else {
    31602                                        while (it.hasNext()) {
    31603                                                final long ix = it.aLong;
    31604                                                double ox;
    31605                                                ox = (Math.toRadians(ix));
    31606                                                for (int j = 0; j < is; j++) {
    31607                                                        oaf64data[it.oIndex + j] = ox;
    31608                                                }
    31609                                        }
    31610                                }
    31611                        } else {
    31612                                if (it.isOutputDouble()) {
    31613                                        while (it.hasNext()) {
    31614                                                for (int j = 0; j < is; j++) {
    31615                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31616                                                        double ox;
    31617                                                        ox = (Math.toRadians(ix));
    31618                                                        oaf64data[it.oIndex + j] = ox;
    31619                                                }
    31620                                        }
    31621                                } else {
    31622                                        while (it.hasNext()) {
    31623                                                for (int j = 0; j < is; j++) {
    31624                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31625                                                        double ox;
    31626                                                        ox = (Math.toRadians(ix));
    31627                                                        oaf64data[it.oIndex + j] = ox;
    31628                                                }
    31629                                        }
    31630                                }
    31631                        }
    31632                        break;
    31633                case Dataset.COMPLEX64:
    31634                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    31635                        if (as == 1) {
    31636                                final double iy = 0;
    31637                                while (it.hasNext()) {
    31638                                        final double ix = it.aDouble;
    31639                                        float ox;
    31640                                        float oy;
    31641                                        ox = (float) (Math.toRadians(ix));
    31642                                        oy = (float) (Math.toRadians(iy));
    31643                                        oc64data[it.oIndex] = ox;
    31644                                        oc64data[it.oIndex + 1] = oy;
    31645                                }
    31646                        } else {
    31647                                while (it.hasNext()) {
    31648                                        final double ix = it.aDouble;
    31649                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    31650                                        float ox;
    31651                                        float oy;
    31652                                        ox = (float) (Math.toRadians(ix));
    31653                                        oy = (float) (Math.toRadians(iy));
    31654                                        oc64data[it.oIndex] = ox;
    31655                                        oc64data[it.oIndex + 1] = oy;
    31656                                }
    31657                        }
    31658                        break;
    31659                case Dataset.COMPLEX128:
    31660                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    31661                        if (as == 1) {
    31662                                final double iy = 0;
    31663                                while (it.hasNext()) {
    31664                                        final double ix = it.aDouble;
    31665                                        double ox;
    31666                                        double oy;
    31667                                        ox = (Math.toRadians(ix));
    31668                                        oy = (Math.toRadians(iy));
    31669                                        oc128data[it.oIndex] = ox;
    31670                                        oc128data[it.oIndex + 1] = oy;
    31671                                }
    31672                        } else {
    31673                                while (it.hasNext()) {
    31674                                        final double ix = it.aDouble;
    31675                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    31676                                        double ox;
    31677                                        double oy;
    31678                                        ox = (Math.toRadians(ix));
    31679                                        oy = (Math.toRadians(iy));
    31680                                        oc128data[it.oIndex] = ox;
    31681                                        oc128data[it.oIndex + 1] = oy;
    31682                                }
    31683                        }
    31684                        break;
    31685                default:
    31686                        throw new IllegalArgumentException("toRadians supports integer, compound integer, real, compound real, complex datasets only");
    31687                }
    31688
    31689                addFunctionName(result, "toRadians");
    31690                return result;
    31691        }
    31692
    31693        /**
    31694         * signum - sign of each element
    31695         * @param a
    31696         * @return dataset
    31697         */
    31698        public static Dataset signum(final Object a) {
    31699                return signum(a, null);
    31700        }
    31701
    31702        /**
    31703         * signum - sign of each element
    31704         * @param a
    31705         * @param o output can be null - in which case, a new dataset is created
    31706         * @return dataset
    31707         */
    31708        public static Dataset signum(final Object a, final Dataset o) {
    31709                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    31710                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    31711                final Dataset result = it.getOutput();
    31712                final int is = result.getElementsPerItem();
    31713                final int as = da.getElementsPerItem();
    31714                final int dt = result.getDType();
    31715
    31716                switch(dt) {
    31717                case Dataset.INT8:
    31718                        final byte[] oi8data = ((ByteDataset) result).getData();
    31719                        if (it.isOutputDouble()) {
    31720                                while (it.hasNext()) {
    31721                                        final double ix = it.aDouble;
    31722                                        byte ox;
    31723                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31724                                        oi8data[it.oIndex] = ox;
    31725                                }
    31726                        } else {
    31727                                while (it.hasNext()) {
    31728                                        final long ix = it.aLong;
    31729                                        byte ox;
    31730                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31731                                        oi8data[it.oIndex] = ox;
    31732                                }
    31733                        }
    31734                        break;
    31735                case Dataset.INT16:
    31736                        final short[] oi16data = ((ShortDataset) result).getData();
    31737                        if (it.isOutputDouble()) {
    31738                                while (it.hasNext()) {
    31739                                        final double ix = it.aDouble;
    31740                                        short ox;
    31741                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31742                                        oi16data[it.oIndex] = ox;
    31743                                }
    31744                        } else {
    31745                                while (it.hasNext()) {
    31746                                        final long ix = it.aLong;
    31747                                        short ox;
    31748                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31749                                        oi16data[it.oIndex] = ox;
    31750                                }
    31751                        }
    31752                        break;
    31753                case Dataset.INT64:
    31754                        final long[] oi64data = ((LongDataset) result).getData();
    31755                        if (it.isOutputDouble()) {
    31756                                while (it.hasNext()) {
    31757                                        final double ix = it.aDouble;
    31758                                        long ox;
    31759                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31760                                        oi64data[it.oIndex] = ox;
    31761                                }
    31762                        } else {
    31763                                while (it.hasNext()) {
    31764                                        final long ix = it.aLong;
    31765                                        long ox;
    31766                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31767                                        oi64data[it.oIndex] = ox;
    31768                                }
    31769                        }
    31770                        break;
    31771                case Dataset.INT32:
    31772                        final int[] oi32data = ((IntegerDataset) result).getData();
    31773                        if (it.isOutputDouble()) {
    31774                                while (it.hasNext()) {
    31775                                        final double ix = it.aDouble;
    31776                                        int ox;
    31777                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31778                                        oi32data[it.oIndex] = ox;
    31779                                }
    31780                        } else {
    31781                                while (it.hasNext()) {
    31782                                        final long ix = it.aLong;
    31783                                        int ox;
    31784                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31785                                        oi32data[it.oIndex] = ox;
    31786                                }
    31787                        }
    31788                        break;
    31789                case Dataset.ARRAYINT8:
    31790                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    31791                        if (is == 1) {
    31792                                if (it.isOutputDouble()) {
    31793                                        while (it.hasNext()) {
    31794                                                final double ix = it.aDouble;
    31795                                                byte ox;
    31796                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31797                                                oai8data[it.oIndex] = ox;
    31798                                        }
    31799                                } else {
    31800                                        while (it.hasNext()) {
    31801                                                final long ix = it.aLong;
    31802                                                byte ox;
    31803                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31804                                                oai8data[it.oIndex] = ox;
    31805                                        }
    31806                                }
    31807                        } else if (as == 1) {
    31808                                if (it.isOutputDouble()) {
    31809                                        while (it.hasNext()) {
    31810                                                final double ix = it.aDouble;
    31811                                                byte ox;
    31812                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31813                                                for (int j = 0; j < is; j++) {
    31814                                                        oai8data[it.oIndex + j] = ox;
    31815                                                }
    31816                                        }
    31817                                } else {
    31818                                        while (it.hasNext()) {
    31819                                                final long ix = it.aLong;
    31820                                                byte ox;
    31821                                                ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31822                                                for (int j = 0; j < is; j++) {
    31823                                                        oai8data[it.oIndex + j] = ox;
    31824                                                }
    31825                                        }
    31826                                }
    31827                        } else {
    31828                                if (it.isOutputDouble()) {
    31829                                        while (it.hasNext()) {
    31830                                                for (int j = 0; j < is; j++) {
    31831                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31832                                                        byte ox;
    31833                                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31834                                                        oai8data[it.oIndex + j] = ox;
    31835                                                }
    31836                                        }
    31837                                } else {
    31838                                        while (it.hasNext()) {
    31839                                                for (int j = 0; j < is; j++) {
    31840                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31841                                                        byte ox;
    31842                                                        ox = (byte) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31843                                                        oai8data[it.oIndex + j] = ox;
    31844                                                }
    31845                                        }
    31846                                }
    31847                        }
    31848                        break;
    31849                case Dataset.ARRAYINT16:
    31850                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    31851                        if (is == 1) {
    31852                                if (it.isOutputDouble()) {
    31853                                        while (it.hasNext()) {
    31854                                                final double ix = it.aDouble;
    31855                                                short ox;
    31856                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31857                                                oai16data[it.oIndex] = ox;
    31858                                        }
    31859                                } else {
    31860                                        while (it.hasNext()) {
    31861                                                final long ix = it.aLong;
    31862                                                short ox;
    31863                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31864                                                oai16data[it.oIndex] = ox;
    31865                                        }
    31866                                }
    31867                        } else if (as == 1) {
    31868                                if (it.isOutputDouble()) {
    31869                                        while (it.hasNext()) {
    31870                                                final double ix = it.aDouble;
    31871                                                short ox;
    31872                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31873                                                for (int j = 0; j < is; j++) {
    31874                                                        oai16data[it.oIndex + j] = ox;
    31875                                                }
    31876                                        }
    31877                                } else {
    31878                                        while (it.hasNext()) {
    31879                                                final long ix = it.aLong;
    31880                                                short ox;
    31881                                                ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31882                                                for (int j = 0; j < is; j++) {
    31883                                                        oai16data[it.oIndex + j] = ox;
    31884                                                }
    31885                                        }
    31886                                }
    31887                        } else {
    31888                                if (it.isOutputDouble()) {
    31889                                        while (it.hasNext()) {
    31890                                                for (int j = 0; j < is; j++) {
    31891                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31892                                                        short ox;
    31893                                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31894                                                        oai16data[it.oIndex + j] = ox;
    31895                                                }
    31896                                        }
    31897                                } else {
    31898                                        while (it.hasNext()) {
    31899                                                for (int j = 0; j < is; j++) {
    31900                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31901                                                        short ox;
    31902                                                        ox = (short) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31903                                                        oai16data[it.oIndex + j] = ox;
    31904                                                }
    31905                                        }
    31906                                }
    31907                        }
    31908                        break;
    31909                case Dataset.ARRAYINT64:
    31910                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    31911                        if (is == 1) {
    31912                                if (it.isOutputDouble()) {
    31913                                        while (it.hasNext()) {
    31914                                                final double ix = it.aDouble;
    31915                                                long ox;
    31916                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31917                                                oai64data[it.oIndex] = ox;
    31918                                        }
    31919                                } else {
    31920                                        while (it.hasNext()) {
    31921                                                final long ix = it.aLong;
    31922                                                long ox;
    31923                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31924                                                oai64data[it.oIndex] = ox;
    31925                                        }
    31926                                }
    31927                        } else if (as == 1) {
    31928                                if (it.isOutputDouble()) {
    31929                                        while (it.hasNext()) {
    31930                                                final double ix = it.aDouble;
    31931                                                long ox;
    31932                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31933                                                for (int j = 0; j < is; j++) {
    31934                                                        oai64data[it.oIndex + j] = ox;
    31935                                                }
    31936                                        }
    31937                                } else {
    31938                                        while (it.hasNext()) {
    31939                                                final long ix = it.aLong;
    31940                                                long ox;
    31941                                                ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31942                                                for (int j = 0; j < is; j++) {
    31943                                                        oai64data[it.oIndex + j] = ox;
    31944                                                }
    31945                                        }
    31946                                }
    31947                        } else {
    31948                                if (it.isOutputDouble()) {
    31949                                        while (it.hasNext()) {
    31950                                                for (int j = 0; j < is; j++) {
    31951                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    31952                                                        long ox;
    31953                                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31954                                                        oai64data[it.oIndex + j] = ox;
    31955                                                }
    31956                                        }
    31957                                } else {
    31958                                        while (it.hasNext()) {
    31959                                                for (int j = 0; j < is; j++) {
    31960                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    31961                                                        long ox;
    31962                                                        ox = toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31963                                                        oai64data[it.oIndex + j] = ox;
    31964                                                }
    31965                                        }
    31966                                }
    31967                        }
    31968                        break;
    31969                case Dataset.ARRAYINT32:
    31970                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    31971                        if (is == 1) {
    31972                                if (it.isOutputDouble()) {
    31973                                        while (it.hasNext()) {
    31974                                                final double ix = it.aDouble;
    31975                                                int ox;
    31976                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31977                                                oai32data[it.oIndex] = ox;
    31978                                        }
    31979                                } else {
    31980                                        while (it.hasNext()) {
    31981                                                final long ix = it.aLong;
    31982                                                int ox;
    31983                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31984                                                oai32data[it.oIndex] = ox;
    31985                                        }
    31986                                }
    31987                        } else if (as == 1) {
    31988                                if (it.isOutputDouble()) {
    31989                                        while (it.hasNext()) {
    31990                                                final double ix = it.aDouble;
    31991                                                int ox;
    31992                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    31993                                                for (int j = 0; j < is; j++) {
    31994                                                        oai32data[it.oIndex + j] = ox;
    31995                                                }
    31996                                        }
    31997                                } else {
    31998                                        while (it.hasNext()) {
    31999                                                final long ix = it.aLong;
    32000                                                int ox;
    32001                                                ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    32002                                                for (int j = 0; j < is; j++) {
    32003                                                        oai32data[it.oIndex + j] = ox;
    32004                                                }
    32005                                        }
    32006                                }
    32007                        } else {
    32008                                if (it.isOutputDouble()) {
    32009                                        while (it.hasNext()) {
    32010                                                for (int j = 0; j < is; j++) {
    32011                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32012                                                        int ox;
    32013                                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    32014                                                        oai32data[it.oIndex + j] = ox;
    32015                                                }
    32016                                        }
    32017                                } else {
    32018                                        while (it.hasNext()) {
    32019                                                for (int j = 0; j < is; j++) {
    32020                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32021                                                        int ox;
    32022                                                        ox = (int) toLong(ix > 0 ? 1 : (ix < 0 ? -1 : 0));
    32023                                                        oai32data[it.oIndex + j] = ox;
    32024                                                }
    32025                                        }
    32026                                }
    32027                        }
    32028                        break;
    32029                case Dataset.FLOAT32:
    32030                        final float[] of32data = ((FloatDataset) result).getData();
    32031                        if (it.isOutputDouble()) {
    32032                                while (it.hasNext()) {
    32033                                        final double ix = it.aDouble;
    32034                                        float ox;
    32035                                        ox = (float) (Math.signum(ix));
    32036                                        of32data[it.oIndex] = ox;
    32037                                }
    32038                        } else {
    32039                                while (it.hasNext()) {
    32040                                        final long ix = it.aLong;
    32041                                        float ox;
    32042                                        ox = (float) (Math.signum(ix));
    32043                                        of32data[it.oIndex] = ox;
    32044                                }
    32045                        }
    32046                        break;
    32047                case Dataset.FLOAT64:
    32048                        final double[] of64data = ((DoubleDataset) result).getData();
    32049                        if (it.isOutputDouble()) {
    32050                                while (it.hasNext()) {
    32051                                        final double ix = it.aDouble;
    32052                                        double ox;
    32053                                        ox = (Math.signum(ix));
    32054                                        of64data[it.oIndex] = ox;
    32055                                }
    32056                        } else {
    32057                                while (it.hasNext()) {
    32058                                        final long ix = it.aLong;
    32059                                        double ox;
    32060                                        ox = (Math.signum(ix));
    32061                                        of64data[it.oIndex] = ox;
    32062                                }
    32063                        }
    32064                        break;
    32065                case Dataset.ARRAYFLOAT32:
    32066                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    32067                        if (is == 1) {
    32068                                if (it.isOutputDouble()) {
    32069                                        while (it.hasNext()) {
    32070                                                final double ix = it.aDouble;
    32071                                                float ox;
    32072                                                ox = (float) (Math.signum(ix));
    32073                                                oaf32data[it.oIndex] = ox;
    32074                                        }
    32075                                } else {
    32076                                        while (it.hasNext()) {
    32077                                                final long ix = it.aLong;
    32078                                                float ox;
    32079                                                ox = (float) (Math.signum(ix));
    32080                                                oaf32data[it.oIndex] = ox;
    32081                                        }
    32082                                }
    32083                        } else if (as == 1) {
    32084                                if (it.isOutputDouble()) {
    32085                                        while (it.hasNext()) {
    32086                                                final double ix = it.aDouble;
    32087                                                float ox;
    32088                                                ox = (float) (Math.signum(ix));
    32089                                                for (int j = 0; j < is; j++) {
    32090                                                        oaf32data[it.oIndex + j] = ox;
    32091                                                }
    32092                                        }
    32093                                } else {
    32094                                        while (it.hasNext()) {
    32095                                                final long ix = it.aLong;
    32096                                                float ox;
    32097                                                ox = (float) (Math.signum(ix));
    32098                                                for (int j = 0; j < is; j++) {
    32099                                                        oaf32data[it.oIndex + j] = ox;
    32100                                                }
    32101                                        }
    32102                                }
    32103                        } else {
    32104                                if (it.isOutputDouble()) {
    32105                                        while (it.hasNext()) {
    32106                                                for (int j = 0; j < is; j++) {
    32107                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32108                                                        float ox;
    32109                                                        ox = (float) (Math.signum(ix));
    32110                                                        oaf32data[it.oIndex + j] = ox;
    32111                                                }
    32112                                        }
    32113                                } else {
    32114                                        while (it.hasNext()) {
    32115                                                for (int j = 0; j < is; j++) {
    32116                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32117                                                        float ox;
    32118                                                        ox = (float) (Math.signum(ix));
    32119                                                        oaf32data[it.oIndex + j] = ox;
    32120                                                }
    32121                                        }
    32122                                }
    32123                        }
    32124                        break;
    32125                case Dataset.ARRAYFLOAT64:
    32126                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    32127                        if (is == 1) {
    32128                                if (it.isOutputDouble()) {
    32129                                        while (it.hasNext()) {
    32130                                                final double ix = it.aDouble;
    32131                                                double ox;
    32132                                                ox = (Math.signum(ix));
    32133                                                oaf64data[it.oIndex] = ox;
    32134                                        }
    32135                                } else {
    32136                                        while (it.hasNext()) {
    32137                                                final long ix = it.aLong;
    32138                                                double ox;
    32139                                                ox = (Math.signum(ix));
    32140                                                oaf64data[it.oIndex] = ox;
    32141                                        }
    32142                                }
    32143                        } else if (as == 1) {
    32144                                if (it.isOutputDouble()) {
    32145                                        while (it.hasNext()) {
    32146                                                final double ix = it.aDouble;
    32147                                                double ox;
    32148                                                ox = (Math.signum(ix));
    32149                                                for (int j = 0; j < is; j++) {
    32150                                                        oaf64data[it.oIndex + j] = ox;
    32151                                                }
    32152                                        }
    32153                                } else {
    32154                                        while (it.hasNext()) {
    32155                                                final long ix = it.aLong;
    32156                                                double ox;
    32157                                                ox = (Math.signum(ix));
    32158                                                for (int j = 0; j < is; j++) {
    32159                                                        oaf64data[it.oIndex + j] = ox;
    32160                                                }
    32161                                        }
    32162                                }
    32163                        } else {
    32164                                if (it.isOutputDouble()) {
    32165                                        while (it.hasNext()) {
    32166                                                for (int j = 0; j < is; j++) {
    32167                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32168                                                        double ox;
    32169                                                        ox = (Math.signum(ix));
    32170                                                        oaf64data[it.oIndex + j] = ox;
    32171                                                }
    32172                                        }
    32173                                } else {
    32174                                        while (it.hasNext()) {
    32175                                                for (int j = 0; j < is; j++) {
    32176                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32177                                                        double ox;
    32178                                                        ox = (Math.signum(ix));
    32179                                                        oaf64data[it.oIndex + j] = ox;
    32180                                                }
    32181                                        }
    32182                                }
    32183                        }
    32184                        break;
    32185                case Dataset.COMPLEX64:
    32186                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    32187                        if (as == 1) {
    32188                                final double iy = 0;
    32189                                while (it.hasNext()) {
    32190                                        final double ix = it.aDouble;
    32191                                        float ox;
    32192                                        float oy;
    32193                                        ox = (float) (Math.signum(ix));
    32194                                        oy = (float) (Math.signum(iy));
    32195                                        oc64data[it.oIndex] = ox;
    32196                                        oc64data[it.oIndex + 1] = oy;
    32197                                }
    32198                        } else {
    32199                                while (it.hasNext()) {
    32200                                        final double ix = it.aDouble;
    32201                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    32202                                        float ox;
    32203                                        float oy;
    32204                                        ox = (float) (Math.signum(ix));
    32205                                        oy = (float) (Math.signum(iy));
    32206                                        oc64data[it.oIndex] = ox;
    32207                                        oc64data[it.oIndex + 1] = oy;
    32208                                }
    32209                        }
    32210                        break;
    32211                case Dataset.COMPLEX128:
    32212                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    32213                        if (as == 1) {
    32214                                final double iy = 0;
    32215                                while (it.hasNext()) {
    32216                                        final double ix = it.aDouble;
    32217                                        double ox;
    32218                                        double oy;
    32219                                        ox = (Math.signum(ix));
    32220                                        oy = (Math.signum(iy));
    32221                                        oc128data[it.oIndex] = ox;
    32222                                        oc128data[it.oIndex + 1] = oy;
    32223                                }
    32224                        } else {
    32225                                while (it.hasNext()) {
    32226                                        final double ix = it.aDouble;
    32227                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    32228                                        double ox;
    32229                                        double oy;
    32230                                        ox = (Math.signum(ix));
    32231                                        oy = (Math.signum(iy));
    32232                                        oc128data[it.oIndex] = ox;
    32233                                        oc128data[it.oIndex + 1] = oy;
    32234                                }
    32235                        }
    32236                        break;
    32237                default:
    32238                        throw new IllegalArgumentException("signum supports integer, compound integer, real, compound real, complex datasets only");
    32239                }
    32240
    32241                addFunctionName(result, "signum");
    32242                return result;
    32243        }
    32244
    32245        /**
    32246         * negative - negative value of each element
    32247         * @param a
    32248         * @return dataset
    32249         */
    32250        public static Dataset negative(final Object a) {
    32251                return negative(a, null);
    32252        }
    32253
    32254        /**
    32255         * negative - negative value of each element
    32256         * @param a
    32257         * @param o output can be null - in which case, a new dataset is created
    32258         * @return dataset
    32259         */
    32260        public static Dataset negative(final Object a, final Dataset o) {
    32261                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    32262                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    32263                final Dataset result = it.getOutput();
    32264                final int is = result.getElementsPerItem();
    32265                final int as = da.getElementsPerItem();
    32266                final int dt = result.getDType();
    32267
    32268                switch(dt) {
    32269                case Dataset.INT8:
    32270                        final byte[] oi8data = ((ByteDataset) result).getData();
    32271                        if (it.isOutputDouble()) {
    32272                                while (it.hasNext()) {
    32273                                        final double ix = it.aDouble;
    32274                                        byte ox;
    32275                                        ox = (byte) toLong(-ix);
    32276                                        oi8data[it.oIndex] = ox;
    32277                                }
    32278                        } else {
    32279                                while (it.hasNext()) {
    32280                                        final long ix = it.aLong;
    32281                                        byte ox;
    32282                                        ox = (byte) toLong(-ix);
    32283                                        oi8data[it.oIndex] = ox;
    32284                                }
    32285                        }
    32286                        break;
    32287                case Dataset.INT16:
    32288                        final short[] oi16data = ((ShortDataset) result).getData();
    32289                        if (it.isOutputDouble()) {
    32290                                while (it.hasNext()) {
    32291                                        final double ix = it.aDouble;
    32292                                        short ox;
    32293                                        ox = (short) toLong(-ix);
    32294                                        oi16data[it.oIndex] = ox;
    32295                                }
    32296                        } else {
    32297                                while (it.hasNext()) {
    32298                                        final long ix = it.aLong;
    32299                                        short ox;
    32300                                        ox = (short) toLong(-ix);
    32301                                        oi16data[it.oIndex] = ox;
    32302                                }
    32303                        }
    32304                        break;
    32305                case Dataset.INT64:
    32306                        final long[] oi64data = ((LongDataset) result).getData();
    32307                        if (it.isOutputDouble()) {
    32308                                while (it.hasNext()) {
    32309                                        final double ix = it.aDouble;
    32310                                        long ox;
    32311                                        ox = toLong(-ix);
    32312                                        oi64data[it.oIndex] = ox;
    32313                                }
    32314                        } else {
    32315                                while (it.hasNext()) {
    32316                                        final long ix = it.aLong;
    32317                                        long ox;
    32318                                        ox = toLong(-ix);
    32319                                        oi64data[it.oIndex] = ox;
    32320                                }
    32321                        }
    32322                        break;
    32323                case Dataset.INT32:
    32324                        final int[] oi32data = ((IntegerDataset) result).getData();
    32325                        if (it.isOutputDouble()) {
    32326                                while (it.hasNext()) {
    32327                                        final double ix = it.aDouble;
    32328                                        int ox;
    32329                                        ox = (int) toLong(-ix);
    32330                                        oi32data[it.oIndex] = ox;
    32331                                }
    32332                        } else {
    32333                                while (it.hasNext()) {
    32334                                        final long ix = it.aLong;
    32335                                        int ox;
    32336                                        ox = (int) toLong(-ix);
    32337                                        oi32data[it.oIndex] = ox;
    32338                                }
    32339                        }
    32340                        break;
    32341                case Dataset.ARRAYINT8:
    32342                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    32343                        if (is == 1) {
    32344                                if (it.isOutputDouble()) {
    32345                                        while (it.hasNext()) {
    32346                                                final double ix = it.aDouble;
    32347                                                byte ox;
    32348                                                ox = (byte) toLong(-ix);
    32349                                                oai8data[it.oIndex] = ox;
    32350                                        }
    32351                                } else {
    32352                                        while (it.hasNext()) {
    32353                                                final long ix = it.aLong;
    32354                                                byte ox;
    32355                                                ox = (byte) toLong(-ix);
    32356                                                oai8data[it.oIndex] = ox;
    32357                                        }
    32358                                }
    32359                        } else if (as == 1) {
    32360                                if (it.isOutputDouble()) {
    32361                                        while (it.hasNext()) {
    32362                                                final double ix = it.aDouble;
    32363                                                byte ox;
    32364                                                ox = (byte) toLong(-ix);
    32365                                                for (int j = 0; j < is; j++) {
    32366                                                        oai8data[it.oIndex + j] = ox;
    32367                                                }
    32368                                        }
    32369                                } else {
    32370                                        while (it.hasNext()) {
    32371                                                final long ix = it.aLong;
    32372                                                byte ox;
    32373                                                ox = (byte) toLong(-ix);
    32374                                                for (int j = 0; j < is; j++) {
    32375                                                        oai8data[it.oIndex + j] = ox;
    32376                                                }
    32377                                        }
    32378                                }
    32379                        } else {
    32380                                if (it.isOutputDouble()) {
    32381                                        while (it.hasNext()) {
    32382                                                for (int j = 0; j < is; j++) {
    32383                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32384                                                        byte ox;
    32385                                                        ox = (byte) toLong(-ix);
    32386                                                        oai8data[it.oIndex + j] = ox;
    32387                                                }
    32388                                        }
    32389                                } else {
    32390                                        while (it.hasNext()) {
    32391                                                for (int j = 0; j < is; j++) {
    32392                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32393                                                        byte ox;
    32394                                                        ox = (byte) toLong(-ix);
    32395                                                        oai8data[it.oIndex + j] = ox;
    32396                                                }
    32397                                        }
    32398                                }
    32399                        }
    32400                        break;
    32401                case Dataset.ARRAYINT16:
    32402                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    32403                        if (is == 1) {
    32404                                if (it.isOutputDouble()) {
    32405                                        while (it.hasNext()) {
    32406                                                final double ix = it.aDouble;
    32407                                                short ox;
    32408                                                ox = (short) toLong(-ix);
    32409                                                oai16data[it.oIndex] = ox;
    32410                                        }
    32411                                } else {
    32412                                        while (it.hasNext()) {
    32413                                                final long ix = it.aLong;
    32414                                                short ox;
    32415                                                ox = (short) toLong(-ix);
    32416                                                oai16data[it.oIndex] = ox;
    32417                                        }
    32418                                }
    32419                        } else if (as == 1) {
    32420                                if (it.isOutputDouble()) {
    32421                                        while (it.hasNext()) {
    32422                                                final double ix = it.aDouble;
    32423                                                short ox;
    32424                                                ox = (short) toLong(-ix);
    32425                                                for (int j = 0; j < is; j++) {
    32426                                                        oai16data[it.oIndex + j] = ox;
    32427                                                }
    32428                                        }
    32429                                } else {
    32430                                        while (it.hasNext()) {
    32431                                                final long ix = it.aLong;
    32432                                                short ox;
    32433                                                ox = (short) toLong(-ix);
    32434                                                for (int j = 0; j < is; j++) {
    32435                                                        oai16data[it.oIndex + j] = ox;
    32436                                                }
    32437                                        }
    32438                                }
    32439                        } else {
    32440                                if (it.isOutputDouble()) {
    32441                                        while (it.hasNext()) {
    32442                                                for (int j = 0; j < is; j++) {
    32443                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32444                                                        short ox;
    32445                                                        ox = (short) toLong(-ix);
    32446                                                        oai16data[it.oIndex + j] = ox;
    32447                                                }
    32448                                        }
    32449                                } else {
    32450                                        while (it.hasNext()) {
    32451                                                for (int j = 0; j < is; j++) {
    32452                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32453                                                        short ox;
    32454                                                        ox = (short) toLong(-ix);
    32455                                                        oai16data[it.oIndex + j] = ox;
    32456                                                }
    32457                                        }
    32458                                }
    32459                        }
    32460                        break;
    32461                case Dataset.ARRAYINT64:
    32462                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    32463                        if (is == 1) {
    32464                                if (it.isOutputDouble()) {
    32465                                        while (it.hasNext()) {
    32466                                                final double ix = it.aDouble;
    32467                                                long ox;
    32468                                                ox = toLong(-ix);
    32469                                                oai64data[it.oIndex] = ox;
    32470                                        }
    32471                                } else {
    32472                                        while (it.hasNext()) {
    32473                                                final long ix = it.aLong;
    32474                                                long ox;
    32475                                                ox = toLong(-ix);
    32476                                                oai64data[it.oIndex] = ox;
    32477                                        }
    32478                                }
    32479                        } else if (as == 1) {
    32480                                if (it.isOutputDouble()) {
    32481                                        while (it.hasNext()) {
    32482                                                final double ix = it.aDouble;
    32483                                                long ox;
    32484                                                ox = toLong(-ix);
    32485                                                for (int j = 0; j < is; j++) {
    32486                                                        oai64data[it.oIndex + j] = ox;
    32487                                                }
    32488                                        }
    32489                                } else {
    32490                                        while (it.hasNext()) {
    32491                                                final long ix = it.aLong;
    32492                                                long ox;
    32493                                                ox = toLong(-ix);
    32494                                                for (int j = 0; j < is; j++) {
    32495                                                        oai64data[it.oIndex + j] = ox;
    32496                                                }
    32497                                        }
    32498                                }
    32499                        } else {
    32500                                if (it.isOutputDouble()) {
    32501                                        while (it.hasNext()) {
    32502                                                for (int j = 0; j < is; j++) {
    32503                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32504                                                        long ox;
    32505                                                        ox = toLong(-ix);
    32506                                                        oai64data[it.oIndex + j] = ox;
    32507                                                }
    32508                                        }
    32509                                } else {
    32510                                        while (it.hasNext()) {
    32511                                                for (int j = 0; j < is; j++) {
    32512                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32513                                                        long ox;
    32514                                                        ox = toLong(-ix);
    32515                                                        oai64data[it.oIndex + j] = ox;
    32516                                                }
    32517                                        }
    32518                                }
    32519                        }
    32520                        break;
    32521                case Dataset.ARRAYINT32:
    32522                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    32523                        if (is == 1) {
    32524                                if (it.isOutputDouble()) {
    32525                                        while (it.hasNext()) {
    32526                                                final double ix = it.aDouble;
    32527                                                int ox;
    32528                                                ox = (int) toLong(-ix);
    32529                                                oai32data[it.oIndex] = ox;
    32530                                        }
    32531                                } else {
    32532                                        while (it.hasNext()) {
    32533                                                final long ix = it.aLong;
    32534                                                int ox;
    32535                                                ox = (int) toLong(-ix);
    32536                                                oai32data[it.oIndex] = ox;
    32537                                        }
    32538                                }
    32539                        } else if (as == 1) {
    32540                                if (it.isOutputDouble()) {
    32541                                        while (it.hasNext()) {
    32542                                                final double ix = it.aDouble;
    32543                                                int ox;
    32544                                                ox = (int) toLong(-ix);
    32545                                                for (int j = 0; j < is; j++) {
    32546                                                        oai32data[it.oIndex + j] = ox;
    32547                                                }
    32548                                        }
    32549                                } else {
    32550                                        while (it.hasNext()) {
    32551                                                final long ix = it.aLong;
    32552                                                int ox;
    32553                                                ox = (int) toLong(-ix);
    32554                                                for (int j = 0; j < is; j++) {
    32555                                                        oai32data[it.oIndex + j] = ox;
    32556                                                }
    32557                                        }
    32558                                }
    32559                        } else {
    32560                                if (it.isOutputDouble()) {
    32561                                        while (it.hasNext()) {
    32562                                                for (int j = 0; j < is; j++) {
    32563                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32564                                                        int ox;
    32565                                                        ox = (int) toLong(-ix);
    32566                                                        oai32data[it.oIndex + j] = ox;
    32567                                                }
    32568                                        }
    32569                                } else {
    32570                                        while (it.hasNext()) {
    32571                                                for (int j = 0; j < is; j++) {
    32572                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32573                                                        int ox;
    32574                                                        ox = (int) toLong(-ix);
    32575                                                        oai32data[it.oIndex + j] = ox;
    32576                                                }
    32577                                        }
    32578                                }
    32579                        }
    32580                        break;
    32581                case Dataset.FLOAT32:
    32582                        final float[] of32data = ((FloatDataset) result).getData();
    32583                        if (it.isOutputDouble()) {
    32584                                while (it.hasNext()) {
    32585                                        final double ix = it.aDouble;
    32586                                        float ox;
    32587                                        ox = (float) (-ix);
    32588                                        of32data[it.oIndex] = ox;
    32589                                }
    32590                        } else {
    32591                                while (it.hasNext()) {
    32592                                        final long ix = it.aLong;
    32593                                        float ox;
    32594                                        ox = (-ix);
    32595                                        of32data[it.oIndex] = ox;
    32596                                }
    32597                        }
    32598                        break;
    32599                case Dataset.FLOAT64:
    32600                        final double[] of64data = ((DoubleDataset) result).getData();
    32601                        if (it.isOutputDouble()) {
    32602                                while (it.hasNext()) {
    32603                                        final double ix = it.aDouble;
    32604                                        double ox;
    32605                                        ox = (-ix);
    32606                                        of64data[it.oIndex] = ox;
    32607                                }
    32608                        } else {
    32609                                while (it.hasNext()) {
    32610                                        final long ix = it.aLong;
    32611                                        double ox;
    32612                                        ox = (-ix);
    32613                                        of64data[it.oIndex] = ox;
    32614                                }
    32615                        }
    32616                        break;
    32617                case Dataset.ARRAYFLOAT32:
    32618                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    32619                        if (is == 1) {
    32620                                if (it.isOutputDouble()) {
    32621                                        while (it.hasNext()) {
    32622                                                final double ix = it.aDouble;
    32623                                                float ox;
    32624                                                ox = (float) (-ix);
    32625                                                oaf32data[it.oIndex] = ox;
    32626                                        }
    32627                                } else {
    32628                                        while (it.hasNext()) {
    32629                                                final long ix = it.aLong;
    32630                                                float ox;
    32631                                                ox = (-ix);
    32632                                                oaf32data[it.oIndex] = ox;
    32633                                        }
    32634                                }
    32635                        } else if (as == 1) {
    32636                                if (it.isOutputDouble()) {
    32637                                        while (it.hasNext()) {
    32638                                                final double ix = it.aDouble;
    32639                                                float ox;
    32640                                                ox = (float) (-ix);
    32641                                                for (int j = 0; j < is; j++) {
    32642                                                        oaf32data[it.oIndex + j] = ox;
    32643                                                }
    32644                                        }
    32645                                } else {
    32646                                        while (it.hasNext()) {
    32647                                                final long ix = it.aLong;
    32648                                                float ox;
    32649                                                ox = (-ix);
    32650                                                for (int j = 0; j < is; j++) {
    32651                                                        oaf32data[it.oIndex + j] = ox;
    32652                                                }
    32653                                        }
    32654                                }
    32655                        } else {
    32656                                if (it.isOutputDouble()) {
    32657                                        while (it.hasNext()) {
    32658                                                for (int j = 0; j < is; j++) {
    32659                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32660                                                        float ox;
    32661                                                        ox = (float) (-ix);
    32662                                                        oaf32data[it.oIndex + j] = ox;
    32663                                                }
    32664                                        }
    32665                                } else {
    32666                                        while (it.hasNext()) {
    32667                                                for (int j = 0; j < is; j++) {
    32668                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32669                                                        float ox;
    32670                                                        ox = (-ix);
    32671                                                        oaf32data[it.oIndex + j] = ox;
    32672                                                }
    32673                                        }
    32674                                }
    32675                        }
    32676                        break;
    32677                case Dataset.ARRAYFLOAT64:
    32678                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    32679                        if (is == 1) {
    32680                                if (it.isOutputDouble()) {
    32681                                        while (it.hasNext()) {
    32682                                                final double ix = it.aDouble;
    32683                                                double ox;
    32684                                                ox = (-ix);
    32685                                                oaf64data[it.oIndex] = ox;
    32686                                        }
    32687                                } else {
    32688                                        while (it.hasNext()) {
    32689                                                final long ix = it.aLong;
    32690                                                double ox;
    32691                                                ox = (-ix);
    32692                                                oaf64data[it.oIndex] = ox;
    32693                                        }
    32694                                }
    32695                        } else if (as == 1) {
    32696                                if (it.isOutputDouble()) {
    32697                                        while (it.hasNext()) {
    32698                                                final double ix = it.aDouble;
    32699                                                double ox;
    32700                                                ox = (-ix);
    32701                                                for (int j = 0; j < is; j++) {
    32702                                                        oaf64data[it.oIndex + j] = ox;
    32703                                                }
    32704                                        }
    32705                                } else {
    32706                                        while (it.hasNext()) {
    32707                                                final long ix = it.aLong;
    32708                                                double ox;
    32709                                                ox = (-ix);
    32710                                                for (int j = 0; j < is; j++) {
    32711                                                        oaf64data[it.oIndex + j] = ox;
    32712                                                }
    32713                                        }
    32714                                }
    32715                        } else {
    32716                                if (it.isOutputDouble()) {
    32717                                        while (it.hasNext()) {
    32718                                                for (int j = 0; j < is; j++) {
    32719                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    32720                                                        double ox;
    32721                                                        ox = (-ix);
    32722                                                        oaf64data[it.oIndex + j] = ox;
    32723                                                }
    32724                                        }
    32725                                } else {
    32726                                        while (it.hasNext()) {
    32727                                                for (int j = 0; j < is; j++) {
    32728                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    32729                                                        double ox;
    32730                                                        ox = (-ix);
    32731                                                        oaf64data[it.oIndex + j] = ox;
    32732                                                }
    32733                                        }
    32734                                }
    32735                        }
    32736                        break;
    32737                case Dataset.COMPLEX64:
    32738                        final float[] oc64data = ((ComplexFloatDataset) result).getData();
    32739                        if (as == 1) {
    32740                                final double iy = 0;
    32741                                while (it.hasNext()) {
    32742                                        final double ix = it.aDouble;
    32743                                        float ox;
    32744                                        float oy;
    32745                                        ox = (float) (-ix);
    32746                                        oy = (float) (-iy);
    32747                                        oc64data[it.oIndex] = ox;
    32748                                        oc64data[it.oIndex + 1] = oy;
    32749                                }
    32750                        } else {
    32751                                while (it.hasNext()) {
    32752                                        final double ix = it.aDouble;
    32753                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    32754                                        float ox;
    32755                                        float oy;
    32756                                        ox = (float) (-ix);
    32757                                        oy = (float) (-iy);
    32758                                        oc64data[it.oIndex] = ox;
    32759                                        oc64data[it.oIndex + 1] = oy;
    32760                                }
    32761                        }
    32762                        break;
    32763                case Dataset.COMPLEX128:
    32764                        final double[] oc128data = ((ComplexDoubleDataset) result).getData();
    32765                        if (as == 1) {
    32766                                final double iy = 0;
    32767                                while (it.hasNext()) {
    32768                                        final double ix = it.aDouble;
    32769                                        double ox;
    32770                                        double oy;
    32771                                        ox = (-ix);
    32772                                        oy = (-iy);
    32773                                        oc128data[it.oIndex] = ox;
    32774                                        oc128data[it.oIndex + 1] = oy;
    32775                                }
    32776                        } else {
    32777                                while (it.hasNext()) {
    32778                                        final double ix = it.aDouble;
    32779                                        final double iy = da.getElementDoubleAbs(it.aIndex + 1);
    32780                                        double ox;
    32781                                        double oy;
    32782                                        ox = (-ix);
    32783                                        oy = (-iy);
    32784                                        oc128data[it.oIndex] = ox;
    32785                                        oc128data[it.oIndex + 1] = oy;
    32786                                }
    32787                        }
    32788                        break;
    32789                default:
    32790                        throw new IllegalArgumentException("negative supports integer, compound integer, real, compound real, complex datasets only");
    32791                }
    32792
    32793                addFunctionName(result, "negative");
    32794                return result;
    32795        }
    32796
    32797        /**
    32798         * clip - clip elements to limits
    32799         * @param a
    32800         * @param pa
    32801         * @param pb
    32802         * @return dataset
    32803         */
    32804        public static Dataset clip(final Object a, final Object pa, final Object pb) {
    32805                return clip(a, null, pa, pb);
    32806        }
    32807
    32808        /**
    32809         * clip - clip elements to limits
    32810         * @param a
    32811         * @param o output can be null - in which case, a new dataset is created
    32812         * @param pa
    32813         * @param pb
    32814         * @return dataset
    32815         */
    32816        public static Dataset clip(final Object a, final Dataset o, final Object pa, final Object pb) {
    32817                final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a);
    32818                final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true);
    32819                final Dataset result = it.getOutput();
    32820                final int is = result.getElementsPerItem();
    32821                final int as = da.getElementsPerItem();
    32822                final int dt = result.getDType();
    32823                final double pax = DTypeUtils.toReal(pa);
    32824                final double pbx = DTypeUtils.toReal(pb);
    32825
    32826                switch(dt) {
    32827                case Dataset.INT8:
    32828                        final byte[] oi8data = ((ByteDataset) result).getData();
    32829                        if (it.isOutputDouble()) {
    32830                                while (it.hasNext()) {
    32831                                        final double ix = it.aDouble;
    32832                                        byte ox;
    32833                                        if (ix < pax)
    32834                                                ox = (byte) toLong(pax);
    32835                                        else if (ix > pbx)
    32836                                                ox = (byte) toLong(pbx);
    32837                                        else
    32838                                                ox = (byte) toLong(ix);
    32839                                        oi8data[it.oIndex] = ox;
    32840                                }
    32841                        } else {
    32842                                while (it.hasNext()) {
    32843                                        final long ix = it.aLong;
    32844                                        byte ox;
    32845                                        if (ix < pax)
    32846                                                ox = (byte) toLong(pax);
    32847                                        else if (ix > pbx)
    32848                                                ox = (byte) toLong(pbx);
    32849                                        else
    32850                                                ox = (byte) toLong(ix);
    32851                                        oi8data[it.oIndex] = ox;
    32852                                }
    32853                        }
    32854                        break;
    32855                case Dataset.INT16:
    32856                        final short[] oi16data = ((ShortDataset) result).getData();
    32857                        if (it.isOutputDouble()) {
    32858                                while (it.hasNext()) {
    32859                                        final double ix = it.aDouble;
    32860                                        short ox;
    32861                                        if (ix < pax)
    32862                                                ox = (short) toLong(pax);
    32863                                        else if (ix > pbx)
    32864                                                ox = (short) toLong(pbx);
    32865                                        else
    32866                                                ox = (short) toLong(ix);
    32867                                        oi16data[it.oIndex] = ox;
    32868                                }
    32869                        } else {
    32870                                while (it.hasNext()) {
    32871                                        final long ix = it.aLong;
    32872                                        short ox;
    32873                                        if (ix < pax)
    32874                                                ox = (short) toLong(pax);
    32875                                        else if (ix > pbx)
    32876                                                ox = (short) toLong(pbx);
    32877                                        else
    32878                                                ox = (short) toLong(ix);
    32879                                        oi16data[it.oIndex] = ox;
    32880                                }
    32881                        }
    32882                        break;
    32883                case Dataset.INT64:
    32884                        final long[] oi64data = ((LongDataset) result).getData();
    32885                        if (it.isOutputDouble()) {
    32886                                while (it.hasNext()) {
    32887                                        final double ix = it.aDouble;
    32888                                        long ox;
    32889                                        if (ix < pax)
    32890                                                ox = toLong(pax);
    32891                                        else if (ix > pbx)
    32892                                                ox = toLong(pbx);
    32893                                        else
    32894                                                ox = toLong(ix);
    32895                                        oi64data[it.oIndex] = ox;
    32896                                }
    32897                        } else {
    32898                                while (it.hasNext()) {
    32899                                        final long ix = it.aLong;
    32900                                        long ox;
    32901                                        if (ix < pax)
    32902                                                ox = toLong(pax);
    32903                                        else if (ix > pbx)
    32904                                                ox = toLong(pbx);
    32905                                        else
    32906                                                ox = toLong(ix);
    32907                                        oi64data[it.oIndex] = ox;
    32908                                }
    32909                        }
    32910                        break;
    32911                case Dataset.INT32:
    32912                        final int[] oi32data = ((IntegerDataset) result).getData();
    32913                        if (it.isOutputDouble()) {
    32914                                while (it.hasNext()) {
    32915                                        final double ix = it.aDouble;
    32916                                        int ox;
    32917                                        if (ix < pax)
    32918                                                ox = (int) toLong(pax);
    32919                                        else if (ix > pbx)
    32920                                                ox = (int) toLong(pbx);
    32921                                        else
    32922                                                ox = (int) toLong(ix);
    32923                                        oi32data[it.oIndex] = ox;
    32924                                }
    32925                        } else {
    32926                                while (it.hasNext()) {
    32927                                        final long ix = it.aLong;
    32928                                        int ox;
    32929                                        if (ix < pax)
    32930                                                ox = (int) toLong(pax);
    32931                                        else if (ix > pbx)
    32932                                                ox = (int) toLong(pbx);
    32933                                        else
    32934                                                ox = (int) toLong(ix);
    32935                                        oi32data[it.oIndex] = ox;
    32936                                }
    32937                        }
    32938                        break;
    32939                case Dataset.ARRAYINT8:
    32940                        final byte[] oai8data = ((CompoundByteDataset) result).getData();
    32941                        if (is == 1) {
    32942                                if (it.isOutputDouble()) {
    32943                                        while (it.hasNext()) {
    32944                                                final double ix = it.aDouble;
    32945                                                byte ox;
    32946                                                if (ix < pax)
    32947                                                        ox = (byte) toLong(pax);
    32948                                                else if (ix > pbx)
    32949                                                        ox = (byte) toLong(pbx);
    32950                                                else
    32951                                                        ox = (byte) toLong(ix);
    32952                                                oai8data[it.oIndex] = ox;
    32953                                        }
    32954                                } else {
    32955                                        while (it.hasNext()) {
    32956                                                final long ix = it.aLong;
    32957                                                byte ox;
    32958                                                if (ix < pax)
    32959                                                        ox = (byte) toLong(pax);
    32960                                                else if (ix > pbx)
    32961                                                        ox = (byte) toLong(pbx);
    32962                                                else
    32963                                                        ox = (byte) toLong(ix);
    32964                                                oai8data[it.oIndex] = ox;
    32965                                        }
    32966                                }
    32967                        } else if (as == 1) {
    32968                                if (it.isOutputDouble()) {
    32969                                        while (it.hasNext()) {
    32970                                                final double ix = it.aDouble;
    32971                                                byte ox;
    32972                                                if (ix < pax)
    32973                                                        ox = (byte) toLong(pax);
    32974                                                else if (ix > pbx)
    32975                                                        ox = (byte) toLong(pbx);
    32976                                                else
    32977                                                        ox = (byte) toLong(ix);
    32978                                                for (int j = 0; j < is; j++) {
    32979                                                        oai8data[it.oIndex + j] = ox;
    32980                                                }
    32981                                        }
    32982                                } else {
    32983                                        while (it.hasNext()) {
    32984                                                final long ix = it.aLong;
    32985                                                byte ox;
    32986                                                if (ix < pax)
    32987                                                        ox = (byte) toLong(pax);
    32988                                                else if (ix > pbx)
    32989                                                        ox = (byte) toLong(pbx);
    32990                                                else
    32991                                                        ox = (byte) toLong(ix);
    32992                                                for (int j = 0; j < is; j++) {
    32993                                                        oai8data[it.oIndex + j] = ox;
    32994                                                }
    32995                                        }
    32996                                }
    32997                        } else {
    32998                                if (it.isOutputDouble()) {
    32999                                        while (it.hasNext()) {
    33000                                                for (int j = 0; j < is; j++) {
    33001                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    33002                                                        byte ox;
    33003                                                        if (ix < pax)
    33004                                                                ox = (byte) toLong(pax);
    33005                                                        else if (ix > pbx)
    33006                                                                ox = (byte) toLong(pbx);
    33007                                                        else
    33008                                                                ox = (byte) toLong(ix);
    33009                                                        oai8data[it.oIndex + j] = ox;
    33010                                                }
    33011                                        }
    33012                                } else {
    33013                                        while (it.hasNext()) {
    33014                                                for (int j = 0; j < is; j++) {
    33015                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    33016                                                        byte ox;
    33017                                                        if (ix < pax)
    33018                                                                ox = (byte) toLong(pax);
    33019                                                        else if (ix > pbx)
    33020                                                                ox = (byte) toLong(pbx);
    33021                                                        else
    33022                                                                ox = (byte) toLong(ix);
    33023                                                        oai8data[it.oIndex + j] = ox;
    33024                                                }
    33025                                        }
    33026                                }
    33027                        }
    33028                        break;
    33029                case Dataset.ARRAYINT16:
    33030                        final short[] oai16data = ((CompoundShortDataset) result).getData();
    33031                        if (is == 1) {
    33032                                if (it.isOutputDouble()) {
    33033                                        while (it.hasNext()) {
    33034                                                final double ix = it.aDouble;
    33035                                                short ox;
    33036                                                if (ix < pax)
    33037                                                        ox = (short) toLong(pax);
    33038                                                else if (ix > pbx)
    33039                                                        ox = (short) toLong(pbx);
    33040                                                else
    33041                                                        ox = (short) toLong(ix);
    33042                                                oai16data[it.oIndex] = ox;
    33043                                        }
    33044                                } else {
    33045                                        while (it.hasNext()) {
    33046                                                final long ix = it.aLong;
    33047                                                short ox;
    33048                                                if (ix < pax)
    33049                                                        ox = (short) toLong(pax);
    33050                                                else if (ix > pbx)
    33051                                                        ox = (short) toLong(pbx);
    33052                                                else
    33053                                                        ox = (short) toLong(ix);
    33054                                                oai16data[it.oIndex] = ox;
    33055                                        }
    33056                                }
    33057                        } else if (as == 1) {
    33058                                if (it.isOutputDouble()) {
    33059                                        while (it.hasNext()) {
    33060                                                final double ix = it.aDouble;
    33061                                                short ox;
    33062                                                if (ix < pax)
    33063                                                        ox = (short) toLong(pax);
    33064                                                else if (ix > pbx)
    33065                                                        ox = (short) toLong(pbx);
    33066                                                else
    33067                                                        ox = (short) toLong(ix);
    33068                                                for (int j = 0; j < is; j++) {
    33069                                                        oai16data[it.oIndex + j] = ox;
    33070                                                }
    33071                                        }
    33072                                } else {
    33073                                        while (it.hasNext()) {
    33074                                                final long ix = it.aLong;
    33075                                                short ox;
    33076                                                if (ix < pax)
    33077                                                        ox = (short) toLong(pax);
    33078                                                else if (ix > pbx)
    33079                                                        ox = (short) toLong(pbx);
    33080                                                else
    33081                                                        ox = (short) toLong(ix);
    33082                                                for (int j = 0; j < is; j++) {
    33083                                                        oai16data[it.oIndex + j] = ox;
    33084                                                }
    33085                                        }
    33086                                }
    33087                        } else {
    33088                                if (it.isOutputDouble()) {
    33089                                        while (it.hasNext()) {
    33090                                                for (int j = 0; j < is; j++) {
    33091                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    33092                                                        short ox;
    33093                                                        if (ix < pax)
    33094                                                                ox = (short) toLong(pax);
    33095                                                        else if (ix > pbx)
    33096                                                                ox = (short) toLong(pbx);
    33097                                                        else
    33098                                                                ox = (short) toLong(ix);
    33099                                                        oai16data[it.oIndex + j] = ox;
    33100                                                }
    33101                                        }
    33102                                } else {
    33103                                        while (it.hasNext()) {
    33104                                                for (int j = 0; j < is; j++) {
    33105                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    33106                                                        short ox;
    33107                                                        if (ix < pax)
    33108                                                                ox = (short) toLong(pax);
    33109                                                        else if (ix > pbx)
    33110                                                                ox = (short) toLong(pbx);
    33111                                                        else
    33112                                                                ox = (short) toLong(ix);
    33113                                                        oai16data[it.oIndex + j] = ox;
    33114                                                }
    33115                                        }
    33116                                }
    33117                        }
    33118                        break;
    33119                case Dataset.ARRAYINT64:
    33120                        final long[] oai64data = ((CompoundLongDataset) result).getData();
    33121                        if (is == 1) {
    33122                                if (it.isOutputDouble()) {
    33123                                        while (it.hasNext()) {
    33124                                                final double ix = it.aDouble;
    33125                                                long ox;
    33126                                                if (ix < pax)
    33127                                                        ox = toLong(pax);
    33128                                                else if (ix > pbx)
    33129                                                        ox = toLong(pbx);
    33130                                                else
    33131                                                        ox = toLong(ix);
    33132                                                oai64data[it.oIndex] = ox;
    33133                                        }
    33134                                } else {
    33135                                        while (it.hasNext()) {
    33136                                                final long ix = it.aLong;
    33137                                                long ox;
    33138                                                if (ix < pax)
    33139                                                        ox = toLong(pax);
    33140                                                else if (ix > pbx)
    33141                                                        ox = toLong(pbx);
    33142                                                else
    33143                                                        ox = toLong(ix);
    33144                                                oai64data[it.oIndex] = ox;
    33145                                        }
    33146                                }
    33147                        } else if (as == 1) {
    33148                                if (it.isOutputDouble()) {
    33149                                        while (it.hasNext()) {
    33150                                                final double ix = it.aDouble;
    33151                                                long ox;
    33152                                                if (ix < pax)
    33153                                                        ox = toLong(pax);
    33154                                                else if (ix > pbx)
    33155                                                        ox = toLong(pbx);
    33156                                                else
    33157                                                        ox = toLong(ix);
    33158                                                for (int j = 0; j < is; j++) {
    33159                                                        oai64data[it.oIndex + j] = ox;
    33160                                                }
    33161                                        }
    33162                                } else {
    33163                                        while (it.hasNext()) {
    33164                                                final long ix = it.aLong;
    33165                                                long ox;
    33166                                                if (ix < pax)
    33167                                                        ox = toLong(pax);
    33168                                                else if (ix > pbx)
    33169                                                        ox = toLong(pbx);
    33170                                                else
    33171                                                        ox = toLong(ix);
    33172                                                for (int j = 0; j < is; j++) {
    33173                                                        oai64data[it.oIndex + j] = ox;
    33174                                                }
    33175                                        }
    33176                                }
    33177                        } else {
    33178                                if (it.isOutputDouble()) {
    33179                                        while (it.hasNext()) {
    33180                                                for (int j = 0; j < is; j++) {
    33181                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    33182                                                        long ox;
    33183                                                        if (ix < pax)
    33184                                                                ox = toLong(pax);
    33185                                                        else if (ix > pbx)
    33186                                                                ox = toLong(pbx);
    33187                                                        else
    33188                                                                ox = toLong(ix);
    33189                                                        oai64data[it.oIndex + j] = ox;
    33190                                                }
    33191                                        }
    33192                                } else {
    33193                                        while (it.hasNext()) {
    33194                                                for (int j = 0; j < is; j++) {
    33195                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    33196                                                        long ox;
    33197                                                        if (ix < pax)
    33198                                                                ox = toLong(pax);
    33199                                                        else if (ix > pbx)
    33200                                                                ox = toLong(pbx);
    33201                                                        else
    33202                                                                ox = toLong(ix);
    33203                                                        oai64data[it.oIndex + j] = ox;
    33204                                                }
    33205                                        }
    33206                                }
    33207                        }
    33208                        break;
    33209                case Dataset.ARRAYINT32:
    33210                        final int[] oai32data = ((CompoundIntegerDataset) result).getData();
    33211                        if (is == 1) {
    33212                                if (it.isOutputDouble()) {
    33213                                        while (it.hasNext()) {
    33214                                                final double ix = it.aDouble;
    33215                                                int ox;
    33216                                                if (ix < pax)
    33217                                                        ox = (int) toLong(pax);
    33218                                                else if (ix > pbx)
    33219                                                        ox = (int) toLong(pbx);
    33220                                                else
    33221                                                        ox = (int) toLong(ix);
    33222                                                oai32data[it.oIndex] = ox;
    33223                                        }
    33224                                } else {
    33225                                        while (it.hasNext()) {
    33226                                                final long ix = it.aLong;
    33227                                                int ox;
    33228                                                if (ix < pax)
    33229                                                        ox = (int) toLong(pax);
    33230                                                else if (ix > pbx)
    33231                                                        ox = (int) toLong(pbx);
    33232                                                else
    33233                                                        ox = (int) toLong(ix);
    33234                                                oai32data[it.oIndex] = ox;
    33235                                        }
    33236                                }
    33237                        } else if (as == 1) {
    33238                                if (it.isOutputDouble()) {
    33239                                        while (it.hasNext()) {
    33240                                                final double ix = it.aDouble;
    33241                                                int ox;
    33242                                                if (ix < pax)
    33243                                                        ox = (int) toLong(pax);
    33244                                                else if (ix > pbx)
    33245                                                        ox = (int) toLong(pbx);
    33246                                                else
    33247                                                        ox = (int) toLong(ix);
    33248                                                for (int j = 0; j < is; j++) {
    33249                                                        oai32data[it.oIndex + j] = ox;
    33250                                                }
    33251                                        }
    33252                                } else {
    33253                                        while (it.hasNext()) {
    33254                                                final long ix = it.aLong;
    33255                                                int ox;
    33256                                                if (ix < pax)
    33257                                                        ox = (int) toLong(pax);
    33258                                                else if (ix > pbx)
    33259                                                        ox = (int) toLong(pbx);
    33260                                                else
    33261                                                        ox = (int) toLong(ix);
    33262                                                for (int j = 0; j < is; j++) {
    33263                                                        oai32data[it.oIndex + j] = ox;
    33264                                                }
    33265                                        }
    33266                                }
    33267                        } else {
    33268                                if (it.isOutputDouble()) {
    33269                                        while (it.hasNext()) {
    33270                                                for (int j = 0; j < is; j++) {
    33271                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    33272                                                        int ox;
    33273                                                        if (ix < pax)
    33274                                                                ox = (int) toLong(pax);
    33275                                                        else if (ix > pbx)
    33276                                                                ox = (int) toLong(pbx);
    33277                                                        else
    33278                                                                ox = (int) toLong(ix);
    33279                                                        oai32data[it.oIndex + j] = ox;
    33280                                                }
    33281                                        }
    33282                                } else {
    33283                                        while (it.hasNext()) {
    33284                                                for (int j = 0; j < is; j++) {
    33285                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    33286                                                        int ox;
    33287                                                        if (ix < pax)
    33288                                                                ox = (int) toLong(pax);
    33289                                                        else if (ix > pbx)
    33290                                                                ox = (int) toLong(pbx);
    33291                                                        else
    33292                                                                ox = (int) toLong(ix);
    33293                                                        oai32data[it.oIndex + j] = ox;
    33294                                                }
    33295                                        }
    33296                                }
    33297                        }
    33298                        break;
    33299                case Dataset.FLOAT32:
    33300                        final float[] of32data = ((FloatDataset) result).getData();
    33301                        if (it.isOutputDouble()) {
    33302                                while (it.hasNext()) {
    33303                                        final double ix = it.aDouble;
    33304                                        float ox;
    33305                                        if (Double.isNaN(ix))
    33306                                                ox = (float) ((pax+pbx)/2.);
    33307                                        else if (ix < pax)
    33308                                                ox = (float) (pax);
    33309                                        else if (ix > pbx)
    33310                                                ox = (float) (pbx);
    33311                                        else
    33312                                                ox = (float) (ix);
    33313                                        of32data[it.oIndex] = ox;
    33314                                }
    33315                        } else {
    33316                                while (it.hasNext()) {
    33317                                        final long ix = it.aLong;
    33318                                        float ox;
    33319                                        if (Double.isNaN(ix))
    33320                                                ox = (float) ((pax+pbx)/2.);
    33321                                        else if (ix < pax)
    33322                                                ox = (float) (pax);
    33323                                        else if (ix > pbx)
    33324                                                ox = (float) (pbx);
    33325                                        else
    33326                                                ox = (ix);
    33327                                        of32data[it.oIndex] = ox;
    33328                                }
    33329                        }
    33330                        break;
    33331                case Dataset.FLOAT64:
    33332                        final double[] of64data = ((DoubleDataset) result).getData();
    33333                        if (it.isOutputDouble()) {
    33334                                while (it.hasNext()) {
    33335                                        final double ix = it.aDouble;
    33336                                        double ox;
    33337                                        if (Double.isNaN(ix))
    33338                                                ox = ((pax+pbx)/2.);
    33339                                        else if (ix < pax)
    33340                                                ox = (pax);
    33341                                        else if (ix > pbx)
    33342                                                ox = (pbx);
    33343                                        else
    33344                                                ox = (ix);
    33345                                        of64data[it.oIndex] = ox;
    33346                                }
    33347                        } else {
    33348                                while (it.hasNext()) {
    33349                                        final long ix = it.aLong;
    33350                                        double ox;
    33351                                        if (Double.isNaN(ix))
    33352                                                ox = ((pax+pbx)/2.);
    33353                                        else if (ix < pax)
    33354                                                ox = (pax);
    33355                                        else if (ix > pbx)
    33356                                                ox = (pbx);
    33357                                        else
    33358                                                ox = (ix);
    33359                                        of64data[it.oIndex] = ox;
    33360                                }
    33361                        }
    33362                        break;
    33363                case Dataset.ARRAYFLOAT32:
    33364                        final float[] oaf32data = ((CompoundFloatDataset) result).getData();
    33365                        if (is == 1) {
    33366                                if (it.isOutputDouble()) {
    33367                                        while (it.hasNext()) {
    33368                                                final double ix = it.aDouble;
    33369                                                float ox;
    33370                                                if (Double.isNaN(ix))
    33371                                                        ox = (float) ((pax+pbx)/2.);
    33372                                                else if (ix < pax)
    33373                                                        ox = (float) (pax);
    33374                                                else if (ix > pbx)
    33375                                                        ox = (float) (pbx);
    33376                                                else
    33377                                                        ox = (float) (ix);
    33378                                                oaf32data[it.oIndex] = ox;
    33379                                        }
    33380                                } else {
    33381                                        while (it.hasNext()) {
    33382                                                final long ix = it.aLong;
    33383                                                float ox;
    33384                                                if (Double.isNaN(ix))
    33385                                                        ox = (float) ((pax+pbx)/2.);
    33386                                                else if (ix < pax)
    33387                                                        ox = (float) (pax);
    33388                                                else if (ix > pbx)
    33389                                                        ox = (float) (pbx);
    33390                                                else
    33391                                                        ox = (ix);
    33392                                                oaf32data[it.oIndex] = ox;
    33393                                        }
    33394                                }
    33395                        } else if (as == 1) {
    33396                                if (it.isOutputDouble()) {
    33397                                        while (it.hasNext()) {
    33398                                                final double ix = it.aDouble;
    33399                                                float ox;
    33400                                                if (Double.isNaN(ix))
    33401                                                        ox = (float) ((pax+pbx)/2.);
    33402                                                else if (ix < pax)
    33403                                                        ox = (float) (pax);
    33404                                                else if (ix > pbx)
    33405                                                        ox = (float) (pbx);
    33406                                                else
    33407                                                        ox = (float) (ix);
    33408                                                for (int j = 0; j < is; j++) {
    33409                                                        oaf32data[it.oIndex + j] = ox;
    33410                                                }
    33411                                        }
    33412                                } else {
    33413                                        while (it.hasNext()) {
    33414                                                final long ix = it.aLong;
    33415                                                float ox;
    33416                                                if (Double.isNaN(ix))
    33417                                                        ox = (float) ((pax+pbx)/2.);
    33418                                                else if (ix < pax)
    33419                                                        ox = (float) (pax);
    33420                                                else if (ix > pbx)
    33421                                                        ox = (float) (pbx);
    33422                                                else
    33423                                                        ox = (ix);
    33424                                                for (int j = 0; j < is; j++) {
    33425                                                        oaf32data[it.oIndex + j] = ox;
    33426                                                }
    33427                                        }
    33428                                }
    33429                        } else {
    33430                                if (it.isOutputDouble()) {
    33431                                        while (it.hasNext()) {
    33432                                                for (int j = 0; j < is; j++) {
    33433                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    33434                                                        float ox;
    33435                                                        if (Double.isNaN(ix))
    33436                                                                ox = (float) ((pax+pbx)/2.);
    33437                                                        else if (ix < pax)
    33438                                                                ox = (float) (pax);
    33439                                                        else if (ix > pbx)
    33440                                                                ox = (float) (pbx);
    33441                                                        else
    33442                                                                ox = (float) (ix);
    33443                                                        oaf32data[it.oIndex + j] = ox;
    33444                                                }
    33445                                        }
    33446                                } else {
    33447                                        while (it.hasNext()) {
    33448                                                for (int j = 0; j < is; j++) {
    33449                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    33450                                                        float ox;
    33451                                                        if (Double.isNaN(ix))
    33452                                                                ox = (float) ((pax+pbx)/2.);
    33453                                                        else if (ix < pax)
    33454                                                                ox = (float) (pax);
    33455                                                        else if (ix > pbx)
    33456                                                                ox = (float) (pbx);
    33457                                                        else
    33458                                                                ox = (ix);
    33459                                                        oaf32data[it.oIndex + j] = ox;
    33460                                                }
    33461                                        }
    33462                                }
    33463                        }
    33464                        break;
    33465                case Dataset.ARRAYFLOAT64:
    33466                        final double[] oaf64data = ((CompoundDoubleDataset) result).getData();
    33467                        if (is == 1) {
    33468                                if (it.isOutputDouble()) {
    33469                                        while (it.hasNext()) {
    33470                                                final double ix = it.aDouble;
    33471                                                double ox;
    33472                                                if (Double.isNaN(ix))
    33473                                                        ox = ((pax+pbx)/2.);
    33474                                                else if (ix < pax)
    33475                                                        ox = (pax);
    33476                                                else if (ix > pbx)
    33477                                                        ox = (pbx);
    33478                                                else
    33479                                                        ox = (ix);
    33480                                                oaf64data[it.oIndex] = ox;
    33481                                        }
    33482                                } else {
    33483                                        while (it.hasNext()) {
    33484                                                final long ix = it.aLong;
    33485                                                double ox;
    33486                                                if (Double.isNaN(ix))
    33487                                                        ox = ((pax+pbx)/2.);
    33488                                                else if (ix < pax)
    33489                                                        ox = (pax);
    33490                                                else if (ix > pbx)
    33491                                                        ox = (pbx);
    33492                                                else
    33493                                                        ox = (ix);
    33494                                                oaf64data[it.oIndex] = ox;
    33495                                        }
    33496                                }
    33497                        } else if (as == 1) {
    33498                                if (it.isOutputDouble()) {
    33499                                        while (it.hasNext()) {
    33500                                                final double ix = it.aDouble;
    33501                                                double ox;
    33502                                                if (Double.isNaN(ix))
    33503                                                        ox = ((pax+pbx)/2.);
    33504                                                else if (ix < pax)
    33505                                                        ox = (pax);
    33506                                                else if (ix > pbx)
    33507                                                        ox = (pbx);
    33508                                                else
    33509                                                        ox = (ix);
    33510                                                for (int j = 0; j < is; j++) {
    33511                                                        oaf64data[it.oIndex + j] = ox;
    33512                                                }
    33513                                        }
    33514                                } else {
    33515                                        while (it.hasNext()) {
    33516                                                final long ix = it.aLong;
    33517                                                double ox;
    33518                                                if (Double.isNaN(ix))
    33519                                                        ox = ((pax+pbx)/2.);
    33520                                                else if (ix < pax)
    33521                                                        ox = (pax);
    33522                                                else if (ix > pbx)
    33523                                                        ox = (pbx);
    33524                                                else
    33525                                                        ox = (ix);
    33526                                                for (int j = 0; j < is; j++) {
    33527                                                        oaf64data[it.oIndex + j] = ox;
    33528                                                }
    33529                                        }
    33530                                }
    33531                        } else {
    33532                                if (it.isOutputDouble()) {
    33533                                        while (it.hasNext()) {
    33534                                                for (int j = 0; j < is; j++) {
    33535                                                        final double ix = da.getElementDoubleAbs(it.aIndex + j);
    33536                                                        double ox;
    33537                                                        if (Double.isNaN(ix))
    33538                                                                ox = ((pax+pbx)/2.);
    33539                                                        else if (ix < pax)
    33540                                                                ox = (pax);
    33541                                                        else if (ix > pbx)
    33542                                                                ox = (pbx);
    33543                                                        else
    33544                                                                ox = (ix);
    33545                                                        oaf64data[it.oIndex + j] = ox;
    33546                                                }
    33547                                        }
    33548                                } else {
    33549                                        while (it.hasNext()) {
    33550                                                for (int j = 0; j < is; j++) {
    33551                                                        final long ix = da.getElementLongAbs(it.aIndex + j);
    33552                                                        double ox;
    33553                                                        if (Double.isNaN(ix))
    33554                                                                ox = ((pax+pbx)/2.);
    33555                                                        else if (ix < pax)
    33556                                                                ox = (pax);
    33557                                                        else if (ix > pbx)
    33558                                                                ox = (pbx);
    33559                                                        else
    33560                                                                ox = (ix);
    33561                                                        oaf64data[it.oIndex + j] = ox;
    33562                                                }
    33563                                        }
    33564                                }
    33565                        }
    33566                        break;
    33567                default:
    33568                        throw new IllegalArgumentException("clip supports integer, compound integer, real, compound real datasets only");
    33569                }
    33570
    33571                addFunctionName(result, "clip");
    33572                return result;
    33573        }
    33574
    33575// End of generated code
    33576
    33577}